优化 Docker 工作流,添加 Go 模块初始化及二进制构建步骤,调整 Dockerfile 中的文件路径

This commit is contained in:
wood chen 2024-10-09 13:08:32 +08:00
parent 77f30efde8
commit 93e960ccd9
2 changed files with 14 additions and 6 deletions

View File

@ -27,6 +27,19 @@ jobs:
with: with:
go-version: ${{ matrix.go-version }} go-version: ${{ matrix.go-version }}
- 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 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 - name: Set up QEMU
uses: docker/setup-qemu-action@v2 uses: docker/setup-qemu-action@v2
@ -39,10 +52,6 @@ jobs:
username: woodchen username: woodchen
password: ${{ secrets.ACCESS_TOKEN }} password: ${{ secrets.ACCESS_TOKEN }}
- name: Build Go binary
run: |
CGO_ENABLED=0 GOOS=linux GOARCH=${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} go build -ldflags '-w -s' -o feishu_chatgpt
- name: Prepare Docker metadata - name: Prepare Docker metadata
id: meta id: meta
uses: docker/metadata-action@v4 uses: docker/metadata-action@v4
@ -62,4 +71,3 @@ jobs:
push: true push: true
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}

View File

@ -4,6 +4,6 @@ WORKDIR /app
RUN apk add --no-cache bash RUN apk add --no-cache bash
COPY feishu_chatgpt /app COPY feishu_chatgpt /app
COPY role_list.yaml /app COPY code/role_list.yaml /app
EXPOSE 9000 EXPOSE 9000
ENTRYPOINT ["/app/feishu_chatgpt"] ENTRYPOINT ["/app/feishu_chatgpt"]