Skip to content

Continuous Deployment #52

Continuous Deployment

Continuous Deployment #52

name: Continuous Deployment
on:
workflow_dispatch:
inputs:
build:
default: true
type: boolean
required: false
description: Build the website before deploying
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
CLIENT: client
SERVER: server
jobs:
build-and-push-image-server:
runs-on: ubuntu-latest
if: inputs.build == true && github.ref == 'refs/heads/main'
permissions:
contents: read
packages: write
defaults:
run:
working-directory: ${{ env.SERVER }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup Libindy
uses: ./.github/actions/setup-libindy
- name: Setup NodeJS
uses: ./.github/actions/setup-node
with:
node-version: 16
- name: Install dependencies
run: yarn install
- run: yarn build
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/${{ env.SERVER }}
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: ./server
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-and-push-image-client:
runs-on: ubuntu-latest
if: inputs.build == true && github.ref == 'refs/heads/main'
permissions:
contents: read
packages: write
defaults:
run:
working-directory: ${{ env.CLIENT }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup Libindy
uses: ./.github/actions/setup-libindy
- name: Install dependencies
run: yarn install
- run: REACT_APP_HOST_BACKEND=${{ secrets.REACT_APP_HOST_BACKEND }} REACT_APP_HOST_WEBSOCKET=${{ secrets.REACT_APP_HOST_WEBSOCKET }} yarn build
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/${{ env.CLIENT }}
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: ./client
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
deploy:
# Only run on main branch
runs-on: ubuntu-latest
needs: [build-and-push-image-server, build-and-push-image-client]
if: |
always() &&
(needs.build-and-push-image-server.result == 'success' || needs.build-and-push-image-server.result == 'skipped') &&
(needs.build-and-push-image-client.result == 'success' || needs.build-and-push-image-client.result == 'skipped') &&
github.ref == 'refs/heads/main'
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Copy stack file to remote
uses: garygrossgarten/[email protected]
with:
local: docker-compose.yml
remote: animo-demo/docker-compose.yml
host: dashboard.dev.animo.id
username: root
privateKey: ${{ secrets.DOCKER_SSH_PRIVATE_KEY }}
- name: Deploy to Docker Swarm via SSH action
uses: appleboy/[email protected]
env:
AGENT_PUBLIC_DID_SEED: ${{ secrets.AGENT_PUBLIC_DID_SEED }}
AGENT_WALLET_KEY: ${{ secrets.AGENT_WALLET_KEY }}
with:
host: dashboard.dev.animo.id
username: root
key: ${{ secrets.DOCKER_SSH_PRIVATE_KEY }}
envs: AGENT_PUBLIC_DID_SEED,AGENT_WALLET_KEY
script: |
AGENT_PUBLIC_DID_SEED=${AGENT_PUBLIC_DID_SEED} AGENT_WALLET_KEY=${AGENT_WALLET_KEY} docker stack deploy --compose-file animo-demo/docker-compose.yml demo --with-registry-auth