优化 Docker 工作流以支持多平台构建与推送,并改进 Dockerfile 的跨平台处理

This commit is contained in:
wood chen 2024-10-09 13:14:27 +08:00
parent 8e7b885957
commit a4ba7c3486
2 changed files with 22 additions and 4 deletions

View File

@ -33,6 +33,20 @@ jobs:
cd code cd code
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags '-w -s' -o ../feishu_chatgpt-arm64 CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags '-w -s' -o ../feishu_chatgpt-arm64
- name: List files
run: ls -l
- 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: Set up QEMU - name: Set up QEMU
uses: docker/setup-qemu-action@v3 uses: docker/setup-qemu-action@v3

View File

@ -7,12 +7,16 @@ RUN apk add --no-cache bash
COPY feishu_chatgpt-* /app/ COPY feishu_chatgpt-* /app/
COPY code/role_list.yaml /app/ COPY code/role_list.yaml /app/
RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ RUN ls -l /app && \
mv /app/feishu_chatgpt-amd64 /app/feishu_chatgpt; \ if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
mv /app/feishu_chatgpt-amd64 /app/feishu_chatgpt || echo "amd64 binary not found"; \
elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
mv /app/feishu_chatgpt-arm64 /app/feishu_chatgpt; \ mv /app/feishu_chatgpt-arm64 /app/feishu_chatgpt || echo "arm64 binary not found"; \
else \
echo "Unknown platform: $TARGETPLATFORM"; \
fi && \ fi && \
chmod +x /app/feishu_chatgpt ls -l /app && \
chmod +x /app/feishu_chatgpt || echo "Failed to set executable permission"
EXPOSE 9000 EXPOSE 9000
ENTRYPOINT ["/app/feishu_chatgpt"] ENTRYPOINT ["/app/feishu_chatgpt"]