mirror of
https://github.com/woodchen-ink/Oapi-Feishu.git
synced 2025-07-18 05:42:08 +08:00
优化 Docker 工作流以支持多平台构建与推送,更新 Go 版本至 1.23
This commit is contained in:
parent
93e960ccd9
commit
8e7b885957
90
.github/workflows/docker.yml
vendored
90
.github/workflows/docker.yml
vendored
@ -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 }}
|
||||
|
18
Dockerfile.multi
Normal file
18
Dockerfile.multi
Normal file
@ -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"]
|
Loading…
x
Reference in New Issue
Block a user