From 8e7b885957baaf33c66ae6543f9607721d295f83 Mon Sep 17 00:00:00 2001 From: wood chen Date: Wed, 9 Oct 2024 13:11:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20Docker=20=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E6=B5=81=E4=BB=A5=E6=94=AF=E6=8C=81=E5=A4=9A=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E6=9E=84=E5=BB=BA=E4=B8=8E=E6=8E=A8=E9=80=81=EF=BC=8C?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Go=20=E7=89=88=E6=9C=AC=E8=87=B3=201.23?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker.yml | 90 ++++++++++++++++-------------------- Dockerfile.multi | 18 ++++++++ 2 files changed, 59 insertions(+), 49 deletions(-) create mode 100644 Dockerfile.multi diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index b7c3a0d..f36160c 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -13,61 +13,53 @@ env: jobs: build: runs-on: ubuntu-latest - strategy: - matrix: - go-version: [1.23.x] - platform: [linux/amd64, linux/arm64] steps: - - name: Checkout code - uses: actions/checkout@v3 + - name: Checkout code + uses: actions/checkout@v4 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: ${{ matrix.go-version }} + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.23' # 使用你项目需要的 Go 版本 - - name: Initialize Go module if needed - working-directory: ./code - run: | - if [ ! -f go.mod ]; then - go mod init github.com/${{ github.repository }} - go mod tidy - fi + - name: Build for amd64 + run: | + cd code + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '-w -s' -o ../feishu_chatgpt-amd64 + + - name: Build for arm64 + run: | + cd code + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags '-w -s' -o ../feishu_chatgpt-arm64 - - name: Build Go binary - working-directory: ./code - run: | - CGO_ENABLED=0 GOOS=linux GOARCH=${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} go build -ldflags '-w -s' -o ../feishu_chatgpt + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: woodchen + password: ${{ secrets.ACCESS_TOKEN }} - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: woodchen - password: ${{ secrets.ACCESS_TOKEN }} + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: Dockerfile.multi + platforms: linux/amd64,linux/arm64 + push: true + tags: | + woodchen/${{ env.IMAGE_NAME }}:latest + woodchen/${{ env.IMAGE_NAME }}:${{ github.sha }} - - name: Prepare Docker metadata - id: meta - uses: docker/metadata-action@v4 - with: - images: woodchen/${{ env.IMAGE_NAME }} - tags: | - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - - - name: Build and push Docker image - uses: docker/build-push-action@v4 - with: - context: . - platforms: ${{ matrix.platform }} - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + - name: Update Docker Hub description + uses: peter-evans/dockerhub-description@v4 + with: + username: woodchen + password: ${{ secrets.ACCESS_TOKEN }} + repository: woodchen/${{ env.IMAGE_NAME }} + short-description: ${{ github.event.repository.description }} diff --git a/Dockerfile.multi b/Dockerfile.multi new file mode 100644 index 0000000..1198f10 --- /dev/null +++ b/Dockerfile.multi @@ -0,0 +1,18 @@ +FROM --platform=$TARGETPLATFORM alpine:latest + +WORKDIR /app + +RUN apk add --no-cache bash + +COPY feishu_chatgpt-* /app/ +COPY code/role_list.yaml /app/ + +RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ + mv /app/feishu_chatgpt-amd64 /app/feishu_chatgpt; \ + elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + mv /app/feishu_chatgpt-arm64 /app/feishu_chatgpt; \ + fi && \ + chmod +x /app/feishu_chatgpt + +EXPOSE 9000 +ENTRYPOINT ["/app/feishu_chatgpt"]