Skip to content

Commit 33bf2b4

Browse files
committed
ci(workflows): adopt short commit hash for service version
1 parent c7684a1 commit 33bf2b4

File tree

9 files changed

+310
-112
lines changed

9 files changed

+310
-112
lines changed

.github/workflows/images.yml

Lines changed: 139 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,94 @@ 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+
29+
- uses: actions/checkout@v4
30+
with:
31+
token: ${{ secrets.botGitHubToken }}
32+
33+
- name: Load .env file
34+
uses: cardinalby/export-env-action@v2
35+
with:
36+
envFile: .env
37+
38+
- name: Set up Docker Buildx
39+
uses: docker/setup-buildx-action@v3
40+
41+
- name: Login to DockerHub
42+
uses: docker/login-action@v3
43+
with:
44+
45+
password: ${{ secrets.botDockerHubPassword }}
46+
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)
53+
if: github.ref == 'refs/heads/main'
54+
uses: docker/build-push-action@v6
55+
with:
56+
platforms: linux/amd64
57+
context: .
58+
push: true
59+
build-args: |
60+
SERVICE_NAME=${{ env.SERVICE_NAME }}
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
65+
66+
- name: Set Versions
67+
if: github.event_name == 'release' || startsWith(github.ref, 'refs/tags/')
68+
uses: actions/github-script@v6
69+
id: set_version
70+
with:
71+
script: |
72+
const tag = '${{ github.ref_name }}'
73+
const no_v_tag = tag.replace('v', '')
74+
core.setOutput('tag', tag)
75+
core.setOutput('no_v_tag', no_v_tag)
76+
77+
- name: Build and push amd64 (rc/release)
78+
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'release'
79+
uses: docker/build-push-action@v6
80+
with:
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+
19104
- uses: actions/checkout@v4
20105
with:
21106
token: ${{ secrets.botGitHubToken }}
@@ -34,19 +119,24 @@ jobs:
34119
35120
password: ${{ secrets.botDockerHubPassword }}
36121

37-
- name: Build and push (latest)
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)
38128
if: github.ref == 'refs/heads/main'
39129
uses: docker/build-push-action@v6
40130
with:
41-
platforms: linux/amd64,linux/arm64
131+
platforms: linux/arm64
42132
context: .
43133
push: true
44134
build-args: |
45135
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
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
50140

51141
- name: Set Versions
52142
if: github.event_name == 'release' || startsWith(github.ref, 'refs/tags/')
@@ -59,16 +149,51 @@ jobs:
59149
core.setOutput('tag', tag)
60150
core.setOutput('no_v_tag', no_v_tag)
61151
62-
- name: Build and push (rc/release)
152+
- name: Build and push arm64 (rc/release)
63153
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'release'
64154
uses: docker/build-push-action@v6
65155
with:
66-
platforms: linux/amd64,linux/arm64
156+
platforms: linux/arm64
67157
context: .
68158
push: true
69159
build-args: |
70160
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
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+
- name: Login to DockerHub
171+
uses: docker/login-action@v3
172+
with:
173+
174+
password: ${{ secrets.botDockerHubPassword }}
175+
176+
- name: Create and push multi-arch manifest (latest)
177+
if: github.ref == 'refs/heads/main'
178+
run: |
179+
docker buildx imagetools create -t instill/${{ env.SERVICE_NAME }}:latest \
180+
instill/${{ env.SERVICE_NAME }}:latest-amd64 \
181+
instill/${{ env.SERVICE_NAME }}:latest-arm64
182+
183+
- name: Set Versions
184+
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'release'
185+
uses: actions/github-script@v6
186+
id: set_version
187+
with:
188+
script: |
189+
const tag = '${{ github.ref_name }}'
190+
const no_v_tag = tag.replace('v', '')
191+
core.setOutput('tag', tag)
192+
core.setOutput('no_v_tag', no_v_tag)
193+
194+
- name: Create and push multi-arch manifest (rc/release)
195+
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'release'
196+
run: |
197+
docker buildx imagetools create -t instill/${{ env.SERVICE_NAME }}:${{ steps.set_version.outputs.no_v_tag }} \
198+
instill/${{ env.SERVICE_NAME }}:${{ steps.set_version.outputs.no_v_tag }}-amd64 \
199+
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: 16 additions & 21 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 \
1712
go build -ldflags "-X main.version=${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 \
2419
go build -ldflags "-X main.version=${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 \
3126
go build -ldflags "-X main.version=${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)