-
Notifications
You must be signed in to change notification settings - Fork 10
89 lines (76 loc) · 2.85 KB
/
docker-publish.yml
File metadata and controls
89 lines (76 loc) · 2.85 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: Build and push Docker image
on:
push:
branches: [ main ]
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-tags: true
fetch-depth: 0
- name: Generate version
id: version
run: |
VERSION=$(date -u +%Y.%m.%d)
# Count existing tags for today and increment
EXISTING=$(git tag -l "v${VERSION}*" | wc -l)
if [ "$EXISTING" -gt "0" ]; then
VERSION="${VERSION}.$((EXISTING + 1))"
fi
# Make sure the tag doesn't already exist
while git tag -l "v${VERSION}" | grep -q .; do
EXISTING=$((EXISTING + 1))
VERSION="$(date -u +%Y.%m.%d).${EXISTING}"
done
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
daalves/bridge-bank:latest
daalves/bridge-bank:${{ steps.version.outputs.version }}
build-args: |
APP_VERSION=${{ steps.version.outputs.version }}
- name: Tag version in git
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git tag "v${{ steps.version.outputs.version }}"
git push origin "v${{ steps.version.outputs.version }}"
- name: Deploy to server
if: github.ref == 'refs/heads/main'
run: |
# Install cloudflared
curl -fsSL https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o /usr/local/bin/cloudflared
chmod +x /usr/local/bin/cloudflared
# Set up SSH key
mkdir -p ~/.ssh
echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
# SSH through Cloudflare Tunnel
ssh -o StrictHostKeyChecking=no \
-o ProxyCommand="cloudflared access ssh --hostname ssh-deploy.david-alves.com" \
-i ~/.ssh/deploy_key \
${{ secrets.DEPLOY_SSH_USER }}@ssh-deploy.david-alves.com \
"docker pull daalves/bridge-bank:latest && docker compose -f /opt/docker/bridge-bank/docker-compose.yml up -d bridge-bank"
# Clean up
rm -f ~/.ssh/deploy_key