Deploy the current version of Crypter to a specific environment #252
Workflow file for this run
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: | |
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@v4 | |
- 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: 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 ${{ env.docker_compose_profile }} 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.docker_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 |