Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
52d7118c33 | ||
|
|
d7631ec671 | ||
|
|
f6eeaed97d |
@@ -7,9 +7,6 @@ on:
|
||||
description: 'Release tag to deploy (e.g. v3.3.0)'
|
||||
required: true
|
||||
|
||||
env:
|
||||
IMAGE: git.adlee.work/alee/golfgame
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -20,19 +17,21 @@ jobs:
|
||||
host: ${{ secrets.PROD_HOST }}
|
||||
username: root
|
||||
key: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
envs: IMAGE
|
||||
script: |
|
||||
set -e
|
||||
TAG="${{ github.event.inputs.tag }}"
|
||||
IMAGE="git.adlee.work/alee/golfgame"
|
||||
|
||||
cd /opt/golfgame
|
||||
|
||||
# Pull the same image that passed staging
|
||||
docker login git.adlee.work -u ${{ secrets.REGISTRY_USER }} -p ${{ secrets.REGISTRY_TOKEN }}
|
||||
docker pull $IMAGE:${{ github.event.inputs.tag }}
|
||||
# Pull the image that passed staging
|
||||
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login git.adlee.work -u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
||||
docker pull "$IMAGE:$TAG"
|
||||
docker tag "$IMAGE:$TAG" golfgame-app:latest
|
||||
|
||||
# Tag it so compose uses it
|
||||
docker tag $IMAGE:${{ github.event.inputs.tag }} golfgame-app:latest
|
||||
|
||||
# Update code (for compose file / env changes)
|
||||
git fetch origin && git checkout ${{ github.event.inputs.tag }}
|
||||
# Update code for compose/env changes
|
||||
git fetch origin
|
||||
git checkout "$TAG"
|
||||
|
||||
# Restart app
|
||||
docker compose -f docker-compose.prod.yml up -d app
|
||||
@@ -41,7 +40,7 @@ jobs:
|
||||
echo "Waiting for health check..."
|
||||
for i in $(seq 1 30); do
|
||||
if docker compose -f docker-compose.prod.yml ps app | grep -q "healthy"; then
|
||||
echo "Production deploy successful — ${{ github.event.inputs.tag }}"
|
||||
echo "Production deploy successful — $TAG"
|
||||
exit 0
|
||||
fi
|
||||
sleep 2
|
||||
|
||||
@@ -4,63 +4,43 @@ on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
env:
|
||||
IMAGE: git.adlee.work/alee/golfgame
|
||||
|
||||
jobs:
|
||||
build:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Log in to Gitea Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: git.adlee.work
|
||||
username: ${{ secrets.REGISTRY_USER }}
|
||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||
|
||||
- name: Build and push image
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: |
|
||||
${{ env.IMAGE }}:${{ github.ref_name }}
|
||||
${{ env.IMAGE }}:latest
|
||||
|
||||
deploy:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Deploy to staging
|
||||
- name: Build, push, and deploy to staging
|
||||
uses: appleboy/ssh-action@v1
|
||||
with:
|
||||
host: ${{ secrets.STAGING_HOST }}
|
||||
username: root
|
||||
key: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
envs: IMAGE
|
||||
script: |
|
||||
set -e
|
||||
TAG="${{ github.ref_name }}"
|
||||
IMAGE="git.adlee.work/alee/golfgame"
|
||||
|
||||
cd /opt/golfgame
|
||||
|
||||
# Pull the pre-built image
|
||||
docker login git.adlee.work -u ${{ secrets.REGISTRY_USER }} -p ${{ secrets.REGISTRY_TOKEN }}
|
||||
docker pull $IMAGE:${{ github.ref_name }}
|
||||
# Pull latest code and checkout the release tag
|
||||
git fetch origin
|
||||
git checkout "$TAG"
|
||||
|
||||
# Tag it so compose uses it
|
||||
docker tag $IMAGE:${{ github.ref_name }} golfgame-app:latest
|
||||
# Build the image
|
||||
docker build -t "$IMAGE:$TAG" -t "$IMAGE:latest" -t golfgame-app:latest .
|
||||
|
||||
# Update code (for compose file / env changes)
|
||||
git fetch origin && git checkout ${{ github.ref_name }}
|
||||
# Push to Gitea container registry
|
||||
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login git.adlee.work -u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
||||
docker push "$IMAGE:$TAG"
|
||||
docker push "$IMAGE:latest"
|
||||
|
||||
# Restart app (no --build, image is pre-built)
|
||||
# Restart app (no --build, image already tagged)
|
||||
docker compose -f docker-compose.staging.yml up -d app
|
||||
|
||||
# Wait for healthy
|
||||
echo "Waiting for health check..."
|
||||
for i in $(seq 1 30); do
|
||||
if docker compose -f docker-compose.staging.yml ps app | grep -q "healthy"; then
|
||||
echo "Staging deploy successful — ${{ github.ref_name }}"
|
||||
echo "Staging deploy successful — $TAG"
|
||||
exit 0
|
||||
fi
|
||||
sleep 2
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
|
||||
<title>Golf Card Game</title>
|
||||
<link rel="icon" type="image/svg+xml" href="golfball-logo.svg">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
42
scripts/deploy-prod.sh
Executable file
42
scripts/deploy-prod.sh
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
TAG="${1:?Usage: deploy-prod.sh <tag> (e.g. v3.3.2)}"
|
||||
DROPLET="root@165.245.152.51"
|
||||
IMAGE="git.adlee.work/alee/golfgame"
|
||||
|
||||
echo "Deploying $TAG to production ($DROPLET)..."
|
||||
|
||||
ssh $DROPLET bash -s "$TAG" "$IMAGE" <<'REMOTE'
|
||||
set -e
|
||||
TAG="$1"
|
||||
IMAGE="$2"
|
||||
|
||||
cd /opt/golfgame
|
||||
|
||||
# Pull the image that passed staging
|
||||
docker pull "$IMAGE:$TAG"
|
||||
docker tag "$IMAGE:$TAG" golfgame-app:latest
|
||||
|
||||
# Update code for compose/env changes
|
||||
git fetch origin
|
||||
git checkout "$TAG"
|
||||
|
||||
# Restart app
|
||||
docker compose -f docker-compose.prod.yml up -d app
|
||||
|
||||
# Wait for healthy
|
||||
echo "Waiting for health check..."
|
||||
for i in $(seq 1 30); do
|
||||
if docker compose -f docker-compose.prod.yml ps app | grep -q "healthy"; then
|
||||
echo "Production deploy successful — $TAG"
|
||||
exit 0
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
echo "CRITICAL: app not healthy after 60s"
|
||||
docker compose -f docker-compose.prod.yml logs --tail=30 app
|
||||
exit 1
|
||||
REMOTE
|
||||
|
||||
echo "Done."
|
||||
Reference in New Issue
Block a user