Skip to content

Commit 02a1ee3

Browse files
authored
chore: support alpine docker image (#755)
1 parent 1e9d710 commit 02a1ee3

File tree

6 files changed

+84
-20
lines changed

6 files changed

+84
-20
lines changed

.docker/alpine/Dockerfile

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
FROM node:22-alpine
2+
3+
# Create app directory
4+
WORKDIR /usr/src/app
5+
6+
# Install app dependencies
7+
COPY . .
8+
9+
RUN chmod +x .docker/build.sh && .docker/build.sh
10+
11+
ENV NODE_ENV=production \
12+
EGG_SERVER_ENV=prod \
13+
CNPMCORE_CONFIG_REGISTRY= \
14+
CNPMCORE_CONFIG_SOURCE_REGISTRY=https://registry.npmmirror.com \
15+
CNPMCORE_CONFIG_SOURCE_REGISTRY_IS_CNPM=true \
16+
CNPMCORE_DATABASE_TYPE= \
17+
CNPMCORE_DATABASE_NAME= \
18+
CNPMCORE_DATABASE_HOST= \
19+
CNPMCORE_DATABASE_PORT=3306 \
20+
CNPMCORE_DATABASE_USER= \
21+
CNPMCORE_DATABASE_PASSWORD= \
22+
CNPMCORE_REDIS_HOST= \
23+
CNPMCORE_REDIS_PORT=6379 \
24+
CNPMCORE_REDIS_PASSWORD= \
25+
CNPMCORE_REDIS_DB= \
26+
CNPMCORE_NFS_TYPE=s3 \
27+
CNPMCORE_NFS_S3_CLIENT_ENDPOINT= \
28+
CNPMCORE_NFS_S3_CLIENT_BUCKET= \
29+
CNPMCORE_NFS_S3_CLIENT_ID= \
30+
CNPMCORE_NFS_S3_CLIENT_SECRET= \
31+
CNPMCORE_NFS_S3_CLIENT_FORCE_PATH_STYLE=true \
32+
CNPMCORE_NFS_S3_CLIENT_DISABLE_URL=true \
33+
TZ=Asia/Shanghai
34+
35+
EXPOSE 7001
36+
CMD ["npm", "run", "start:foreground"]

.docker/build.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
npm install -g npminstall --registry=https://registry.npmmirror.com \
4+
&& npminstall -c \
5+
&& npm run tsc \
6+
&& npmupdate -c --production

.docker/debian/Dockerfile

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
FROM node:22
2+
3+
# Create app directory
4+
WORKDIR /usr/src/app
5+
6+
# Install app dependencies
7+
COPY . .
8+
9+
RUN chmod +x .docker/build.sh && .docker/build.sh
10+
11+
ENV NODE_ENV=production \
12+
EGG_SERVER_ENV=prod \
13+
CNPMCORE_CONFIG_REGISTRY= \
14+
CNPMCORE_CONFIG_SOURCE_REGISTRY=https://registry.npmmirror.com \
15+
CNPMCORE_CONFIG_SOURCE_REGISTRY_IS_CNPM=true \
16+
CNPMCORE_DATABASE_TYPE= \
17+
CNPMCORE_DATABASE_NAME= \
18+
CNPMCORE_DATABASE_HOST= \
19+
CNPMCORE_DATABASE_PORT=3306 \
20+
CNPMCORE_DATABASE_USER= \
21+
CNPMCORE_DATABASE_PASSWORD= \
22+
CNPMCORE_REDIS_HOST= \
23+
CNPMCORE_REDIS_PORT=6379 \
24+
CNPMCORE_REDIS_PASSWORD= \
25+
CNPMCORE_REDIS_DB= \
26+
CNPMCORE_NFS_TYPE=s3 \
27+
CNPMCORE_NFS_S3_CLIENT_ENDPOINT= \
28+
CNPMCORE_NFS_S3_CLIENT_BUCKET= \
29+
CNPMCORE_NFS_S3_CLIENT_ID= \
30+
CNPMCORE_NFS_S3_CLIENT_SECRET= \
31+
CNPMCORE_NFS_S3_CLIENT_FORCE_PATH_STYLE=true \
32+
CNPMCORE_NFS_S3_CLIENT_DISABLE_URL=true \
33+
TZ=Asia/Shanghai
34+
35+
EXPOSE 7001
36+
CMD ["npm", "run", "start:foreground"]

Dockerfile

-18
This file was deleted.

docs/deploy-in-docker.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## 构建镜像
44

55
```bash
6-
docker build -t cnpmcore .
6+
npm run images
77
```
88

99
## 通过环境变量配置参数
@@ -230,5 +230,6 @@ npm whoami --registry=https://registry-demo.fengmk2.com:9443
230230
https://hub.docker.com/r/fengmk2/cnpmcore
231231

232232
```bash
233-
docker pull fengmk2/cnpmcore
233+
docker pull fengmk2/cnpmcore:latest
234+
docker pull fengmk2/cnpmcore:latest-alpine
234235
```

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
"tsc": "npm run clean && tsc -p ./tsconfig.json",
6262
"tsc:prod": "npm run clean && tsc -p ./tsconfig.prod.json",
6363
"prepublishOnly": "npm run tsc:prod",
64+
"images": "npm run images:alpine && npm run images:debian",
65+
"images:alpine": "docker build -t cnpmcore:alpine-latest -f .docker/alpine/Dockerfile .",
66+
"images:debian": "docker build -t cnpmcore:latest -f .docker/debian/Dockerfile .",
6467
"start": "eggctl start --daemon && touch egg.status",
6568
"start:foreground": "eggctl start",
6669
"stop": "rm -f egg.status && sleep 15 && eggctl stop"

0 commit comments

Comments
 (0)