-
Notifications
You must be signed in to change notification settings - Fork 1
77 lines (68 loc) · 2.36 KB
/
docker.yml
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
name: Publish Docker image
on:
push:
branches:
- main
jobs:
build-and-push:
runs-on: ubuntu-24.04
outputs:
image_sha: ${{ steps.determine-tag.outputs.image_sha }} # Output the SHA for deploy
steps:
- name: Checkout
uses: actions/[email protected]
- name: Set up QEMU
uses: docker/[email protected]
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Login to GitHub Container Registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/[email protected]
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=sha # Fallback to SHA
type=raw,value=latest
- name: Build and push Docker image
id: buildandpush
uses: docker/[email protected]
with:
context: .
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Capture SHA from Docker metadata
id: determine-tag
run: |
echo "Capturing image SHA..."
TAGS=$(echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n')
IMAGE_SHA=$(echo "$TAGS" | grep '^.*:sha-' | awk -F':' '{print $NF}' | head -n 1)
echo "Image SHA: $IMAGE_SHA"
echo "image_sha=$IMAGE_SHA" >> $GITHUB_OUTPUT
deploy:
runs-on: ubuntu-24.04
needs: build-and-push
environment: badger-servers
env:
DOCKER_TAG: ${{ needs.build-and-push.outputs.image_sha }} # Pass the SHA to deploy
steps:
- name: Deploy to server
uses: garygrossgarten/[email protected]
with:
command: |
cd badgehub-infra/badgehub
export FRONTEND_IMAGE_TAG=${{ env.DOCKER_TAG }}
echo "FRONTEND_IMAGE_TAG is: $FRONTEND_IMAGE_TAG"
docker-compose -f docker-compose.yml up --no-deps -d badgehub-frontend
host: ${{ secrets.HOST }}
port: ${{ secrets.PORT }}
username: ${{ secrets.USERNAME }}
passphrase: ${{ secrets.PASSPHRASE }}
privateKey: ${{ secrets.PRIVATE_KEY }}