tjsr Deploy Tagtool dev build. #15
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy dev | |
run-name: ${{ github.actor }} Deploy Tagtool dev build. | |
on: | |
workflow_dispatch: | |
inputs: | |
environment: | |
type: choice | |
description: 'Environment ID' | |
required: true | |
default: 'dev' | |
options: | |
- dev | |
- test | |
- prod | |
jobs: | |
deployment: | |
runs-on: ubuntu-latest | |
if: github.actor != 'dependabot[bot]' | |
environment: | |
name: ${{ inputs.environment }} | |
url: https://tagtool.dev.pinpare.com | |
env: | |
IMAGE_TAG: ${{ github.sha }} | |
DB_IMAGE_TAG: dbmigrate-${{ github.sha }} | |
IMAGE_NAME: tagtool:${{ github.sha }} | |
DB_IMAGE_NAME: tagtool:dbmigrate-${{ github.sha }} | |
REGISTRY_ALIAS: tjsrowe | |
PRISMA_DATABASE_URL: ${{ secrets.PRISMA_DATABASE_URL }} | |
CONTAINER_NAME: ${{ vars.CONTAINER_NAME }} | |
API_PORT: ${{ vars.API_PORT }} | |
steps: | |
- name: Pull DB migration deploy image on remote. | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.DEPLOYMENT_HOST }} | |
username: ${{ secrets.DEPLOYMENT_USER }} | |
key: ${{ secrets.DEPLOYMENT_SSH_KEY }} | |
envs: DB_IMAGE_NAME,IMAGE_NAME,REGISTRY_ALIAS | |
script: | | |
docker pull public.ecr.aws/$REGISTRY_ALIAS/$DB_IMAGE_NAME | |
docker tag public.ecr.aws/$REGISTRY_ALIAS/$DB_IMAGE_NAME $DB_IMAGE_NAME | |
- name: Pull API image on remote. | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.DEPLOYMENT_HOST }} | |
username: ${{ secrets.DEPLOYMENT_USER }} | |
key: ${{ secrets.DEPLOYMENT_SSH_KEY }} | |
envs: DB_IMAGE_NAME,IMAGE_NAME,REGISTRY_ALIAS | |
script: | | |
docker pull public.ecr.aws/$REGISTRY_ALIAS/$IMAGE_NAME | |
docker tag public.ecr.aws/$REGISTRY_ALIAS/$IMAGE_NAME $IMAGE_NAME | |
- name: Stop containers and apply DB migration script | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.DEPLOYMENT_HOST }} | |
username: ${{ secrets.DEPLOYMENT_USER }} | |
key: ${{ secrets.DEPLOYMENT_SSH_KEY }} | |
envs: DB_IMAGE_NAME,PRISMA_DATABASE_URL,CONTAINER_NAME | |
script: | | |
docker stop $CONTAINER_NAME || true | |
docker rm $CONTAINER_NAME || true | |
docker run -e PRISMA_DATABASE_URL=$PRISMA_DATABASE_URL --rm --name tagtool-migrate -t $DB_IMAGE_NAME | |
- name: Re-start API container | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.DEPLOYMENT_HOST }} | |
username: ${{ secrets.DEPLOYMENT_USER }} | |
key: ${{ secrets.DEPLOYMENT_SSH_KEY }} | |
envs: IMAGE_NAME,CONTAINER_NAME,API_PORT | |
script: docker run --name $CONTAINER_NAME --restart=always -p $API_PORT:8242 --env-file=/home/ec2-user/tagtool/.env.dev -d -t $IMAGE_NAME |