Repository navigation
52 lines (42 loc) · 1.67 KB
/
Copy pathdeploy.yml
File metadata and controls
52 lines (42 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
name: Deploy to Server (Production)
on:
workflow_dispatch:
inputs:
tag:
description: "Docker image tag (e.g. latest or SHA)"
required: false
default: "latest"
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Deploy via SSH
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.PROD_SERVER_HOST }}
username: ${{ secrets.PROD_SERVER_USER }}
key: ${{ secrets.PROD_SERVER_SSH_KEY }}
script: |
set -e
TAG="${{ github.event.inputs.tag || 'latest' }}"
COMPOSE_FILE="docker-compose.app.yml"
echo "🔐 Logging into GHCR..."
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
echo "📂 Switching to /opt/algotecture"
cd /opt/algotecture
echo "🔄 Resetting compose file to use :latest placeholders"
# Replace all tags back to :latest to avoid accumulating many tags
sed -i -E 's/(ghcr\.io\/[^:]+):[a-zA-Z0-9_.-]+/\1:latest/g' "$COMPOSE_FILE"
if [ "$TAG" != "latest" ]; then
echo "🎯 Applying tag: $TAG"
sed -i "s/:latest/:$TAG/g" "$COMPOSE_FILE"
fi
echo "📦 Pulling updated images..."
docker compose -f "$COMPOSE_FILE" pull
echo "🚀 Restarting all services..."
docker compose -f "$COMPOSE_FILE" up -d
echo "🧹 Cleaning Docker disk space..."
docker image prune -af
docker container prune -f
docker builder prune -af
echo "🟢 Deployment finished successfully."