Skip to content

Commit

Permalink
chore: introduce local build of artifacts (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrekucci authored May 2, 2024
1 parent 9def6a6 commit 62c191f
Show file tree
Hide file tree
Showing 31 changed files with 232 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
module: [ infrastructure/tools/keystore-generator, p2p/integrationtest/bidder, p2p/integrationtest/provider, bridge/standard/bridge-v1, external/geth, oracle, p2p]
module: [ infrastructure/tools/keystore-generator, p2p/integrationtest/provider, p2p/integrationtest/bidder, bridge/standard/bridge-v1, external/geth, oracle, p2p]
steps:
- name: Set Snapshot Flag
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
Expand Down
13 changes: 8 additions & 5 deletions bridge/standard/bridge-v1/.goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ archives:
name_template: >-
{{ .ProjectName }}-
{{- .Binary }}_
{{- if .IsSnapshot }}{{ .ShortCommit }}_
{{- else }}{{ .Version }}_
{{- if .IsSnapshot }}{{ .ShortCommit }}
{{- else }}{{ .Version }}
{{ end }}
{{- if .Env.DIRTY_SUFFIX }}{{ .Env.DIRTY_SUFFIX }}{{ end }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
Expand All @@ -67,9 +68,10 @@ archives:
name_template: >-
{{ .ProjectName }}-
{{- .Binary }}_
{{- if .IsSnapshot }}{{ .ShortCommit }}_
{{- else }}{{ .Version }}_
{{- if .IsSnapshot }}{{ .ShortCommit }}
{{- else }}{{ .Version }}
{{ end }}
{{- if .Env.DIRTY_SUFFIX }}{{ .Env.DIRTY_SUFFIX }}{{ end }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
Expand All @@ -85,7 +87,8 @@ checksum:
{{ .ProjectName }}_
{{- if .IsSnapshot }}{{ .ShortCommit }}
{{- else }}{{ .Version }}
{{- end -}}
{{- end }}
{{- if .Env.DIRTY_SUFFIX }}{{ .Env.DIRTY_SUFFIX }}{{ end -}}
_checksums.txt
changelog:
Expand Down
2 changes: 1 addition & 1 deletion external/geth
Submodule geth updated from 66a4f6 to 0d4c12
85 changes: 0 additions & 85 deletions infrastructure/ansible/playbooks/nomad/deploy.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ Prepare `hosts.ini` File: This file contains the IP addresses of your Nomad serv

## Running the Playbook

Execute the Ansible playbook to install Nomad on the specified servers and clients. Navigate to the directory containing your playbook and run the following command:
Execute the Ansible playbook to install Nomad on the specified servers and clients. From the root of the repository run the following command:

```shell
cd ansible
ansible-playbook -i hosts.ini playbooks/nomad/init.yml --private-key=~/.ssh/your_private_key
ansible-playbook -i hosts.ini infrastructure/nomad/init.yml --private-key=~/.ssh/your_private_key
```

- Replace ~/.ssh/your_private_key with the path to your SSH private key if not using the default SSH key.
Expand All @@ -49,23 +49,23 @@ ansible-playbook -i hosts.ini playbooks/nomad/init.yml --private-key=~/.ssh/your
To generate and run Nomad jobs run the following playbook:

```shell
ansible-playbook -i hosts.ini playbooks/nomad/deploy.yml --private-key=~/.ssh/your_private_key
ansible-playbook -i hosts.ini infrastructure/nomad/deploy.yml --private-key=~/.ssh/your_private_key
```

To destroy all running Nomad jobs run the following playbook:

```shell
ansible-playbook -i hosts.ini playbooks/nomad/destroy.yml --private-key=~/.ssh/your_private_key
ansible-playbook -i hosts.ini infrastructure/nomad/destroy.yml --private-key=~/.ssh/your_private_key
```

To install [crisis tools](https://www.brendangregg.com/blog/2024-03-24/linux-crisis-tools.html) run the following playbook:

```shell
ansible-playbook -i hosts.ini playbooks/nomad/install_linux_crisis_tools.yml --private-key=~/.ssh/your_private_key
ansible-playbook -i hosts.ini infrastructure/nomad/install_linux_crisis_tools.yml --private-key=~/.ssh/your_private_key
```

And finally if you need certificates for development purposes, run the following playbook:

```shell
ansible-playbook -i hosts.ini playbooks/nomad/install_dev_ss_certificates.yml --private-key=~/.ssh/your_private_key
ansible-playbook -i hosts.ini infrastructure/nomad/install_dev_ss_certificates.yml --private-key=~/.ssh/your_private_key
```
188 changes: 188 additions & 0 deletions infrastructure/nomad/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
- name: Deploy Nomad Jobs
hosts: nomad_clients
vars:
env: "devnet"
build: false
datacenter: "dc1"
destination: "{{ ansible_env.HOME }}/{{ env }}"
tls_ca_crt_file: "/usr/local/share/ca-certificates/ca-mev-commit_{{ env }}.mev-commit.primev.xyz.crt"
tls_crt_file: "/etc/ssl/certs/mev-commit_{{ env }}.mev-commit.primev.xyz.crt"
tls_key_file: "/etc/ssl/private/mev-commit_{{ env }}.mev-commit.primev.xyz.key"
aws_s3_bucket: "primev-infrastructure-artifacts"
profiles:
devnet:
job_names:
- 'datadog-agent-logs-collector'
- 'mev-commit-geth-bootnode1'
- 'mev-commit-geth-signer-node1'
- 'mev-commit-geth-member-node'
- 'deploy-contracts'
- 'mev-commit-bootnode1'
- 'mev-commit-provider-node1'
- 'mev-commit-provider-node1-funder'
- 'mev-commit-bidder-node1'
- 'mev-commit-bidder-node1-funder'
- 'mev-commit-provider-emulator-node1'
- 'mev-commit-bidder-emulator-node1'
- 'mev-commit-oracle'
- 'datadog-agent-metrics-collector'
testnet:
job_names:
- 'datadog-agent-logs-collector'
- 'mev-commit-geth-bootnode1'
- 'mev-commit-geth-signer-node1'
- 'mev-commit-geth-member-node'
- 'deploy-contracts'
- 'mev-commit-bootnode1'
- 'mev-commit-provider-node1'
- 'mev-commit-provider-node1-funder'
- 'mev-commit-provider-emulator-node1'
- 'mev-commit-oracle'
- 'datadog-agent-metrics-collector'

vars_prompt:
- name: version
prompt: "Enter the version"
private: no

pre_tasks:
- name: Configuration | Get AWS caller information
amazon.aws.aws_caller_info:
register: aws_caller_info
delegate_to: localhost
when: version is not defined or version == ''

- name: Configuration | Check and fail AWS caller information
ansible.builtin.fail:
msg: "AWS Caller Information is empty or invalid; configure your aws credentials."
when: >
(aws_caller_info is undefined or
aws_caller_info.user_id is undefined or
aws_caller_info.user_id == "") and
(version is not defined or version == '')
- name: Configuration | Determining build version
ansible.builtin.shell: |
echo "$(git rev-parse --short HEAD)$(git diff --quiet || echo '-dirty')"
register: git_hash
delegate_to: localhost
changed_when: false
when: version is not defined or version == ''

- name: Configuration | Setting up build version
set_fact:
build: true
version: "{{ git_hash.stdout }}"
when: version is not defined or version == ''

- name: Configuration | Version info
ansible.builtin.debug:
msg: |
version: {{ version | default('Version not set') }}
- name: Configuration | Build info
ansible.builtin.debug:
msg: |
local build: {{ build | default('Build status unknown') }}
- name: Configuration | Check version
ansible.builtin.fail:
msg: "Version is not set; provide a valid version."
when: version is not defined or version == ''

- name: Configuration | Include job definitions
include_vars:
file: jobs.yml

- name: Configuration | Using "{{ env }}" profile
set_fact:
jobs: "{{ lookup('vars', 'jobs') | selectattr('name', 'in', profiles[env].job_names) | list }}"

tasks:
- name: Check | "{{ destination }}" exists
ansible.builtin.file:
path: "{{ destination }}"
state: directory
mode: '0744'
recurse: yes

- name: Build | Nomad artifacts
ansible.builtin.shell: |
DESTINATION_DIR="/tmp/dist/{{ item }}-{{ version }}"
mkdir -p ${DESTINATION_DIR}
if [ "{{ item }}" == "contracts" ]; then
set -x
tar -czvf "${DESTINATION_DIR}/contracts_{{ version }}.tar.gz" ./{{ item }}
else
goreleaser release --config=./{{ item }}/.goreleaser.yml --clean --snapshot
mv ./dist/* ${DESTINATION_DIR}
fi
environment:
DIRTY_SUFFIX: "{{ '-dirty' if '-dirty' in version else '' }}"
args:
chdir: "{{ playbook_dir }}/../../"
loop:
- infrastructure/tools/keystore-generator
- p2p/integrationtest/provider
- p2p/integrationtest/bidder
- bridge/standard/bridge-v1
- external/geth
- contracts
- oracle
- p2p
loop_control:
label: "{{ item }}"
delegate_to: localhost
when: build

- name: Upload | Filter artifacts
ansible.builtin.find:
paths: "/tmp/dist"
patterns: "*{{ version }}*.gz,*{{ version }}*.txt"
recurse: yes
register: artefacts
delegate_to: localhost
when: build

- name: Upload | Files to S3
amazon.aws.aws_s3:
bucket: "{{ aws_s3_bucket }}"
object: "{{ item.path | basename }}"
src: "{{ item.path }}"
mode: put
tags:
AutoDelete: "true"
loop: "{{ artefacts.files }}"
loop_control:
label: "{{ item.path | basename }}"
when: (artefacts.files | default([])) | length > 0 and build
delegate_to: localhost

- name: Cleanup | Removing "/tmp/dist"
ansible.builtin.file:
path: "/tmp/dist"
state: absent
delegate_to: localhost
when: build

- name: Generate | Nomad scripts
ansible.builtin.template:
src: "templates/nomad/{{ item.template }}"
dest: "{{ destination }}/{{ item.name }}.nomad"
loop: "{{ jobs }}"
loop_control:
label: "{{ item.name }}"
vars:
job: "{{ item }}"

- name: Deploy | Nomad jobs
ansible.builtin.shell: |
nomad run {{ destination }}/{{ job.name }}.nomad
[ "{{ job.name }}" = "deploy-contracts" ] && sleep 180 || true
args:
executable: bash
loop: "{{ jobs }}"
loop_control:
label: "{{ item.name }}"
vars:
job: "{{ item }}"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 6 additions & 4 deletions infrastructure/tools/keystore-generator/.goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ builds:
archives:
- format: tar.gz
name_template: >-
{{ .ProjectName }}_
{{- if .IsSnapshot }}{{ .ShortCommit }}_
{{- else }}{{ .Version }}_
{{ .Binary }}_
{{- if .IsSnapshot }}{{ .ShortCommit }}
{{- else }}{{ .Version }}
{{ end }}
{{- if .Env.DIRTY_SUFFIX }}{{ .Env.DIRTY_SUFFIX }}{{ end }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
Expand All @@ -43,5 +44,6 @@ checksum:
{{ .ProjectName }}_
{{- if .IsSnapshot }}{{ .ShortCommit }}
{{- else }}{{ .Version }}
{{- end -}}
{{- end }}
{{- if .Env.DIRTY_SUFFIX }}{{ .Env.DIRTY_SUFFIX }}{{ end -}}
_checksums.txt
Loading

0 comments on commit 62c191f

Please sign in to comment.