Deploy API Gateway to DigitalOcean (PRE) #13
This file contains hidden or 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 API Gateway to DigitalOcean (PRE) | |
| on: | |
| workflow_dispatch: # Allows manual triggering | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Step 1: Checkout the code | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| # Step 2: Build the Docker image | |
| - name: Build Docker Image | |
| run: | | |
| docker build -t api-gateway:latest -f ./docker/Dockerfile ./docker | |
| # Step 3: Save and compress the Docker image | |
| - name: Save and Compress Docker Image | |
| run: | | |
| docker save api-gateway:latest > api-gateway.tar.gz | |
| # Step 4: Transfer compressed Docker image to the remote server | |
| - name: Transfer Docker Image to Droplet | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ${{ secrets.SSH_USERNAME }} | |
| key: ${{ secrets.SSH_KEY }} | |
| source: api-gateway.tar.gz | |
| target: /opt/summoners-sync/api-gateway | |
| # Step 5: Load and run the Docker image on the remote server | |
| - name: Deploy Docker Image on Remote | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ${{ secrets.SSH_USERNAME }} | |
| key: ${{ secrets.SSH_KEY }} | |
| script: | | |
| set -e | |
| # Navigate to deployment directory | |
| cd /opt/summoners-sync/api-gateway | |
| # Load the Docker image | |
| docker load < api-gateway.tar.gz | |
| # Stop and remove existing container if it exists | |
| docker stop api-gateway || true | |
| docker rm api-gateway || true | |
| # Run the new container | |
| docker run -d --name api-gateway --restart always api-gateway:latest |