Skip to content

Deploy the current version of Crypter to a specific environment #216

Deploy the current version of Crypter to a specific environment

Deploy the current version of Crypter to a specific environment #216

name: Deploy the current version of Crypter to a specific environment
on:
workflow_dispatch:
inputs:
environment:
description: 'Define the environment name'
required: true
type: choice
options:
- production
- development
env:
docker_compose_profile: ${{ (github.event.inputs.environment == 'development' && 'local') || 'web' }}
jobs:
deploy-web-container:
runs-on: ubuntu-latest
environment:
name: ${{ github.event.inputs.environment }}
steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Stop service
uses: appleboy/ssh-action@029f5b4aeeeb58fdfe1410a5d17f967dacf36262 # v1.0.3
with:
host: ${{ secrets.APPSERVER_SSH_HOST }}
port: ${{ secrets.APPSERVER_SSH_PORT }}
username: ${{ secrets.APPSERVER_SSH_USER }}
key: ${{ secrets.APPSERVER_SSH_PRIVATE_KEY }}
script: |
if [ "$(systemctl --user is-active crypter.service)" = "active" ]; then
echo "Stopping service"
systemctl --user stop crypter.service;
fi
script_stop: true
- name: Push latest systemctl service file
uses: appleboy/[email protected]
with:
host: ${{ secrets.APPSERVER_SSH_HOST }}
port: ${{ secrets.APPSERVER_SSH_PORT }}
username: ${{ secrets.APPSERVER_SSH_USER }}
key: ${{ secrets.APPSERVER_SSH_PRIVATE_KEY }}
source: Environments/${{ github.event.inputs.environment }}/crypter.service
target: .config/systemd/user/
strip_components: 2
- name: Reload systemctl daemon
uses: appleboy/ssh-action@029f5b4aeeeb58fdfe1410a5d17f967dacf36262 # v1.0.3
with:
host: ${{ secrets.APPSERVER_SSH_HOST }}
port: ${{ secrets.APPSERVER_SSH_PORT }}
username: ${{ secrets.APPSERVER_SSH_USER }}
key: ${{ secrets.APPSERVER_SSH_PRIVATE_KEY }}
script: systemctl --user daemon-reload
- name: Push latest Docker Compose file
uses: appleboy/[email protected]
with:
host: ${{ secrets.APPSERVER_SSH_HOST }}
port: ${{ secrets.APPSERVER_SSH_PORT }}
username: ${{ secrets.APPSERVER_SSH_USER }}
key: ${{ secrets.APPSERVER_SSH_PRIVATE_KEY }}
source: docker-compose.yml
target: crypter-web-container/
- name: Push latest Docker Compose override file if deploying to Development server
if: github.event.inputs.environment == 'development'
uses: appleboy/[email protected]
with:
host: ${{ secrets.APPSERVER_SSH_HOST }}
port: ${{ secrets.APPSERVER_SSH_PORT }}
username: ${{ secrets.APPSERVER_SSH_USER }}
key: ${{ secrets.APPSERVER_SSH_PRIVATE_KEY }}
source: docker-compose.override.yml
target: crypter-web-container/
- name: Pull latest images
uses: appleboy/ssh-action@029f5b4aeeeb58fdfe1410a5d17f967dacf36262 # v1.0.3
with:
host: ${{ secrets.APPSERVER_SSH_HOST }}
port: ${{ secrets.APPSERVER_SSH_PORT }}
username: ${{ secrets.APPSERVER_SSH_USER }}
key: ${{ secrets.APPSERVER_SSH_PRIVATE_KEY }}
script: docker compose --project-directory crypter-web-container --profile ${{ env.docker_compose_profile }} pull
script_stop: true
- name: Migrate database
uses: appleboy/ssh-action@029f5b4aeeeb58fdfe1410a5d17f967dacf36262 # v1.0.3
with:
host: ${{ secrets.APPSERVER_SSH_HOST }}
port: ${{ secrets.APPSERVER_SSH_PORT }}
username: ${{ secrets.APPSERVER_SSH_USER }}
key: ${{ secrets.APPSERVER_SSH_PRIVATE_KEY }}
script: docker compose --project-directory crypter-web-container --profile ${{ env.docker_compose_profile }} run api /app/efbundle
script_stop: true
- name: Start service
uses: appleboy/ssh-action@029f5b4aeeeb58fdfe1410a5d17f967dacf36262 # v1.0.3
with:
host: ${{ secrets.APPSERVER_SSH_HOST }}
port: ${{ secrets.APPSERVER_SSH_PORT }}
username: ${{ secrets.APPSERVER_SSH_USER }}
key: ${{ secrets.APPSERVER_SSH_PRIVATE_KEY }}
script: systemctl --user start crypter.service
script_stop: true