diff --git a/.github/workflows/docker-ci.yaml b/.github/workflows/docker-ci.yaml index 03d2ec8..d6a54d7 100644 --- a/.github/workflows/docker-ci.yaml +++ b/.github/workflows/docker-ci.yaml @@ -2,31 +2,37 @@ name: Docker Image CI on: push: - branches: [ main ] + branches: [main] jobs: - build: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + with: + platforms: "arm64,amd64" - name: Login to DockerHub - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v2 - name: Build and push Docker images - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v3 with: context: . file: ./Dockerfile platforms: linux/amd64,linux/arm64 push: true tags: programzmh/chatnio:latest + cache-from: type=registry,ref=programzmh/chatnio:buildcache + cache-to: type=registry,ref=programzmh/chatnio:buildcache,mode=max diff --git a/Dockerfile b/Dockerfile index b94ca20..d5441ce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,14 +2,16 @@ # License: Apache-2.0 # Description: Dockerfile for chatnio -FROM golang:1.20-alpine AS backend +FROM --platform=$BUILDPLATFORM golang:1.20-alpine AS backend WORKDIR /backend COPY . . # Set go proxy to https://goproxy.cn (open for vps in China Mainland) # RUN go env -w GOPROXY=https://goproxy.cn,direct -ENV GOOS=linux GO111MODULE=on CGO_ENABLED=1 +ARG TARGETARCH +ARG TARGETOS +ENV GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on CGO_ENABLED=1 # Install dependencies for cgo RUN apk add --no-cache gcc musl-dev