-
Notifications
You must be signed in to change notification settings - Fork 24
162 lines (140 loc) · 5.38 KB
/
Copy pathdocker-build-deploy.yml
File metadata and controls
162 lines (140 loc) · 5.38 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Docker Build and Deploy
on:
push:
branches:
- main
- github-actions # For testing workflow changes
env:
REGISTRY: ghcr.io
IMAGE_NAME: dohsimpson/tasktrove
jobs:
build-and-push:
runs-on: ubuntu-latest
outputs:
EXISTS: ${{ steps.check-version.outputs.EXISTS }}
VERSION: ${{ steps.package-version.outputs.VERSION }}
IMAGE_DIGEST: ${{ steps.build.outputs.digest }}
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
- name: Get version from package.json
id: package-version
run: echo "VERSION=$(node -p "require('./apps/web/package.json').version")" >> $GITHUB_OUTPUT
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Check if version exists
id: check-version
run: |
if docker manifest inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:v${{ steps.package-version.outputs.VERSION }} >/dev/null 2>&1; then
echo "EXISTS=true" >> $GITHUB_OUTPUT
echo "Version v${{ steps.package-version.outputs.VERSION }} already exists"
else
echo "EXISTS=false" >> $GITHUB_OUTPUT
echo "Version v${{ steps.package-version.outputs.VERSION }} is new"
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=dev
type=raw,value=v${{ steps.package-version.outputs.VERSION }},enable=${{ steps.check-version.outputs.EXISTS == 'false' }}
type=raw,value=latest,enable=${{ steps.check-version.outputs.EXISTS == 'false' }}
type=raw,value=demo,enable=${{ steps.check-version.outputs.EXISTS == 'false' }}
- name: Build and push Docker image
id: build
uses: docker/build-push-action@v6
with:
context: .
file: ./apps/web/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v2
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
subject-digest: ${{ steps.build.outputs.digest }}
push-to-registry: true
deploy-demo:
runs-on: ubuntu-latest
needs: build-and-push
if: needs.build-and-push.outputs.EXISTS == 'false'
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Deploy to demo instance
uses: actions-hub/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
args: rollout restart -n ${{ secrets.KUBE_NAMESPACE }} deployment/${{ secrets.KUBE_DEPLOYMENT }}
create-release:
runs-on: ubuntu-latest
needs: build-and-push
if: needs.build-and-push.outputs.EXISTS == 'false'
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Extract changelog for version
id: changelog
env:
VERSION: ${{ needs.build-and-push.outputs.VERSION }}
run: |
# Extract release notes from CHANGELOG.md using same approach as HabitTrove
notes=$(awk -v version="$VERSION" '
/^## / && $0 ~ version {flag=1;next}
/^## / && flag {exit}
flag' CHANGELOG.md)
if [ -z "$notes" ]; then
echo "No changelog found for version $VERSION, using auto-generated notes"
echo "USE_AUTO_NOTES=true" >> $GITHUB_OUTPUT
else
# Save changelog section to output
echo "RELEASE_NOTES<<EOF" >> $GITHUB_OUTPUT
echo "$notes" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "USE_AUTO_NOTES=false" >> $GITHUB_OUTPUT
fi
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.build-and-push.outputs.VERSION }}
USE_AUTO_NOTES: ${{ steps.changelog.outputs.USE_AUTO_NOTES }}
RELEASE_NOTES: ${{ steps.changelog.outputs.RELEASE_NOTES }}
run: |
if [ "$USE_AUTO_NOTES" = "true" ]; then
# Fallback to auto-generated notes if no changelog found
gh release create "v$VERSION" \
--repo="$GITHUB_REPOSITORY" \
--title="TaskTrove v$VERSION" \
--generate-notes \
--notes-start-tag=$(gh release list --limit 1 --json tagName --jq '.[0].tagName' 2>/dev/null || echo "")
else
# Use changelog content
gh release create "v$VERSION" \
--repo="$GITHUB_REPOSITORY" \
--title="TaskTrove v$VERSION" \
--notes="$RELEASE_NOTES"
fi