60 lines
1.8 KiB
YAML
60 lines
1.8 KiB
YAML
name: Pure Run Build
|
|
on: [push]
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: git.vipjhzf.cn/github/ci-base:latest
|
|
steps:
|
|
- name: 克隆当前仓库
|
|
run: |
|
|
git clone ${{ gitea.server_url }}/${{ gitea.repository }}.git .
|
|
git checkout ${{ gitea.sha }}
|
|
|
|
- name: 编译 Go 项目
|
|
run: |
|
|
go mod tidy
|
|
CGO_ENABLED=0 go build -o myapp .
|
|
|
|
- name: 运行测试
|
|
run: |
|
|
go test ./...
|
|
|
|
- name: 打印完成
|
|
run: echo "构建完成 ✅"
|
|
|
|
- name: 编译docker镜像
|
|
run: |
|
|
cat > Dockerfile <<EOF
|
|
# 多阶段构建:首先定义builder阶段
|
|
FROM git.vipjhzf.cn/github/alpine:3.16.2 AS builder
|
|
|
|
# 在builder阶段配置APK清华源并安装所需工具
|
|
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories \
|
|
&& apk update \
|
|
&& apk add --no-cache ca-certificates tzdata
|
|
|
|
FROM git.vipjhzf.cn/github/alpine:3.16.2
|
|
LABEL use=hzz_app
|
|
# LABEL use=hzz_$build_service
|
|
|
|
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
|
COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai
|
|
ENV TZ=Asia/Shanghai
|
|
|
|
WORKDIR /app
|
|
|
|
COPY ./myapp /app/server
|
|
#COPY ./${build_service} /app/server
|
|
#COPY ./etc /app/etc
|
|
#COPY ./etc/${conf_name} /app/etc/config.yaml
|
|
|
|
# api暴露端口 80-
|
|
EXPOSE 8080 8888 8889 8688 10000
|
|
|
|
# CMD ["/app/server", "-f", "/app/etc/config.yaml"]
|
|
CMD ["/app/server"]
|
|
EOF
|
|
docker build -t myapp:v${{ gitea.run_id }} .
|