Skip to content

πŸ”¨ fix : μ„œλ²„ μš©λŸ‰ 확인 #54

πŸ”¨ fix : μ„œλ²„ μš©λŸ‰ 확인

πŸ”¨ fix : μ„œλ²„ μš©λŸ‰ 확인 #54

Workflow file for this run

name: Deploy to GCP GCE
on:
push:
branches: [ "release" ]
workflow_dispatch:
env:
IMAGE_NAME: resttest-be
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GCP_REGION: ${{ secrets.GCP_REGION }}
ARTIFACT_REPO: ${{ secrets.ARTIFACT_REPO }}
ARTIFACT_REGISTRY: ${{ secrets.GCP_REGION }}-docker.pkg.dev
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v3
- name: Auth to GCP
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
with:
project_id: ${{ env.GCP_PROJECT_ID }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Configure Docker for Artifact Registry
run: |
gcloud auth configure-docker ${{ env.ARTIFACT_REGISTRY }} --quiet
- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ env.ARTIFACT_REGISTRY }}/${{ env.GCP_PROJECT_ID }}/${{ env.ARTIFACT_REPO }}/${{ env.IMAGE_NAME }}:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Deploy to GCE via SSH
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.GCE_HOST }}
username: ${{ secrets.GCE_SSH_USER }}
key: ${{ secrets.GCE_SSH_KEY }}
script: |
# λ””μŠ€ν¬ μƒνƒœ 확인
echo "=== Disk usage before cleanup ==="
df -h
echo ""
echo "=== Docker system usage ==="
docker system df
echo ""
# λ””μŠ€ν¬ 곡간 확보 (λ³Όλ₯¨ μ œμ™Έ)
echo "=== Cleaning up disk space ==="
docker system prune -a -f
docker builder prune -a -f
echo ""
echo "=== Disk usage after cleanup ==="
df -h
echo ""
mkdir -p ~/app-path
cd ~/app-path
cat << 'EOF' > .env
${{ secrets.ENV_PROD }}
EOF
cat << 'COMPOSE_EOF' > docker-compose.prod.yml
version: "3.9"
services:
redis:
image: redis:alpine
container_name: redis-prod
ports:
- "6379:6379"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
fastapi:
image: us-west1-docker.pkg.dev/resttest-479411/resttest-be/resttest-be:latest
container_name: resttest-prod
command: uvicorn main:app --host 0.0.0.0 --port 8080
ports:
- "80:8080"
env_file:
- .env
environment:
- MODE=prod
- REDIS_HOST=redis
- REDIS_PORT=6379
depends_on:
redis:
condition: service_healthy
COMPOSE_EOF
gcloud auth configure-docker ${{ env.ARTIFACT_REGISTRY }} --quiet
docker compose -f docker-compose.prod.yml down
docker compose -f docker-compose.prod.yml pull
docker compose -f docker-compose.prod.yml run --rm -e MODE=prod fastapi alembic upgrade head
docker compose -f docker-compose.prod.yml up -d