Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zeitgeist Client Update Automation #944

Merged
merged 11 commits into from
Jul 20, 2023
27 changes: 27 additions & 0 deletions .github/workflows/client-auto-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Deploy
on:
# Triggers this Action on push or pull request events on the "main" branch and when manually requested from the "Actions" tab
workflow_dispatch:
push:
branches: [ main ]
tags: ['*']
samuelarogbonlo marked this conversation as resolved.
Show resolved Hide resolved

jobs:
auto-update-client:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Checkout repository
id: vars
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT

- name: Run Ansible playbook
env:
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
uses: dawidd6/[email protected]
with:
playbook: scripts/ansible/client-auto-update.yml
directory: ./
key: ${{ secrets.ANSIBLE_SSH_PRIVATE_KEY }}
inventory: ${{ secrets.ANSIBLE_INVENTORY }}

26 changes: 19 additions & 7 deletions .github/workflows/docker-hub-parachain.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
name: Publish features parachain to Docker Hub

on:
push:
tags:
- '*'
workflow_dispatch:
push:
branches: [ main ]
tags: [ '*' ]
samuelarogbonlo marked this conversation as resolved.
Show resolved Hide resolved

jobs:
publish:
name: Publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v2
id: vars
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT

- name: Docker meta
id: meta
Expand All @@ -23,7 +25,7 @@ jobs:
images: |
zeitgeistpm/zeitgeist-node-parachain
tags: |
type=sha
type=ref

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
Expand All @@ -38,12 +40,22 @@ jobs:
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Build and push
uses: docker/build-push-action@v2
uses: docker/build-push-action@v3.2.0
with:
build-args: |
PROFILE=production
FEATURES=parachain
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}


- name: Update image version of the existing network spec
uses: "OnFinality-io/action-onf-release@v1"
with:
onf-access-key: ${{ secrets.ONF_ACCESS_KEY }}
onf-secret-key: ${{ secrets.ONF_SECRET_KEY }}
onf-workspace-id: ${{ secrets.ONF_WORKSPACE_ID }}
onf-network-key: ${{ secrets.ONF_NETWORK_KEY }}
onf-sub-command: image
onf-action: add
image-version: ${{ steps.vars.outputs.tag }}
samuelarogbonlo marked this conversation as resolved.
Show resolved Hide resolved
73 changes: 73 additions & 0 deletions scripts/ansible/client-auto-update-playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
- hosts: zeitgeist
gather_facts: no
become: true
environment:
RELEASE_VERSION: "{{ lookup('env', 'RELEASE_VERSION') }}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do we set RELEASE_VERSION? In the environment variables? What happens, if it is not set? Can we print the RELEASE_VERSION in the Github Actions Debug Console?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RELEASE_VERSION is automatically set by the Github client-auto-update.yml workflow as an environment variable. So when the playbook is ran in, it looks for environment variable already set by the Github workflow. I may have to include some logic so the workflow can run if RELEASE_VERSION is not specified, just to be on the safer side.


tasks:
- name: Get Zeitgeist services
no_log: true
Chralt98 marked this conversation as resolved.
Show resolved Hide resolved
shell: ls -a /etc/systemd/system/zeitgeist* | xargs -n 1 basename
register: zeitgeist_files

- name: Stop Zeitgeist services
no_log: true
systemd:
name: "{{ item }}"
state: stopped
with_items: "{{ zeitgeist_files.stdout_lines }}"

- name: Check if Mount Dir Exists
no_log: true
stat:
path: /mnt/
register: mnt

- name: Create Backup from Previous Zeitgeist Client in Mount Dir
no_log: true
shell: |
cd /mnt/*/services/zeitgeist/bin
PREV_VERSION=$(./zeitgeist --version | grep -Eo '([0-9]{1,}\.)+[0-9]{1,}' | tr -d '.')
mv zeitgeist zeitgeist_$PREV_VERSION.bak
when: mnt.stat.exists and mnt.stat.isdir
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to remove old backups here to avoid bloating.


- name: Create Backup from Previous Zeitgeist Client
no_log: true
shell: |
cd /services/zeitgeist/bin
PREV_VERSION=$(./zeitgeist --version | grep -Eo '([0-9]{1,}\.)+[0-9]{1,}' | tr -d '.')
mv zeitgeist zeitgeist_$PREV_VERSION.bak
when: not mnt.stat.exists and mnt.stat.isdir
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to remove old backups here to avoid bloating.


- name: Download Zeitgeist Client to Mount Dir
no_log: true
shell: |
cd /mnt/*/services/zeitgeist/bin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works as long as there are not two folder trees of the following form:
/mnt/<folder1>/services
/mnt/<folder2>/services

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes for now there's no more than one sub-directory in the /mnt/ directory. These sub-directories contain the parachain and relay-chain data mounted in volumes for each zeitgeist node.

if [[ -v RELEASE_VERSION ]]; then
wget -O zeitgeist https://github.com/zeitgeistpm/zeitgeist/releases/download/$RELEASE_VERSION/zeitgeist_parachain
else
wget -O zeitgeist https://github.com/zeitgeistpm/zeitgeist/releases/download/v0.3.6/zeitgeist_parachain
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v0.3.6 is bugged.

Suggested change
wget -O zeitgeist https://github.com/zeitgeistpm/zeitgeist/releases/download/v0.3.6/zeitgeist_parachain
wget -O zeitgeist https://github.com/zeitgeistpm/zeitgeist/releases/download/v0.3.4/zeitgeist_parachain

fi
chmod 0755 zeitgeist
chown zeitgeist:zeitgeist zeitgeist
when: mnt.stat.exists and mnt.stat.isdir

- name: Download Zeitgeist Client
no_log: true
shell: |
cd /services/zeitgeist/bin
if [[ -v RELEASE_VERSION ]]; then
wget -O zeitgeist https://github.com/zeitgeistpm/zeitgeist/releases/download/$RELEASE_VERSION/zeitgeist_parachain
else
wget -O zeitgeist https://github.com/zeitgeistpm/zeitgeist/releases/download/v0.3.6/zeitgeist_parachain
samuelarogbonlo marked this conversation as resolved.
Show resolved Hide resolved
fi
chmod 0755 zeitgeist
chown zeitgeist:zeitgeist zeitgeist
when: not mnt.stat.exists and mnt.stat.isdir

- name: Start Zeitgeist Services
no_log: true
systemd:
name: "{{ item }}"
state: started
with_items: "{{ zeitgeist_files.stdout_lines }}"