Skip to content

Deploy API Gateway to DigitalOcean (PRE) #12

Deploy API Gateway to DigitalOcean (PRE)

Deploy API Gateway to DigitalOcean (PRE) #12

Workflow file for this run

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 | gzip > api-gateway.tar.gz
ls -lh 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/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/api-gateway
# Load the Docker image
gunzip -c api-gateway.tar.gz | docker load
# 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 -p 80:80 api-gateway:latest