Skip to content

Commit

Permalink
ci: move deployment script to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbrusegard committed Sep 23, 2024
1 parent 58164cc commit 6f79896
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 32 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/deploy-script.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: SSH Deploy Script

on:
workflow_call:
inputs:
environment:
required: true
type: string
branch:
required: true
type: string
secrets:
host:
required: true
port:
required: true
key:
required: true
username:
required: true

jobs:
deploy:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- uses: appleboy/[email protected]
with:
host: ${{ secrets.host }}
port: ${{ secrets.port }}
key: ${{ secrets.key }}
username: ${{ secrets.username }}
script: |
cd ${GITHUB_REPOSITORY##*/}
git checkout ${{ inputs.branch }}
git pull
docker compose down
docker compose up -d
50 changes: 18 additions & 32 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,26 @@ on:
jobs:
deploy-prod:
name: Production
runs-on: ubuntu-latest
environment: Production
if: github.ref == 'refs/heads/main' || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'Production')
steps:
- name: Executing remote SSH commands using SSH key
uses: appleboy/[email protected]
with:
username: ${{ secrets.USERNAME }}
host: ${{ secrets.HOST }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
script: |
cd ${GITHUB_REPOSITORY##*/}
git checkout ${GITHUB_REF##*/}
git pull
docker compose down
docker compose up -d
uses: ./.github/workflows/deploy-script.yml
with:
environment: Production
branch: main
secrets:
host: ${{ secrets.ssh_host }}
port: ${{ secrets.ssh_port }}
key: ${{ secrets.ssh_key }}
username: ${{ secrets.username }}

deploy-dev:
name: Development
runs-on: ubuntu-latest
environment: Development
if: github.ref == 'refs/heads/dev' || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'Development')
steps:
- name: Executing remote SSH commands using SSH key
uses: appleboy/[email protected]
with:
username: ${{ secrets.USERNAME }}
host: ${{ secrets.HOST }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
script: |
cd ${GITHUB_REPOSITORY##*/}
git checkout ${GITHUB_REF##*/}
git pull
docker compose down
docker compose up -d
uses: ./.github/workflows/deploy-script.yml
with:
environment: Development
branch: dev
secrets:
host: ${{ secrets.ssh_host }}
port: ${{ secrets.ssh_port }}
key: ${{ secrets.ssh_key }}
username: ${{ secrets.username }}

0 comments on commit 6f79896

Please sign in to comment.