From 6f798967e72c353288c71002b642664c1988c6f2 Mon Sep 17 00:00:00 2001 From: Michael Brusegard <56915010+michaelbrusegard@users.noreply.github.com> Date: Mon, 23 Sep 2024 18:52:36 +0200 Subject: [PATCH] ci: move deployment script to its own file --- .github/workflows/deploy-script.yml | 38 ++++++++++++++++++++++ .github/workflows/deploy.yml | 50 +++++++++++------------------ 2 files changed, 56 insertions(+), 32 deletions(-) create mode 100644 .github/workflows/deploy-script.yml diff --git a/.github/workflows/deploy-script.yml b/.github/workflows/deploy-script.yml new file mode 100644 index 0000000..655ec36 --- /dev/null +++ b/.github/workflows/deploy-script.yml @@ -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/ssh-action@v1.0.3 + 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 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 13997b9..d050155 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -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/ssh-action@v1.0.3 - 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/ssh-action@v1.0.3 - 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 }}