Skip to content

Commit 15a059a

Browse files
committed
feat: optimize docker image size
1 parent 5da473e commit 15a059a

File tree

3 files changed

+21
-27
lines changed

3 files changed

+21
-27
lines changed

lib/docker.go

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -120,26 +120,7 @@ func CreateDockerfile(v string) {
120120
makeFile(dockerfilePath)
121121

122122
// 写入 Dockerfile
123-
content := `FROM node:16.18-slim
124-
125-
# 设置工作目录
126-
WORKDIR /app
127-
128-
# 复制 package.json 和 pnpm-lock.yaml 并安装依赖项
129-
COPY package.json pnpm-lock.yaml ./
130-
RUN mkdir config && npm install -g pnpm && pnpm install && npm cache clean --force
131-
132-
# 复制项目文件
133-
COPY . .
134-
135-
# 暴露端口
136-
EXPOSE 3000
137-
138-
# 启动应用
139-
CMD cd config && node ../sub-store.min.js
140-
`
141-
142-
err := os.WriteFile(dockerfilePath, []byte(content), 0666)
123+
err := os.WriteFile(dockerfilePath, []byte(dockerfileStrNode), 0666)
143124
if err != nil {
144125
fmt.Println("Failed to write Dockerfile: ", err)
145126
os.Exit(1)
@@ -148,12 +129,12 @@ CMD cd config && node ../sub-store.min.js
148129
fmt.Println("Dockerfile created successfully.")
149130

150131
// 下载对应版本后端程序文件
151-
packageJson := filepath.Join(versionDir, "package.json")
152-
downloadFile("https://raw.githubusercontent.com/sub-store-org/Sub-Store/master/backend/package.json", packageJson)
153-
lockfile := filepath.Join(versionDir, "pnpm-lock.yaml")
154-
downloadFile("https://raw.githubusercontent.com/sub-store-org/Sub-Store/master/backend/pnpm-lock.yaml", lockfile)
155-
minFile := filepath.Join(versionDir, "sub-store.min.js")
156-
downloadFile(fmt.Sprintf("https://github.com/sub-store-org/Sub-Store/releases/download/%s/sub-store.min.js", v), minFile)
132+
// packageJson := filepath.Join(versionDir, "package.json")
133+
// downloadFile("https://raw.githubusercontent.com/sub-store-org/Sub-Store/master/backend/package.json", packageJson)
134+
// lockfile := filepath.Join(versionDir, "pnpm-lock.yaml")
135+
// downloadFile("https://raw.githubusercontent.com/sub-store-org/Sub-Store/master/backend/pnpm-lock.yaml", lockfile)
136+
minFile := filepath.Join(versionDir, "sub-store.bundle.js")
137+
downloadFile(fmt.Sprintf("https://github.com/sub-store-org/Sub-Store/releases/download/%s/sub-store.bundle.js", v), minFile)
157138

158139
fmt.Println("Files downloaded successfully.")
159140
}

lib/dockerfile.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package lib
2+
3+
const dockerfileStrNode = `FROM node:16-alpine
4+
5+
WORKDIR /app
6+
7+
COPY . .
8+
9+
RUN mkdir config
10+
11+
EXPOSE 3000
12+
13+
CMD cd config && node ../sub-store.bundle.js`

vars/vars.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
const (
10-
Version = "0.0.3"
10+
Version = "0.0.4"
1111
DockerName = "sub-store-manager-backend"
1212
)
1313

0 commit comments

Comments
 (0)