Skip to content

Commit 21e8ab7

Browse files
eryajferyajf
authored andcommitted
build: 重构构建流程,统一使用docker获取前端资源并优化Dockerfile结构
1 parent 07281cf commit 21e8ab7

File tree

6 files changed

+49
-60
lines changed

6 files changed

+49
-60
lines changed

.cnb/workflows/build-docker-images.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ main:
1414
ALIHUB_USERNAME: eryajf
1515
ALIHUB_IMAGE_REPONAME: eryajf
1616
stages:
17+
- name: 📦 构建制品
18+
image: docker.cnb.cool/znb/images/debian:all
19+
script: |
20+
docker cp $(docker create --rm docker.cnb.cool/opsre/go-ldap-admin-ui):/app/dist public/static/dist
21+
make gox-linux
1722
- name: 🐋 推送镜像
1823
timeout: 3h
1924
script: |

.cnb/workflows/release.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ $:
1212
ALIHUB_USERNAME: eryajf
1313
ALIHUB_IMAGE_REPONAME: eryajf
1414
stages:
15+
- name: 📦 构建制品
16+
timeout: 3h
17+
image: docker.cnb.cool/znb/images/debian:new
18+
script: |
19+
docker cp $(docker create --rm docker.cnb.cool/opsre/go-ldap-admin-ui):/app/dist public/static/dist
20+
make gox-all
21+
- name: release upload attachments
22+
timeout: 3h
23+
image: cnbcool/attachments:latest
24+
settings:
25+
attachments:
26+
- ./bin/*
1527
- name: 🐋 推送镜像
1628
timeout: 3h
1729
script: |
@@ -29,16 +41,4 @@ $:
2941
-t ${ALIHUB_URL}/${ALIHUB_USERNAME}/${IMAGE_NAME}:${CNB_BRANCH}_`date "+%Y%m%d%H%M%S"` \
3042
-t ${CNB_DOCKER_REGISTRY}/${CNB_REPO_SLUG_LOWERCASE} \
3143
-t ${CNB_DOCKER_REGISTRY}/${CNB_REPO_SLUG_LOWERCASE}:${CNB_BRANCH}_`date "+%Y%m%d%H%M%S"` \
32-
--platform=linux/arm64,linux/amd64 . --push
33-
- name: 📦 构建制品
34-
timeout: 3h
35-
image: docker.cnb.cool/znb/images/debian:new
36-
script: |
37-
docker cp $(docker create --rm docker.cnb.cool/opsre/go-ldap-admin-ui):/app/dist public/static/dist
38-
make gox-all
39-
- name: release upload attachments
40-
timeout: 3h
41-
image: cnbcool/attachments:latest
42-
settings:
43-
attachments:
44-
- ./bin/*
44+
--platform=linux/arm64,linux/amd64 . --push

.github/workflows/build-docker-image.yml

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,20 @@ jobs:
5050
registry: ghcr.io
5151
username: ${{ github.actor }}
5252
password: ${{ secrets.GITHUB_TOKEN }}
53-
# - name: Login to the Ali Registry
54-
# uses: docker/login-action@v3
55-
# with:
56-
# registry: ${{ env.ALIHUB_URL }}
57-
# username: ${{ env.ALIHUB_USERNAME }}
58-
# password: ${{ secrets.ALIHUB_TOKEN }}
5953

60-
# - name: 设置go环境
61-
# uses: actions/setup-go@v5
62-
# with:
63-
# go-version-file: "go.mod"
64-
# cache-dependency-path: "go.sum"
65-
# - name: 安装 UPX
66-
# uses: crazy-max/ghaction-upx@v3
67-
# with:
68-
# install-only: true
69-
# - run: go install github.com/authelia/gox@latest # setup gox
70-
# - run: make gox-linux
54+
- name: 设置go环境
55+
uses: actions/setup-go@v5
56+
with:
57+
go-version-file: "go.mod"
58+
cache-dependency-path: "go.sum"
59+
- name: 安装 UPX
60+
uses: crazy-max/ghaction-upx@v3
61+
with:
62+
install-only: true
63+
- run: go install github.com/authelia/gox@latest # setup gox
64+
- run: |
65+
docker cp $(docker create --rm docker.cnb.cool/opsre/go-ldap-admin-ui):/app/dist public/static/dist
66+
make gox-linux
7167
7268
- name: Build and push
7369
uses: docker/build-push-action@v6
@@ -82,6 +78,6 @@ jobs:
8278
${{ env.DOCKERHUB_USERNAME }}/${{ env.IMAGE_REPONAME }}:latest
8379
${{ env.DOCKERHUB_USERNAME }}/${{ env.IMAGE_REPONAME }}:${{ env.GITHUB_REF_NAME }}
8480
${{ env.DOCKERHUB_USERNAME }}/${{ env.IMAGE_REPONAME }}:${{ steps.date.outputs.today }}
85-
ghcr.io/${{ github.actor }}/${{ github.repository }}
86-
ghcr.io/${{ github.actor }}/${{ github.repository }}:${{ env.GITHUB_REF_NAME }}
87-
ghcr.io/${{ github.actor }}/${{ github.repository }}:${{ steps.date.outputs.today }}
81+
ghcr.io/${{ github.repository }}
82+
ghcr.io/${{ github.repository }}:${{ env.GITHUB_REF_NAME }}
83+
ghcr.io/${{ github.repository }}:${{ steps.date.outputs.today }}

.github/workflows/buildAndPush-binary-to-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v4
1919
- run: |
20-
release_url=$(curl -s https://api.github.com/repos/opsre/go-ldap-admin-ui/releases/latest | grep "browser_download_url" | grep -v 'dist.zip.md5' | cut -d '"' -f 4); wget $release_url && unzip dist.zip && rm dist.zip && mv dist public/static
20+
docker cp $(docker create --rm docker.cnb.cool/opsre/go-ldap-admin-ui):/app/dist public/static/dist
2121
- uses: wangyoucao577/go-release-action@v1
2222
with:
2323
github_token: ${{ secrets.GITHUB_TOKEN }} # 一个默认的变量,用来实现往 Release 中添加文件

.github/workflows/go-ci-check.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
go-version-file: "go.mod"
1515
cache-dependency-path: "go.sum"
1616
- run: |
17-
release_url=$(curl -s https://api.github.com/repos/opsre/go-ldap-admin-ui/releases/latest | grep "browser_download_url" | grep -v 'dist.zip.md5' | cut -d '"' -f 4); wget $release_url && unzip dist.zip && rm dist.zip && mv dist public/static
17+
docker cp $(docker create --rm docker.cnb.cool/opsre/go-ldap-admin-ui):/app/dist public/static/dist
1818
- name: golangci-lint
1919
uses: golangci/golangci-lint-action@v8
2020
with:
@@ -26,7 +26,7 @@ jobs:
2626
steps:
2727
- uses: actions/checkout@v4
2828
- run: |
29-
release_url=$(curl -s https://api.github.com/repos/opsre/go-ldap-admin-ui/releases/latest | grep "browser_download_url" | grep -v 'dist.zip.md5' | cut -d '"' -f 4); wget $release_url && unzip dist.zip && rm dist.zip && mv dist public/static
29+
docker cp $(docker create --rm docker.cnb.cool/opsre/go-ldap-admin-ui):/app/dist public/static/dist
3030
- name: 设置go环境
3131
uses: actions/setup-go@v5
3232
with:

Dockerfile

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,22 @@
1-
FROM docker.cnb.cool/znb/images/golang:1.25.0-alpine3.22 AS builder
1+
FROM docker.cnb.cool/znb/images/alpine
22

33
WORKDIR /app
4+
LABEL maintainer=eryajf@163.com
45

5-
ENV GOPROXY=https://goproxy.io
6-
7-
RUN sed -i "s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g" /etc/apk/repositories \
8-
&& apk upgrade && apk add --no-cache --virtual .build-deps \
9-
ca-certificates gcc g++ curl upx
6+
ENV TZ=Asia/Shanghai
7+
ENV BINARY_NAME=go-ldap-admin
108

11-
ADD . .
9+
ARG TARGETOS
10+
ARG TARGETARCH
1211

12+
COPY LICENSE .
13+
COPY config.yml .
14+
COPY bin/${BINARY_NAME}_${TARGETOS}_${TARGETARCH} ${BINARY_NAME}
1315
COPY --from=docker.cnb.cool/znb/images/docker-compose-wait /wait .
14-
COPY --from=docker.cnb.cool/opsre/go-ldap-admin-ui /app/dist public/static/dist
15-
16-
RUN sed -i 's@localhost:389@openldap:389@g' /app/config.yml \
17-
&& sed -i 's@host: localhost@host: mysql@g' /app/config.yml && go build -o go-ldap-admin . && upx -9 go-ldap-admin && upx -9 wait
18-
19-
### build final image
20-
FROM docker.cnb.cool/znb/images/alpine:latest
21-
22-
LABEL maintainer=eryajf@163.com
23-
24-
WORKDIR /app
25-
26-
COPY --from=builder /app/wait .
27-
COPY --from=builder /app/LICENSE .
28-
COPY --from=builder /app/config.yml .
29-
COPY --from=builder /app/go-ldap-admin .
3016

31-
RUN chmod +x wait go-ldap-admin
17+
RUN chmod +x wait go-ldap-admin &&\
18+
sed -i 's@localhost:389@openldap:389@g' /app/config.yml \
19+
&& sed -i 's@host: localhost@host: mysql@g' /app/config.yml
3220

3321
# see wait repo: https://github.com/ufoscout/docker-compose-wait
3422
CMD ./wait && ./go-ldap-admin

0 commit comments

Comments
 (0)