-
Notifications
You must be signed in to change notification settings - Fork 1.6k
116 lines (104 loc) · 4.15 KB
/
docker-image.yml
File metadata and controls
116 lines (104 loc) · 4.15 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
name: Build and Push Docker Image
on:
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
build-app:
strategy:
matrix:
include:
- service_name: ui
file: frontend/Dockerfile
context: ./frontend
platform: linux/amd64
runner: ubuntu-latest
- service_name: ui
file: frontend/Dockerfile
context: ./frontend
platform: linux/arm64
runner: buildjet-2vcpu-ubuntu-2204-arm64
- service_name: app
file: docker/Dockerfile.app
context: .
platform: linux/amd64
runner: ubuntu-latest
- service_name: app
file: docker/Dockerfile.app
context: .
platform: linux/arm64
runner: buildjet-2vcpu-ubuntu-2204-arm64
- service_name: docreader
file: docker/Dockerfile.docreader
context: .
platform: linux/amd64
runner: ubuntu-latest
- service_name: docreader
file: docker/Dockerfile.docreader
context: .
platform: linux/arm64
runner: buildjet-2vcpu-ubuntu-2204-arm64
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Set up Go (only for app)
if: matrix.service_name == 'app'
uses: actions/setup-go@v4
with:
go-version: '1.24'
- name: Prepare version info
id: version
run: |
eval "$(./scripts/get_version.sh env)"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "commit_id=$COMMIT_ID" >> $GITHUB_OUTPUT
echo "build_time=$BUILD_TIME" >> $GITHUB_OUTPUT
echo "go_version=$GO_VERSION" >> $GITHUB_OUTPUT
./scripts/get_version.sh info
- name: Build ${{ matrix.service_name }} for ${{ matrix.platform }}
uses: docker/build-push-action@v3
with:
push: true
platforms: ${{ matrix.platform }}
file: ${{ matrix.file }}
context: ${{ matrix.context }}
build-args: |
${{ matrix.service_name == 'app' && format('VERSION_ARG={0}', steps.version.outputs.version) || '' }}
${{ matrix.service_name == 'app' && format('COMMIT_ID_ARG={0}', steps.version.outputs.commit_id) || '' }}
${{ matrix.service_name == 'app' && format('BUILD_TIME_ARG={0}', steps.version.outputs.build_time) || '' }}
${{ matrix.service_name == 'app' && format('GO_VERSION_ARG={0}', steps.version.outputs.go_version) || '' }}
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/weknora-${{ matrix.service_name }}:${{ matrix.platform }}
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/weknora-${{ matrix.service_name }}:${{ matrix.platform }}-cache
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/weknora-${{ matrix.service_name }}:${{ matrix.platform }}-cache,mode=max
merge-manifest:
runs-on: ubuntu-latest
needs: build-app
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Create and push multi-arch manifest
run: |
for service in ui app docreader; do
docker buildx imagetools create \
-t ${{ secrets.DOCKERHUB_USERNAME }}/weknora-$service:latest \
-t ${{ secrets.DOCKERHUB_USERNAME }}/weknora-$service:${{ needs.build-app.outputs.version }} \
${{ secrets.DOCKERHUB_USERNAME }}/weknora-$service:linux/amd64 \
${{ secrets.DOCKERHUB_USERNAME }}/weknora-$service:linux/arm64
done