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"]