diff --git a/.github/workflows/client-auto-update.yml b/.github/workflows/client-auto-update.yml new file mode 100644 index 000000000..18c41fa66 --- /dev/null +++ b/.github/workflows/client-auto-update.yml @@ -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: + tags: + - '^v[0-9]+.[0-9]+.[0-9]+$' + +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/action-ansible-playbook@v2.6.1 + with: + playbook: scripts/ansible/client-auto-update.yml + directory: ./ + key: ${{ secrets.ANSIBLE_SSH_PRIVATE_KEY }} + inventory: ${{ secrets.ANSIBLE_INVENTORY }} + diff --git a/.github/workflows/docker-hub-parachain.yml b/.github/workflows/docker-hub-parachain.yml index 75763740d..278d0c8bb 100644 --- a/.github/workflows/docker-hub-parachain.yml +++ b/.github/workflows/docker-hub-parachain.yml @@ -1,18 +1,20 @@ name: Publish features parachain to Docker Hub on: - push: - tags: - - '*' workflow_dispatch: + push: + tags: + - '^v[0-9]+.[0-9]+.[0-9]+$' 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 @@ -38,7 +40,7 @@ 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 @@ -46,4 +48,25 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - + + - name: Update image version of the existing Zeitgeist 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_ZG }} + onf-sub-command: image + onf-action: add + image-version: ${{ steps.vars.outputs.tag }} + + - name: Update image version of the existing Battery Station 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_BS }} + onf-sub-command: image + onf-action: add + image-version: ${{ steps.vars.outputs.tag }} diff --git a/scripts/ansible/client-auto-update-playbook.yml b/scripts/ansible/client-auto-update-playbook.yml new file mode 100644 index 000000000..3279ff6fd --- /dev/null +++ b/scripts/ansible/client-auto-update-playbook.yml @@ -0,0 +1,71 @@ +- hosts: zeitgeist + gather_facts: no + become: true + environment: + RELEASE_VERSION: "{{ lookup('env', 'RELEASE_VERSION') }}" + + tasks: + - name: Get Zeitgeist services + no_log: true + 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: Remove Previous Zeitgeist Client in Mount Dir + no_log: true + shell: | + cd /mnt/*/services/zeitgeist/bin + rm zeitgeist + when: mnt.stat.exists and mnt.stat.isdir + + - name: Remove Previous Zeitgeist Client + no_log: true + shell: | + cd /services/zeitgeist/bin + rm zeitgeist + when: not mnt.stat.exists and mnt.stat.isdir + + - name: Download Zeitgeist Client to Mount Dir + no_log: true + shell: | + cd /mnt/*/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.9/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.9/zeitgeist_parachain + 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 }}"