diff --git a/README.md b/README.md index cd55449..f68668e 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,10 @@ All variables which can be overridden are stored in [defaults/main.yml](defaults | Name | Default Value | Description | | -------------- | ------------- | -----------------------------------| -| `besu_version` | ___unset___ | __REQUIRED__ Version of Besu to install and run. All available versions are listed on our Besu [solutions](https://pegasys.tech/solutions/hyperledger-besu/) page | +| `besu_build_from_source` | ___unset___ | When set to `true`, Besu is build from git sources. See also `besu_git_repo` and `besu_git_commit` | +| `besu_version` | ___unset___ | __REQUIRED__ if `besu_build_from_source` is false. Version of Besu to install and run. All available versions are listed on our Besu [solutions](https://pegasys.tech/solutions/hyperledger-besu/) page | +| `besu_git_repo` | https://github.com/hyperledger/besu.git | The URL to use when cloning besu sources. Only necessary when `besu_build_from_source` is `true`. | +| `besu_git_commit` | master | The git commit to use when building Besu from source. Can be a branchname, commit hash, or anything that's legal to be used as an argument to `git checkout`. Only used if `besu_build_from_source` is `true`. | | `besu_user` | besu | Besu user | | `besu_group` | besu | Besu group | | `besu_download_url` | https://bintray.com/hyperledger-org/besu-repo/download_file?file_path=besu-{{ besu_version }}.tar.gz | The download tar.gz file used. You can use this if you need to retrieve besu from a custom location such as an internal repository. | diff --git a/defaults/main.yml b/defaults/main.yml index 63ef8e4..35eaa2b 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -7,6 +7,11 @@ besu_group: "{{ besu_user }}" # Version to install besu_download_url: "https://bintray.com/hyperledger-org/besu-repo/download_file?file_path=besu-{{ besu_version }}.tar.gz" +# Building from source +besu_build_from_source: false +besu_git_repo: "https://github.com/hyperledger/besu.git" +besu_git_commit: "master" + # Directory paths besu_base_dir: "/opt/besu" besu_install_dir: "{{ besu_base_dir }}/besu-{{ besu_version }}" diff --git a/tasks/compile.yml b/tasks/compile.yml new file mode 100644 index 0000000..31ec2c2 --- /dev/null +++ b/tasks/compile.yml @@ -0,0 +1,39 @@ +--- + +- name: Ensure we have sane configuration + fail: + msg: You must set "besu_git_repo" for this role to run when "besu_build_from_source" is enabled + when: not (besu_git_repo is defined) or besu_git_repo|length == 0 + +- name: Check JDK version + shell: javac -version | egrep -o '[0-9]+\.[0-9]+\.[0-9]+' + register: jdk_version + ignore_errors: true + +- name: Ensure JDK is installed + fail: + msg: "You must have JDK 11 or later installed. {{ 'No version found.' if jdk_version is failed else 'Found version ' + jdk_version.stdout }}" + when: jdk_version.stdout is version('11.0.0', '<') + +- name: Clone Besu Sources + git: + repo: "{{ besu_git_repo }}" + dest: '/tmp/besu' + version: "{{ besu_git_commit }}" + +- name: Build Besu + shell: ./gradlew --no-daemon --parallel clean assemble + args: + chdir: /tmp/besu + +- name: Get Besu Version + shell: "awk '/version=/ { gsub(/version=/,\"\"); print $1 }' gradle.properties" + args: + chdir: /tmp/besu + register: besu_version_cmd + +- name: Set Besu Version Fact + set_fact: + besu_version: "{{ besu_version_cmd.stdout }}" + + diff --git a/tasks/install.yml b/tasks/install.yml index a0e8c39..2aab8c8 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -44,8 +44,8 @@ - name: Extract Besu source to install directory unarchive: - src: "{{ besu_download_url }}" - remote_src: true + src: "{{ '/tmp/besu/build/distributions/besu-' + besu_version + '.tar.gz' if besu_build_from_source else besu_download_url }}" + remote_src: "{{ false if besu_build_from_source else true }}" dest: "{{ besu_install_dir }}" owner: "{{ besu_user }}" group: "{{ besu_group }}" diff --git a/tasks/main.yml b/tasks/main.yml index 1310651..a8db28a 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -2,8 +2,11 @@ - name: Ensure we have sane configuration block: - fail: - msg: You must set "besu_version" for this role to run - when: besu_version is not defined + msg: You must set "besu_version" for this role to run when not building Besu from source + when: besu_version is not defined and not besu_build_from_source + - fail: + msg: The vars "besu_version" and "besu_build_from_source" are incompatible. If trying to build a specific git refspec, use "besu_git_refspec" instead of besu_version. + when: besu_version is defined and besu_build_from_source - fail: msg: Orion and Fast-Sync are incompatible when: orion_version is defined and besu_sync_mode == "FAST" @@ -16,6 +19,10 @@ - "{{ ansible_os_family|lower }}.yml" skip: true +- name: Compile besu + include_tasks: "compile.yml" + when: besu_build_from_source + - name: Install besu include_tasks: "install.yml"