Skip to content

Commit bda5b2d

Browse files
committed
ci(workflows): adopt short commit hash for service version (#210)
Because - `github.sha` is the complete commit SHA hash which is too long. Shot commit hash is preferred, especially for the backend service log presentation. This commit - adopted short git commit hash for representing the `latest` build version
1 parent c7684a1 commit bda5b2d

File tree

9 files changed

+310
-102
lines changed

9 files changed

+310
-102
lines changed

.github/workflows/images.yml

Lines changed: 148 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,19 @@ on:
1313
types: [published]
1414

1515
jobs:
16-
docker-hub:
17-
runs-on: ubuntu-latest
16+
build-amd64:
17+
runs-on: ubuntu-24.04
1818
steps:
19+
- name: Maximize build space
20+
uses: easimon/maximize-build-space@master
21+
with:
22+
overprovision-lvm: "true"
23+
remove-dotnet: "true"
24+
build-mount-path: "/var/lib/docker/"
25+
26+
- name: Restart docker
27+
run: sudo service docker restart
28+
1929
- uses: actions/checkout@v4
2030
with:
2131
token: ${{ secrets.botGitHubToken }}
@@ -34,19 +44,24 @@ jobs:
3444
3545
password: ${{ secrets.botDockerHubPassword }}
3646

37-
- name: Build and push (latest)
47+
- name: Set short commit SHA
48+
if: github.ref == 'refs/heads/main'
49+
run: |
50+
echo "COMMIT_SHORT_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV
51+
52+
- name: Build and push amd64 (latest)
3853
if: github.ref == 'refs/heads/main'
3954
uses: docker/build-push-action@v6
4055
with:
41-
platforms: linux/amd64,linux/arm64
56+
platforms: linux/amd64
4257
context: .
4358
push: true
4459
build-args: |
4560
SERVICE_NAME=${{ env.SERVICE_NAME }}
46-
SERVICE_VERSION=${{ github.sha }}
47-
tags: instill/artifact-backend:latest
48-
cache-from: type=registry,ref=instill/artifact-backend:buildcache
49-
cache-to: type=registry,ref=instill/artifact-backend:buildcache,mode=max
61+
SERVICE_VERSION=${{ env.COMMIT_SHORT_SHA }}
62+
tags: instill/${{ env.SERVICE_NAME }}:latest-amd64
63+
cache-from: type=registry,ref=instill/${{ env.SERVICE_NAME }}:buildcache
64+
cache-to: type=registry,ref=instill/${{ env.SERVICE_NAME }}:buildcache,mode=max
5065

5166
- name: Set Versions
5267
if: github.event_name == 'release' || startsWith(github.ref, 'refs/tags/')
@@ -59,16 +74,135 @@ jobs:
5974
core.setOutput('tag', tag)
6075
core.setOutput('no_v_tag', no_v_tag)
6176
62-
- name: Build and push (rc/release)
77+
- name: Build and push amd64 (rc/release)
6378
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'release'
6479
uses: docker/build-push-action@v6
6580
with:
66-
platforms: linux/amd64,linux/arm64
81+
platforms: linux/amd64
82+
context: .
83+
push: true
84+
build-args: |
85+
SERVICE_NAME=${{ env.SERVICE_NAME }}
86+
SERVICE_VERSION=${{ steps.set_version.outputs.no_v_tag }}
87+
tags: instill/${{ env.SERVICE_NAME }}:${{ steps.set_version.outputs.no_v_tag }}-amd64
88+
cache-from: type=registry,ref=instill/${{ env.SERVICE_NAME }}:buildcache
89+
cache-to: type=registry,ref=instill/${{ env.SERVICE_NAME }}:buildcache,mode=max
90+
91+
build-arm64:
92+
runs-on: ubuntu-24.04-arm
93+
steps:
94+
- name: Maximize build space
95+
uses: easimon/maximize-build-space@master
96+
with:
97+
overprovision-lvm: "true"
98+
remove-dotnet: "true"
99+
build-mount-path: "/var/lib/docker/"
100+
101+
- name: Restart docker
102+
run: sudo service docker restart
103+
104+
- uses: actions/checkout@v4
105+
with:
106+
token: ${{ secrets.botGitHubToken }}
107+
108+
- name: Load .env file
109+
uses: cardinalby/export-env-action@v2
110+
with:
111+
envFile: .env
112+
113+
- name: Set up Docker Buildx
114+
uses: docker/setup-buildx-action@v3
115+
116+
- name: Login to DockerHub
117+
uses: docker/login-action@v3
118+
with:
119+
120+
password: ${{ secrets.botDockerHubPassword }}
121+
122+
- name: Set short commit SHA
123+
if: github.ref == 'refs/heads/main'
124+
run: |
125+
echo "COMMIT_SHORT_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV
126+
127+
- name: Build and push arm64 (latest)
128+
if: github.ref == 'refs/heads/main'
129+
uses: docker/build-push-action@v6
130+
with:
131+
platforms: linux/arm64
67132
context: .
68133
push: true
69134
build-args: |
70135
SERVICE_NAME=${{ env.SERVICE_NAME }}
71-
SERVICE_VERSION=${{steps.set_version.outputs.no_v_tag}}
72-
tags: instill/artifact-backend:${{steps.set_version.outputs.no_v_tag}}
73-
cache-from: type=registry,ref=instill/artifact-backend:buildcache
74-
cache-to: type=registry,ref=instill/artifact-backend:buildcache,mode=max
136+
SERVICE_VERSION=${{ env.COMMIT_SHORT_SHA }}
137+
tags: instill/${{ env.SERVICE_NAME }}:latest-arm64
138+
cache-from: type=registry,ref=instill/${{ env.SERVICE_NAME }}:buildcache
139+
cache-to: type=registry,ref=instill/${{ env.SERVICE_NAME }}:buildcache,mode=max
140+
141+
- name: Set Versions
142+
if: github.event_name == 'release' || startsWith(github.ref, 'refs/tags/')
143+
uses: actions/github-script@v6
144+
id: set_version
145+
with:
146+
script: |
147+
const tag = '${{ github.ref_name }}'
148+
const no_v_tag = tag.replace('v', '')
149+
core.setOutput('tag', tag)
150+
core.setOutput('no_v_tag', no_v_tag)
151+
152+
- name: Build and push arm64 (rc/release)
153+
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'release'
154+
uses: docker/build-push-action@v6
155+
with:
156+
platforms: linux/arm64
157+
context: .
158+
push: true
159+
build-args: |
160+
SERVICE_NAME=${{ env.SERVICE_NAME }}
161+
SERVICE_VERSION=${{ steps.set_version.outputs.no_v_tag }}
162+
tags: instill/${{ env.SERVICE_NAME }}:${{ steps.set_version.outputs.no_v_tag }}-arm64
163+
cache-from: type=registry,ref=instill/${{ env.SERVICE_NAME }}:buildcache
164+
cache-to: type=registry,ref=instill/${{ env.SERVICE_NAME }}:buildcache,mode=max
165+
166+
combine-and-push:
167+
needs: [build-amd64, build-arm64]
168+
runs-on: ubuntu-24.04
169+
steps:
170+
- uses: actions/checkout@v4
171+
with:
172+
token: ${{ secrets.botGitHubToken }}
173+
174+
- name: Load .env file
175+
uses: cardinalby/export-env-action@v2
176+
with:
177+
envFile: .env
178+
179+
- name: Login to DockerHub
180+
uses: docker/login-action@v3
181+
with:
182+
183+
password: ${{ secrets.botDockerHubPassword }}
184+
185+
- name: Create and push multi-arch manifest (latest)
186+
if: github.ref == 'refs/heads/main'
187+
run: |
188+
docker buildx imagetools create -t instill/${{ env.SERVICE_NAME }}:latest \
189+
instill/${{ env.SERVICE_NAME }}:latest-amd64 \
190+
instill/${{ env.SERVICE_NAME }}:latest-arm64
191+
192+
- name: Set Versions
193+
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'release'
194+
uses: actions/github-script@v6
195+
id: set_version
196+
with:
197+
script: |
198+
const tag = '${{ github.ref_name }}'
199+
const no_v_tag = tag.replace('v', '')
200+
core.setOutput('tag', tag)
201+
core.setOutput('no_v_tag', no_v_tag)
202+
203+
- name: Create and push multi-arch manifest (rc/release)
204+
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'release'
205+
run: |
206+
docker buildx imagetools create -t instill/${{ env.SERVICE_NAME }}:${{ steps.set_version.outputs.no_v_tag }} \
207+
instill/${{ env.SERVICE_NAME }}:${{ steps.set_version.outputs.no_v_tag }}-amd64 \
208+
instill/${{ env.SERVICE_NAME }}:${{ steps.set_version.outputs.no_v_tag }}-arm64

.github/workflows/integration-test.yml

Lines changed: 95 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,98 @@ on:
99
- main
1010

1111
jobs:
12-
build-push-image:
13-
if: github.ref == 'refs/heads/main'
14-
name: Build and push image
15-
uses: instill-ai/artifact-backend/.github/workflows/images.yml@main
16-
secrets: inherit
12+
integration-test:
13+
name: Integration test
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Maximize build space
17+
uses: easimon/maximize-build-space@master
18+
with:
19+
root-reserve-mb: 5120
20+
remove-dotnet: "true"
21+
remove-android: "true"
22+
remove-haskell: "true"
23+
remove-codeql: "true"
24+
remove-docker-images: "true"
25+
build-mount-path: "/var/lib/docker"
26+
27+
- name: Restart docker
28+
run: sudo service docker restart
29+
30+
- name: Checkout (artifact-backend)
31+
uses: actions/checkout@v4
32+
with:
33+
repository: instill-ai/artifact-backend
34+
ref: ${{ github.event.pull_request.head.sha }}
35+
path: artifact-backend
36+
37+
- name: Load .env file (artifact-backend)
38+
uses: cardinalby/export-env-action@v2
39+
with:
40+
envFile: ./artifact-backend/.env
41+
42+
- name: Checkout (instill-core)
43+
uses: actions/checkout@v4
44+
with:
45+
repository: instill-ai/instill-core
46+
ref: main
47+
path: instill-core
48+
49+
- name: Load .env file (instill-core)
50+
uses: cardinalby/export-env-action@v2
51+
with:
52+
envFile: ./instill-core/.env
53+
54+
- uses: actions/setup-go@v5
55+
with:
56+
go-version: ${{ env.GOLANG_VERSION }}
57+
58+
- name: Install k6
59+
run: |
60+
go install go.k6.io/xk6/cmd/xk6@v${{ env.XK6_VERSION }}
61+
xk6 build v${{ env.K6_VERSION }} \
62+
--with github.com/grafana/xk6-sql@v${{ env.XK6_SQL_VERSION }} \
63+
--with github.com/grafana/xk6-sql-driver-postgres@v${{ env.XK6_SQL_POSTGRES_VERSION }} && sudo cp k6 /usr/bin
64+
65+
- name: Login to Docker Hub
66+
uses: docker/login-action@v3
67+
with:
68+
69+
password: ${{ secrets.BOTDOCKERHUBPASSWORD }}
70+
71+
- name: Set up Docker Buildx
72+
uses: docker/setup-buildx-action@v3
73+
74+
- name: Set short commit SHA
75+
run: |
76+
echo "COMMIT_SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
77+
78+
- name: Build image
79+
uses: docker/build-push-action@v6
80+
with:
81+
context: artifact-backend
82+
load: true
83+
build-args: |
84+
SERVICE_NAME=artifact-backend
85+
SERVICE_VERSION=${{ env.COMMIT_SHORT_SHA }}
86+
tags: instill/artifact-backend:latest
87+
cache-from: |
88+
type=registry,ref=instill/artifact-backend:buildcache
89+
cache-to: |
90+
type=registry,ref=instill/artifact-backend:buildcache,mode=max
91+
92+
- name: Launch Instill Core CE (latest)
93+
working-directory: instill-core
94+
run: |
95+
make latest EDITION=docker-ce:test ENV_SECRETS_COMPONENT=.env.secrets.component.test
96+
97+
- name: Run integration-test
98+
working-directory: artifact-backend
99+
run: |
100+
# make integration-test API_GATEWAY_URL=localhost:8080
101+
102+
- name: Tear down Instill Core CE
103+
if: always()
104+
working-directory: instill-core
105+
run: |
106+
make down

Dockerfile

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,45 @@
11
ARG GOLANG_VERSION=1.24.2
2-
FROM golang:${GOLANG_VERSION}-bullseye AS build
2+
FROM golang:${GOLANG_VERSION} AS build
33

4-
WORKDIR /src
5-
6-
COPY go.mod go.sum ./
7-
8-
RUN --mount=type=cache,target=/go/pkg/mod \
9-
go mod download
10-
COPY . .
4+
WORKDIR /build
115

126
ARG SERVICE_NAME SERVICE_VERSION TARGETOS TARGETARCH
137

14-
RUN --mount=type=cache,target=/go/pkg/mod \
8+
RUN --mount=type=bind,target=. \
9+
--mount=type=cache,target=/go/pkg/mod \
1510
--mount=type=cache,target=/root/.cache/go-build \
1611
GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 \
17-
go build -ldflags "-X main.version=${SERVICE_VERSION} -X main.serviceName=${SERVICE_NAME}" \
12+
go build -ldflags "-X main.serviceVersion=${SERVICE_VERSION} -X main.serviceName=${SERVICE_NAME}" \
1813
-o /${SERVICE_NAME} ./cmd/main
1914

20-
# Build the migration tool
21-
RUN --mount=type=cache,target=/go/pkg/mod \
15+
RUN --mount=type=bind,target=. \
16+
--mount=type=cache,target=/go/pkg/mod \
2217
--mount=type=cache,target=/root/.cache/go-build \
2318
GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 \
24-
go build -ldflags "-X main.version=${SERVICE_VERSION} -X main.serviceName=${SERVICE_NAME}-init" \
19+
go build -ldflags "-X main.serviceVersion=${SERVICE_VERSION} -X main.serviceName=${SERVICE_NAME}-init" \
2520
-o /${SERVICE_NAME}-migrate ./cmd/migration
2621

27-
# Build the init tool
28-
RUN --mount=type=cache,target=/go/pkg/mod \
22+
RUN --mount=type=bind,target=. \
23+
--mount=type=cache,target=/go/pkg/mod \
2924
--mount=type=cache,target=/root/.cache/go-build \
3025
GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 \
31-
go build -ldflags "-X main.version=${SERVICE_VERSION} -X main.serviceName=${SERVICE_NAME}-init" \
26+
go build -ldflags "-X main.serviceVersion=${SERVICE_VERSION} -X main.serviceName=${SERVICE_NAME}-init" \
3227
-o /${SERVICE_NAME}-init ./cmd/init
3328

34-
35-
FROM golang:1.23.4
29+
FROM golang:${GOLANG_VERSION}
3630

3731
USER nobody:nogroup
3832

39-
ARG SERVICE_NAME
33+
ARG SERVICE_NAME SERVICE_VERSION
4034

4135
WORKDIR /${SERVICE_NAME}
4236

43-
COPY --from=docker:dind-rootless --chown=nobody:nogroup /usr/local/bin/docker /usr/local/bin
44-
45-
COPY --from=build --chown=nobody:nogroup /src/config ./config
46-
COPY --from=build --chown=nobody:nogroup /src/release-please ./release-please
47-
COPY --from=build --chown=nobody:nogroup /src/pkg/db/migration ./pkg/db/migration
4837
COPY --from=build --chown=nobody:nogroup /${SERVICE_NAME}-migrate ./
4938
COPY --from=build --chown=nobody:nogroup /${SERVICE_NAME}-init ./
5039
COPY --from=build --chown=nobody:nogroup /${SERVICE_NAME} ./
40+
41+
COPY --chown=nobody:nogroup ./config ./config
42+
COPY --chown=nobody:nogroup ./pkg/db/migration ./pkg/db/migration
43+
44+
ENV SERVICE_NAME=${SERVICE_NAME}
45+
ENV SERVICE_VERSION=${SERVICE_VERSION}

0 commit comments

Comments
 (0)