Deploy API Gateway to DigitalOcean (PRE) #26
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 using Docker Compose | |
| - name: Build Docker Image with Docker Compose | |
| run: | | |
| docker compose -f ./docker/docker-compose.yml build | |
| # 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 | |
| # Stop and remove existing container if it exists | |
| docker stop api-gateway || true | |
| docker rm api-gateway || true | |
| docker rmi api-gateway || true | |
| # Load the Docker image | |
| docker load < api-gateway.tar.gz | |
| # Run the new container | |
| docker run -d --name api-gateway -e SPRING_PROFILES_ACTIVE=dev --restart always api-gateway:latest |