Skip to content

ci(workflows): adopt short commit hash for service version #210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 148 additions & 14 deletions .github/workflows/images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@ on:
types: [published]

jobs:
docker-hub:
runs-on: ubuntu-latest
build-amd64:
runs-on: ubuntu-24.04
steps:
- name: Maximize build space
uses: easimon/maximize-build-space@master
with:
overprovision-lvm: "true"
remove-dotnet: "true"
build-mount-path: "/var/lib/docker/"

- name: Restart docker
run: sudo service docker restart

- uses: actions/checkout@v4
with:
token: ${{ secrets.botGitHubToken }}
Expand All @@ -34,19 +44,24 @@ jobs:
username: [email protected]
password: ${{ secrets.botDockerHubPassword }}

- name: Build and push (latest)
- name: Set short commit SHA
if: github.ref == 'refs/heads/main'
run: |
echo "COMMIT_SHORT_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV

- name: Build and push amd64 (latest)
if: github.ref == 'refs/heads/main'
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
platforms: linux/amd64
context: .
push: true
build-args: |
SERVICE_NAME=${{ env.SERVICE_NAME }}
SERVICE_VERSION=${{ github.sha }}
tags: instill/artifact-backend:latest
cache-from: type=registry,ref=instill/artifact-backend:buildcache
cache-to: type=registry,ref=instill/artifact-backend:buildcache,mode=max
SERVICE_VERSION=${{ env.COMMIT_SHORT_SHA }}
tags: instill/${{ env.SERVICE_NAME }}:latest-amd64
cache-from: type=registry,ref=instill/${{ env.SERVICE_NAME }}:buildcache
cache-to: type=registry,ref=instill/${{ env.SERVICE_NAME }}:buildcache,mode=max

- name: Set Versions
if: github.event_name == 'release' || startsWith(github.ref, 'refs/tags/')
Expand All @@ -59,16 +74,135 @@ jobs:
core.setOutput('tag', tag)
core.setOutput('no_v_tag', no_v_tag)

- name: Build and push (rc/release)
- name: Build and push amd64 (rc/release)
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'release'
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
platforms: linux/amd64
context: .
push: true
build-args: |
SERVICE_NAME=${{ env.SERVICE_NAME }}
SERVICE_VERSION=${{ steps.set_version.outputs.no_v_tag }}
tags: instill/${{ env.SERVICE_NAME }}:${{ steps.set_version.outputs.no_v_tag }}-amd64
cache-from: type=registry,ref=instill/${{ env.SERVICE_NAME }}:buildcache
cache-to: type=registry,ref=instill/${{ env.SERVICE_NAME }}:buildcache,mode=max

build-arm64:
runs-on: ubuntu-24.04-arm
steps:
- name: Maximize build space
uses: easimon/maximize-build-space@master
with:
overprovision-lvm: "true"
remove-dotnet: "true"
build-mount-path: "/var/lib/docker/"

- name: Restart docker
run: sudo service docker restart

- uses: actions/checkout@v4
with:
token: ${{ secrets.botGitHubToken }}

- name: Load .env file
uses: cardinalby/export-env-action@v2
with:
envFile: .env

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: [email protected]
password: ${{ secrets.botDockerHubPassword }}

- name: Set short commit SHA
if: github.ref == 'refs/heads/main'
run: |
echo "COMMIT_SHORT_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV

- name: Build and push arm64 (latest)
if: github.ref == 'refs/heads/main'
uses: docker/build-push-action@v6
with:
platforms: linux/arm64
context: .
push: true
build-args: |
SERVICE_NAME=${{ env.SERVICE_NAME }}
SERVICE_VERSION=${{steps.set_version.outputs.no_v_tag}}
tags: instill/artifact-backend:${{steps.set_version.outputs.no_v_tag}}
cache-from: type=registry,ref=instill/artifact-backend:buildcache
cache-to: type=registry,ref=instill/artifact-backend:buildcache,mode=max
SERVICE_VERSION=${{ env.COMMIT_SHORT_SHA }}
tags: instill/${{ env.SERVICE_NAME }}:latest-arm64
cache-from: type=registry,ref=instill/${{ env.SERVICE_NAME }}:buildcache
cache-to: type=registry,ref=instill/${{ env.SERVICE_NAME }}:buildcache,mode=max

- name: Set Versions
if: github.event_name == 'release' || startsWith(github.ref, 'refs/tags/')
uses: actions/github-script@v6
id: set_version
with:
script: |
const tag = '${{ github.ref_name }}'
const no_v_tag = tag.replace('v', '')
core.setOutput('tag', tag)
core.setOutput('no_v_tag', no_v_tag)

- name: Build and push arm64 (rc/release)
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'release'
uses: docker/build-push-action@v6
with:
platforms: linux/arm64
context: .
push: true
build-args: |
SERVICE_NAME=${{ env.SERVICE_NAME }}
SERVICE_VERSION=${{ steps.set_version.outputs.no_v_tag }}
tags: instill/${{ env.SERVICE_NAME }}:${{ steps.set_version.outputs.no_v_tag }}-arm64
cache-from: type=registry,ref=instill/${{ env.SERVICE_NAME }}:buildcache
cache-to: type=registry,ref=instill/${{ env.SERVICE_NAME }}:buildcache,mode=max

combine-and-push:
needs: [build-amd64, build-arm64]
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.botGitHubToken }}

- name: Load .env file
uses: cardinalby/export-env-action@v2
with:
envFile: .env

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: [email protected]
password: ${{ secrets.botDockerHubPassword }}

- name: Create and push multi-arch manifest (latest)
if: github.ref == 'refs/heads/main'
run: |
docker buildx imagetools create -t instill/${{ env.SERVICE_NAME }}:latest \
instill/${{ env.SERVICE_NAME }}:latest-amd64 \
instill/${{ env.SERVICE_NAME }}:latest-arm64

- name: Set Versions
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'release'
uses: actions/github-script@v6
id: set_version
with:
script: |
const tag = '${{ github.ref_name }}'
const no_v_tag = tag.replace('v', '')
core.setOutput('tag', tag)
core.setOutput('no_v_tag', no_v_tag)

- name: Create and push multi-arch manifest (rc/release)
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'release'
run: |
docker buildx imagetools create -t instill/${{ env.SERVICE_NAME }}:${{ steps.set_version.outputs.no_v_tag }} \
instill/${{ env.SERVICE_NAME }}:${{ steps.set_version.outputs.no_v_tag }}-amd64 \
instill/${{ env.SERVICE_NAME }}:${{ steps.set_version.outputs.no_v_tag }}-arm64
100 changes: 95 additions & 5 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,98 @@ on:
- main

jobs:
build-push-image:
if: github.ref == 'refs/heads/main'
name: Build and push image
uses: instill-ai/artifact-backend/.github/workflows/images.yml@main
secrets: inherit
integration-test:
name: Integration test
runs-on: ubuntu-latest
steps:
- name: Maximize build space
uses: easimon/maximize-build-space@master
with:
root-reserve-mb: 5120
remove-dotnet: "true"
remove-android: "true"
remove-haskell: "true"
remove-codeql: "true"
remove-docker-images: "true"
build-mount-path: "/var/lib/docker"

- name: Restart docker
run: sudo service docker restart

- name: Checkout (artifact-backend)
uses: actions/checkout@v4
with:
repository: instill-ai/artifact-backend
ref: ${{ github.event.pull_request.head.sha }}
path: artifact-backend

- name: Load .env file (artifact-backend)
uses: cardinalby/export-env-action@v2
with:
envFile: ./artifact-backend/.env

- name: Checkout (instill-core)
uses: actions/checkout@v4
with:
repository: instill-ai/instill-core
ref: main
path: instill-core

- name: Load .env file (instill-core)
uses: cardinalby/export-env-action@v2
with:
envFile: ./instill-core/.env

- uses: actions/setup-go@v5
with:
go-version: ${{ env.GOLANG_VERSION }}

- name: Install k6
run: |
go install go.k6.io/xk6/cmd/xk6@v${{ env.XK6_VERSION }}
xk6 build v${{ env.K6_VERSION }} \
--with github.com/grafana/xk6-sql@v${{ env.XK6_SQL_VERSION }} \
--with github.com/grafana/xk6-sql-driver-postgres@v${{ env.XK6_SQL_POSTGRES_VERSION }} && sudo cp k6 /usr/bin

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: [email protected]
password: ${{ secrets.BOTDOCKERHUBPASSWORD }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set short commit SHA
run: |
echo "COMMIT_SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV

- name: Build image
uses: docker/build-push-action@v6
with:
context: artifact-backend
load: true
build-args: |
SERVICE_NAME=artifact-backend
SERVICE_VERSION=${{ env.COMMIT_SHORT_SHA }}
tags: instill/artifact-backend:latest
cache-from: |
type=registry,ref=instill/artifact-backend:buildcache
cache-to: |
type=registry,ref=instill/artifact-backend:buildcache,mode=max

- name: Launch Instill Core CE (latest)
working-directory: instill-core
run: |
make latest EDITION=docker-ce:test ENV_SECRETS_COMPONENT=.env.secrets.component.test

- name: Run integration-test
working-directory: artifact-backend
run: |
# make integration-test API_GATEWAY_URL=localhost:8080

- name: Tear down Instill Core CE
if: always()
working-directory: instill-core
run: |
make down
37 changes: 16 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,50 +1,45 @@
ARG GOLANG_VERSION=1.24.2
FROM golang:${GOLANG_VERSION}-bullseye AS build
FROM golang:${GOLANG_VERSION} AS build

WORKDIR /src

COPY go.mod go.sum ./

RUN --mount=type=cache,target=/go/pkg/mod \
go mod download
COPY . .
WORKDIR /build

ARG SERVICE_NAME SERVICE_VERSION TARGETOS TARGETARCH

RUN --mount=type=cache,target=/go/pkg/mod \
RUN --mount=type=bind,target=. \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 \
go build -ldflags "-X main.version=${SERVICE_VERSION} -X main.serviceName=${SERVICE_NAME}" \
-o /${SERVICE_NAME} ./cmd/main

# Build the migration tool
RUN --mount=type=cache,target=/go/pkg/mod \
RUN --mount=type=bind,target=. \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 \
go build -ldflags "-X main.version=${SERVICE_VERSION} -X main.serviceName=${SERVICE_NAME}-init" \
-o /${SERVICE_NAME}-migrate ./cmd/migration

# Build the init tool
RUN --mount=type=cache,target=/go/pkg/mod \
RUN --mount=type=bind,target=. \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 \
go build -ldflags "-X main.version=${SERVICE_VERSION} -X main.serviceName=${SERVICE_NAME}-init" \
-o /${SERVICE_NAME}-init ./cmd/init


FROM golang:1.23.4
FROM golang:${GOLANG_VERSION}

USER nobody:nogroup

ARG SERVICE_NAME
ARG SERVICE_NAME SERVICE_VERSION

WORKDIR /${SERVICE_NAME}

COPY --from=docker:dind-rootless --chown=nobody:nogroup /usr/local/bin/docker /usr/local/bin

COPY --from=build --chown=nobody:nogroup /src/config ./config
COPY --from=build --chown=nobody:nogroup /src/release-please ./release-please
COPY --from=build --chown=nobody:nogroup /src/pkg/db/migration ./pkg/db/migration
COPY --from=build --chown=nobody:nogroup /${SERVICE_NAME}-migrate ./
COPY --from=build --chown=nobody:nogroup /${SERVICE_NAME}-init ./
COPY --from=build --chown=nobody:nogroup /${SERVICE_NAME} ./

COPY --chown=nobody:nogroup ./config ./config
COPY --chown=nobody:nogroup ./pkg/db/migration ./pkg/db/migration

ENV SERVICE_NAME=${SERVICE_NAME}
ENV SERVICE_VERSION=${SERVICE_VERSION}
Loading
Loading