Skip to content

Commit

Permalink
测试修复 Docker 构建的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
xiwangly2 committed Sep 22, 2023
1 parent f75902b commit bfb1097
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_docker_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le,linux/s390x
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
25 changes: 16 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
# 阶段一:构建阶段
FROM golang:1.21 AS builder
FROM golang:1.21.1-alpine3.18 AS builder

# 设置工作目录为 /app
WORKDIR /app
# 安装 UPX 压缩工具
RUN apk --no-cache add curl xz && \
curl -L -o upx.tar.xz https://github.com/upx/upx/releases/latest/download/upx-4.1.0-amd64_linux.tar.xz && \
tar -xJf upx.tar.xz && \
mv upx-*-amd64_linux/upx /usr/local/bin/ && \
rm -rf upx.tar.xz upx-*

# 设置工作目录
WORKDIR /build

# 复制Go程序文件到容器中
COPY . .

# 构建Go程序
RUN go build -o "connect_jxyy_network"
RUN go build -o connect_jxyy_network

# 压缩可执行文件
RUN upx -9 connect_jxyy_network

# 阶段二:运行阶段
FROM alpine:latest

# 设置工作目录为 /app
# 设置工作目录
WORKDIR /app

# 从第一阶段中复制生成的可执行文件到当前容器
COPY --from=builder "/app/connect_jxyy_network" "/app/connect_jxyy_network"

# 暴露容器的端口号
EXPOSE 8080
COPY --from=builder /build/connect_jxyy_network /app/connect_jxyy_network

# 定义启动容器时运行的命令
CMD ["/app/connect_jxyy_network"]

0 comments on commit bfb1097

Please sign in to comment.