Skip to content

Continuous Deployment #3

Continuous Deployment

Continuous Deployment #3

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 }}
SERVER: server
CLIENT: client
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: packages/${{ env.SERVER }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- 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: ./packages/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: packages/${{ env.CLIENT }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Install dependencies
run: pnpm install --no-frozen-lockfile
- run: VITE_API_URL=https://snake-demo-server.paradym.id pnpm 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: ./packages/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: paradym-snake-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:
PARADYM_API_KEY: ${{ secrets.PARADYM_API_KEY }}
PARADYM_WORKFLOW_ID: ${{ vars.PARADYM_WORKFLOW_ID }}
PARADYM_HMAC_SIGNATURE: ${{ secrets.PARADYM_HMAC_SIGNATURE }}
with:
host: dashboard.dev.animo.id
username: root
key: ${{ secrets.DOCKER_SSH_PRIVATE_KEY }}
envs: PARADYM_API_KEY,PARADYM_WORKFLOW_ID,PARADYM_HMAC_SIGNATURE
script: |
PARADYM_HMAC_SIGNATURE=${PARADYM_HMAC_SIGNATURE} PARADYM_WORKFLOW_ID=${PARADYM_WORKFLOW_ID} PARADYM_API_KEY=${PARADYM_API_KEY} docker stack deploy --compose-file paradym-snake-demo/docker-compose.yml paradym-snake-demo --with-registry-auth