diff --git a/defaults/main.yml b/defaults/main.yml index 2d41994..d3f42f2 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,19 +1,27 @@ --- -# shared testnet name: medalla, toledo, pyrmont, etc. -beacon_node_network: 'medalla' beacon_node_service_name: 'beacon-node-{{ beacon_node_network }}' -beacon_node_service_path: 'C:\Users\{{ beacon_node_user }}\{{ beacon_node_service_name }}' +beacon_node_service_user_name: 'nimbus' +beacon_node_service_user_pass: '{{ ansible_date_time.epoch | password_hash("sha512") }}' +beacon_node_service_home: 'C:/Users/{{ beacon_node_service_user_name }}' +beacon_node_service_path: '{{ beacon_node_service_home }}/{{ beacon_node_service_name }}' +beacon_node_service_bin_path: '{{ beacon_node_service_path }}/bin' +beacon_node_repo_url: 'https://github.com/status-im/nimbus-eth2.git' +beacon_node_repo_branch: 'stable' +beacon_node_repo_path: '{{ beacon_node_service_path }}/repo' +beacon_node_build_script: '{{ beacon_node_service_path }}/build.sh' + +# shared testnet name: mainnet, pyrmont, prater, etc. +beacon_node_network: 'mainnet' beacon_node_log_level: 'INFO' -beacon_node_data_folder: 'shared_{{ beacon_node_network }}_0' beacon_node_subscribe_all: false beacon_node_doppelganger_detection: true -# For validation -beacon_node_valid_network_names: ["toledo", "pyrmont", "prater", "mainnet", "steklo", "nocturne"] +# Location for all node data +beacon_node_data_path: '{{ beacon_node_service_path }}/data/shared_{{ beacon_node_network }}_0' -# Subfolders for separate read-only mounting -beacon_node_secrets_path: '{{ beacon_node_service_path }}/data/{{ beacon_node_data_folder }}/secrets' +# For validation +beacon_node_valid_network_names: ["pyrmont", "prater", "mainnet", "steklo", "nocturne"] # connectivity settings beacon_node_discovery_port: 9000 diff --git a/tasks/install.yml b/tasks/install.yml new file mode 100644 index 0000000..195b16b --- /dev/null +++ b/tasks/install.yml @@ -0,0 +1,61 @@ +--- +- name: Create service folders + win_file: + path: '{{ item }}' + state: 'directory' + with_items: + - '{{ beacon_node_service_path }}' + - '{{ beacon_node_service_bin_path }}' + +- name: Clone Git repository + win_shell: | + git --no-pager clone \ + {{ beacon_node_repo_url }} \ + {{ beacon_node_repo_path }} \ + --branch {{ beacon_node_repo_branch }} + args: + creates: '{{ beacon_node_repo_path }}' + +- name: Fix repo permissions + win_owner: + path: '{{ beacon_node_repo_path }}' + user: '{{ beacon_node_service_user_name }}' + +# WARNING: There's a known issue with broken GCC mirrors: +# TODO: Install using some other method. +# https://github.com/ScoopInstaller/Main/issues/1752 +- name: Install GCC to compile Nim + win_shell: 'scoop install --global gcc' + +- name: Add GCC to the system wide PATH + win_path: + name: 'PATH' + elements: 'C:/ProgramData/scoop/apps/gcc/current/bin' + scope: 'machine' + state: 'present' + register: machine_path + +- name: Restart host for PATH change to work + win_reboot: + reboot_timeout: 160 + when: machine_path.changed + +- name: Create build script + win_template: + src: 'build.sh.j2' + dest: '{{ beacon_node_build_script }}' + mode: 0750 + +- name: Schedule node builds + win_scheduled_task: + description: 'Daily rebuild of Nimbus beacon node binaries' + name: '{{ beacon_node_service_name }}-build' + #path: '{{ beacon_node_service_path }}' + actions: + - path: '{{ beacon_node_build_script }}' + triggers: + - type: 'daily' + start_boundary: '2021-01-01T01:00:00' + username: '{{ beacon_node_service_user_name }}' + state: 'present' + enabled: true diff --git a/tasks/main.yml b/tasks/main.yml index bf68fac..62e6d99 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,5 +1,6 @@ --- - import_tasks: checks.yml - import_tasks: user.yml +- import_tasks: install.yml - import_tasks: service.yml - import_tasks: firewall.yml diff --git a/templates/build.sh.j2 b/templates/build.sh.j2 new file mode 100644 index 0000000..5d83e65 --- /dev/null +++ b/templates/build.sh.j2 @@ -0,0 +1,73 @@ +#!/usr/bin/env bash +# vim: ft=sh +set -e + +function headIsDetached() { + [[ $(git rev-parse --abbrev-ref --symbolic-full-name HEAD) == "HEAD" ]]; +} + +function binaryExists() { + ls -l build/nimbus_beacon_node_${COMMIT} 2>&1 1>/dev/null +} + +function fetchChanges() { + # We cannot use "git pull" in here, because history may be changed upstream + git fetch + git reset --hard "origin/${BRANCH}" +} + +function buildBinaries() { + # Just one process so it doesn't affect the running beacon nodes. + make -j1 update V=3 + make -j1 nimbus_beacon_node nimbus_signing_process V=3 \ + LOG_LEVEL="TRACE" NIMFLAGS="-d:testnet_servers_image -d:noSignalHandler" + + # Rename binaries to match commit the were built from. + mv "build/nimbus_beacon_node" "build/nimbus_beacon_node_${COMMIT}" + mv "build/nimbus_signing_process" "build/nimbus_signing_process_${COMMIT}" + + # Delete copies that are older than 7 days + find build -mtime +7 -exec rm '{}' \+ +} + +#------------------------------------------------------------------------------- + +BRANCH="{{ beacon_node_repo_branch }}" +BUILD_USER="{{ beacon_node_service_user_name }}" +INSTALL_PATH="{{ beacon_node_service_bin_path }}" + +if [[ "${USER}" != "${BUILD_USER}" ]]; then + echo "Incorrect user: ${USER}" >&2 + echo "Expected: ${BUILD_USER}" >&2 + exit 1 +fi + +# Build the Beacon node binaries +pushd repo >/dev/null + +# Detached HEAD means we're probably on a tag +if headIsDetached; then + echo " >>> Deatached HEAD, nothing to fetch." +else + echo " >>> Fetching changes..." + fetchChanges +fi + +COMMIT=$(git rev-parse --short=8 HEAD) + +if binaryExists && [[ "$1" != "--force" ]]; then + echo " >>> Binary already built" +else + echo " >>> Building binaries..." + buildBinaries +fi + +popd >/dev/null + +echo " >>> Install binaries..." +cp "repo/build/nimbus_beacon_node_${COMMIT}" "${INSTALL_PATH}" +cp "repo/build/nimbus_signing_process_${COMMIT}" "${INSTALL_PATH}" + +# TODO, deploy binary + +echo " >>> SUCCESS"