Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
e2107ce4
Commit
e2107ce4
authored
Feb 14, 2026
by
yangjianbo
Browse files
fix(build): Docker 构建注入版本号并同步 aicodex 镜像脚本
parent
5feff6b1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Dockerfile
View file @
e2107ce4
...
...
@@ -36,7 +36,7 @@ RUN pnpm run build
FROM
${GOLANG_IMAGE} AS backend-builder
# Build arguments for version info (set by CI)
ARG
VERSION=
docker
ARG
VERSION=
ARG
COMMIT=docker
ARG
DATE
ARG
GOPROXY
...
...
@@ -63,7 +63,7 @@ COPY --from=frontend-builder /app/backend/internal/web/dist ./internal/web/dist
# Build the binary (BuildType=release for CI builds, embed frontend)
RUN
CGO_ENABLED
=
0
GOOS
=
linux go build
\
-tags
embed
\
-ldflags
=
"-s -w -X main.Commit=
${
COMMIT
}
-X main.Date=
${
DATE
:-
$(
date
-u
+%Y-%m-%dT%H:%M:%SZ
)
}
-X main.BuildType=release"
\
-ldflags
=
"-s -w -X
main.Version=
${
VERSION
}
-X
main.Commit=
${
COMMIT
}
-X main.Date=
${
DATE
:-
$(
date
-u
+%Y-%m-%dT%H:%M:%SZ
)
}
-X main.BuildType=release"
\
-o
/app/sub2api
\
./cmd/server
...
...
backend/cmd/server/main.go
View file @
e2107ce4
...
...
@@ -40,7 +40,12 @@ var (
)
func
init
()
{
// Read version from embedded VERSION file
// 如果 Version 已通过 ldflags 注入(例如 -X main.Version=...),则不要覆盖。
if
strings
.
TrimSpace
(
Version
)
!=
""
{
return
}
// 默认从 embedded VERSION 文件读取版本号(编译期打包进二进制)。
Version
=
strings
.
TrimSpace
(
embeddedVersion
)
if
Version
==
""
{
Version
=
"0.0.0-dev"
...
...
build_image_aicodex.sh
View file @
e2107ce4
#!/bin/bash
# 本地构建镜像的快速脚本,避免在命令行反复输入构建参数。
docker build
-t
yangjianbo/aicodex2api:latest
\
--build-arg
GOPROXY
=
https://goproxy.cn,direct
\
--build-arg
GOSUMDB
=
sum.golang.google.cn
\
-f
Dockerfile
\
.
set
-euo
pipefail
SCRIPT_DIR
=
"
$(
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
&&
pwd
)
"
REPO_ROOT
=
"
${
SCRIPT_DIR
}
"
VERSION_FILE
=
"
${
REPO_ROOT
}
/backend/cmd/server/VERSION"
VERSION
=
""
if
[
-f
"
${
VERSION_FILE
}
"
]
;
then
VERSION
=
"
$(
tr
-d
'\r\n'
<
"
${
VERSION_FILE
}
"
)
"
fi
if
[
-z
"
${
VERSION
}
"
]
;
then
echo
"未找到版本号(
${
VERSION_FILE
}
为空或不存在),将仅构建 latest 镜像"
>
&2
VERSION
=
"docker"
fi
COMMIT
=
"
$(
git
-C
"
${
REPO_ROOT
}
"
rev-parse
--short
HEAD 2>/dev/null
||
echo
docker
)
"
DATE
=
"
$(
date
-u
+%Y-%m-%dT%H:%M:%SZ
)
"
docker build
\
-t
"yangjianbo/aicodex2api:latest"
\
-t
"yangjianbo/aicodex2api:
${
VERSION
}
"
\
--build-arg
VERSION
=
"
${
VERSION
}
"
\
--build-arg
COMMIT
=
"
${
COMMIT
}
"
\
--build-arg
DATE
=
"
${
DATE
}
"
\
--build-arg
GOPROXY
=
https://goproxy.cn,direct
\
--build-arg
GOSUMDB
=
sum.golang.google.cn
\
-f
"
${
REPO_ROOT
}
/Dockerfile"
\
"
${
REPO_ROOT
}
"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment