Skip to content

Deploy mnemosyne

Deploy mnemosyne #56

name: Deploy mnemosyne
on:
workflow_dispatch:
inputs:
stack:
required: true
type: string
default: next
description: Either 'next' (to deploy the development version) or 'stable' (to deploy to production)
env:
REGISTRY: ghcr.io
jobs:
build:
runs-on: ubuntu-latest
env:
IMAGE_NAME: ${{ github.repository }}_node_${{ inputs.stack }}
BRANCH_REF: ${{ inputs.stack }}
outputs:
image: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout source code
uses: actions/checkout@master
with:
ref: ${{ env.BRANCH_REF }}
- name: Log in to the Container registry
uses: docker/login-action@master
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@master
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha
- name: Build and push
uses: docker/build-push-action@master
with:
context: .
build-args: |
NODE_ENV=production
TZ=utc
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
deploy:
needs: [build]
env:
BRANCH_REF: ${{ inputs.stack }}
DEPLOY_SOURCE: deploy/${{ inputs.stack }}/stack.yml
STACK_COMPOSE_PATH: /home/runner/mnemosyne/deploy/${{ inputs.stack }}/stack.yml
STACK_CONFIG_PATH: /home/runner/mnemosyne/deploy/${{ inputs.stack }}/stack.env
runs-on: saeon
steps:
- name: Check out source code (shared)
uses: actions/checkout@master
with:
ref: ${{ env.BRANCH_REF }}
- name: (SCP) Copy stack configuration to app server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SWARM_HOSTNAME }}
username: ${{ secrets.SWARM_USERNAME }}
password: ${{ secrets.SWARM_PASSWORD }}
port: ${{ secrets.SWARM_SSH_PORT }}
source: ${{ env.DEPLOY_SOURCE }}
target: 'mnemosyne'
- name: (SSH) Deploy stack
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SWARM_HOSTNAME }}
username: ${{ secrets.SWARM_USERNAME }}
password: ${{ secrets.SWARM_PASSWORD }}
port: ${{ secrets.SWARM_SSH_PORT }}
script: |
echo "DOCKER_IMAGE=${{ needs.build.outputs.image }}" > ${{ env.STACK_CONFIG_PATH }}
echo "KEY=${{ secrets.APP_KEY }}" >> ${{ env.STACK_CONFIG_PATH }}
sudo /opt/deploy-docker-stack.sh ${{ env.STACK_COMPOSE_PATH }} ${{ env.STACK_CONFIG_PATH }} mnemosyne_${{ inputs.stack }}