diff --git a/.github/workflows/deploy-staging.yaml b/.github/workflows/deploy-staging.yaml new file mode 100644 index 0000000..49f8e51 --- /dev/null +++ b/.github/workflows/deploy-staging.yaml @@ -0,0 +1,19 @@ +name: Deploy application to staging environment + +on: + push: + branches: [main] + workflow_dispatch: + +jobs: + deploy: + runs-on: [self-hosted] + steps: + - name: Execute the build and run script on the server + uses: appleboy/ssh-action@v0.1.7 + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USERNAME }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + port: ${{ secrets.SSH_PORT }} + script: "/services/duogradus/build-and-run.sh" diff --git a/build-and-run.sh b/build-and-run.sh new file mode 100755 index 0000000..d2fc903 --- /dev/null +++ b/build-and-run.sh @@ -0,0 +1,13 @@ +# Stop the current docker compose server +docker compose down + +# Download the current code main branch from github +git fetch --all +# Yes, this is the desired option! +git reset --hard origin/master + +# Rebuild the images with the new code +docker compose build + +# Restart the service +docker compose up -d \ No newline at end of file