-
Notifications
You must be signed in to change notification settings - Fork 136
206 lines (184 loc) · 7.35 KB
/
docker.yml
File metadata and controls
206 lines (184 loc) · 7.35 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
name: Docker Build and Push
on:
workflow_dispatch:
inputs:
version:
description: 'Version tag (e.g., v5.0.0)'
required: true
type: string
push:
description: 'Push to registry'
required: false
type: boolean
default: true
release:
types: [published]
env:
REGISTRY: ghcr.io
IMAGE_BASE: ghcr.io/${{ github.repository_owner }}/stratos
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: 'true'
permissions:
contents: read
packages: write
jobs:
build-matrix:
name: Build Container Images
runs-on: ubuntu-latest
strategy:
matrix:
component: [ui, backend]
platform: [linux/amd64, linux/arm64]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get version
id: version
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
VERSION="${{ inputs.version }}"
else
VERSION="${{ github.event.release.tag_name }}"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "version_short=${VERSION#v}" >> $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 GitHub Container Registry
if: github.event_name != 'workflow_dispatch' || inputs.push
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for ${{ matrix.component }}
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_BASE }}-${{ matrix.component }}
tags: |
type=semver,pattern={{version}},value=${{ steps.version.outputs.version }}
type=semver,pattern={{major}}.{{minor}},value=${{ steps.version.outputs.version }}
type=semver,pattern={{major}},value=${{ steps.version.outputs.version }}
type=raw,value=latest,enable=${{ !contains(steps.version.outputs.version, '-') }}
- name: Build and push ${{ matrix.component }} (${{ matrix.platform }})
uses: docker/build-push-action@v5
with:
context: .
file: deploy/Dockerfile.${{ matrix.component == 'backend' && 'bk' || 'ui' }}
platforms: ${{ matrix.platform }}
push: ${{ github.event_name != 'workflow_dispatch' || inputs.push }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
target: prod-build
build-args: |
stratos_version=${{ steps.version.outputs.version_short }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-all-in-one:
name: Build All-in-One Image
runs-on: ubuntu-latest
needs: build-matrix
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get version
id: version
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
VERSION="${{ inputs.version }}"
else
VERSION="${{ github.event.release.tag_name }}"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "version_short=${VERSION#v}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
if: github.event_name != 'workflow_dispatch' || inputs.push
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Check for all-in-one Dockerfile
id: check-aio
run: |
if [ -f "deploy/all-in-one/Dockerfile" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "⚠️ All-in-one Dockerfile not found, skipping"
fi
- name: Extract metadata
if: steps.check-aio.outputs.exists == 'true'
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_BASE }}
tags: |
type=semver,pattern={{version}},value=${{ steps.version.outputs.version }}
type=semver,pattern={{major}}.{{minor}},value=${{ steps.version.outputs.version }}
type=semver,pattern={{major}},value=${{ steps.version.outputs.version }}
type=raw,value=latest,enable=${{ !contains(steps.version.outputs.version, '-') }}
- name: Build and push all-in-one
if: steps.check-aio.outputs.exists == 'true'
uses: docker/build-push-action@v5
with:
context: .
file: deploy/all-in-one/Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'workflow_dispatch' || inputs.push }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
stratos_version=${{ steps.version.outputs.version_short }}
cache-from: type=gha
cache-to: type=gha,mode=max
verify-images:
name: Verify Images
runs-on: ubuntu-latest
needs: [build-matrix, build-all-in-one]
if: github.event_name != 'workflow_dispatch' || inputs.push
steps:
- name: Get version
id: version
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
VERSION="${{ inputs.version }}"
else
VERSION="${{ github.event.release.tag_name }}"
fi
echo "version=${VERSION#v}" >> $GITHUB_OUTPUT
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Verify UI image
run: |
docker pull ${{ env.IMAGE_BASE }}-ui:${{ steps.version.outputs.version }}
docker inspect ${{ env.IMAGE_BASE }}-ui:${{ steps.version.outputs.version }}
- name: Verify backend image
run: |
docker pull ${{ env.IMAGE_BASE }}-backend:${{ steps.version.outputs.version }}
docker inspect ${{ env.IMAGE_BASE }}-backend:${{ steps.version.outputs.version }}
- name: Summary
run: |
echo "# 🐳 Docker Images Published!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## Images" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- \`${{ env.IMAGE_BASE }}-ui:${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
echo "- \`${{ env.IMAGE_BASE }}-backend:${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## Usage" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo "docker pull ${{ env.IMAGE_BASE }}-ui:${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "docker pull ${{ env.IMAGE_BASE }}-backend:${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ All images verified successfully!" >> $GITHUB_STEP_SUMMARY