Skip to content

Commit

Permalink
Adapt to multi-platform image building (#703)
Browse files Browse the repository at this point in the history
Co-authored-by: mason <[email protected]>
  • Loading branch information
MasonXon and mason authored Oct 9, 2024
1 parent e5529cd commit 8d44282
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ on:
jobs:
build:
runs-on: ubuntu-latest
env:
BUILDX_NO_DEFAULT_ATTESTATIONS: 1

steps:
- name: Checkout repository
Expand Down Expand Up @@ -50,3 +52,4 @@ jobs:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64,linux/arm64
11 changes: 8 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ csghub-build:
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
DOCKER_HOST: "tcp://docker:2375"
DOCKER_TLS_CERTDIR: ""
script:
BUILDX_NO_DEFAULT_ATTESTATIONS: 1
before_script:
- apk add --no-cache --virtual .build-deps curl
- mkdir -p ~/.docker/cli-plugins
- curl -SL https://github.com/docker/buildx/releases/download/v0.17.1/buildx-v0.17.1.linux-amd64 -o ~/.docker/cli-plugins/docker-buildx
- chmod +x ~/.docker/cli-plugins/docker-buildx
- docker login $CI_REGISTRY -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN
- docker build -t $IMAGE_TAG .
- docker push $IMAGE_TAG
script:
- docker buildx build --platform linux/amd64,linux/arm64 -t ${IMAGE_TAG} --push .

csghub-deploy:
stage: deploy
Expand Down
12 changes: 9 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
FROM opencsg-registry.cn-beijing.cr.aliyuncs.com/opencsg_public/go-node AS build
FROM --platform=$BUILDPLATFORM opencsg-registry.cn-beijing.cr.aliyuncs.com/opencsg_public/go-node AS builder
ARG TARGETPLATFORM
ARG BUILDPLATFORM

RUN mkdir /myapp
WORKDIR /myapp
ADD . /myapp

ENV CGO_ENABLED=0
RUN go mod tidy
RUN cd frontend && yarn install && yarn build
RUN go build -o csghub-portal ./cmd/csghub-portal
RUN GOOS=$(echo ${TARGETPLATFORM} | cut -f1 -d '/') \
GOARCH=$(echo ${TARGETPLATFORM} | cut -f2 -d '/') \
go build -o csghub-portal ./cmd/csghub-portal

FROM bitnami/minideb:latest
RUN apt update && apt install -y ca-certificates && update-ca-certificates
WORKDIR /myapp
COPY --from=build /myapp/csghub-portal /myapp/csghub-portal
COPY --from=builder /myapp/csghub-portal /myapp/csghub-portal

0 comments on commit 8d44282

Please sign in to comment.