Deploy the current version of Crypter to a specific environment #24
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 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: | |
db_migration_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@v3 | |
- name: Stop service | |
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 }} | |
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/[email protected] | |
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: Create directory to store variables as files | |
run: mkdir scp-files | |
- name: Write latest .env to temp file | |
run: ${{ secrets.APPSERVER_ENV_FILE }} > scp-files/.env | |
- name: Push latest .env 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: scp-files/.env | |
target: ${{ secrets.APPSERVER_ENV_FILE_PATH }} | |
strip_components: 1 | |
- name: Write latest appsettings.json to temp file | |
run: ${{ secrets.APPSERVER_APPSETTINGS_JSON }} > scp-files/appsettings.json | |
- name: Push latest appsettings.json 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: scp-files/appsettings.json | |
target: ${{ secrets.APPSERVER_APPSETTINGS_JSON_PATH }} | |
strip_components: 1 | |
- 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/[email protected] | |
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 web pull | |
script_stop: true | |
- name: Migrate database | |
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 }} | |
script: docker compose --project-directory crypter-web-container --profile ${{ env.db_migration_compose_profile }} run api /app/efbundle | |
script_stop: true | |
- name: Start service | |
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 }} | |
script: systemctl --user start crypter.service | |
script_stop: true |