Skip to content

Commit b13f991

Browse files
authored
Merge pull request s045pd#2 from MSKNET/patch
Optimize the docker image
2 parents 1a961c9 + 2a979af commit b13f991

File tree

7 files changed

+12475
-19227
lines changed

7 files changed

+12475
-19227
lines changed

Dockerfile

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
1-
FROM node:12.16.2-stretch
2-
3-
4-
COPY sources.list /etc/apt/sources.list
5-
RUN apt update && apt install ffmpeg -y
6-
1+
FROM node:12-slim AS gui-builder
2+
COPY gui/package.json gui/package-lock.json /work/gui/
3+
RUN cd /work/gui && npm ci && npm cache clean --force
4+
COPY gui /work/gui
5+
RUN cd /work/gui && npm run build && npm cache clean --force
6+
7+
8+
FROM node:12-slim AS production
9+
RUN sed -i 's/deb.debian.org/archive.debian.org/g' /etc/apt/sources.list && \
10+
sed -i 's/security.debian.org/archive.debian.org/g' /etc/apt/sources.list && \
11+
sed -i '/stretch-updates/d' /etc/apt/sources.list && \
12+
apt-get update && \
13+
apt-get install -y --no-install-recommends ffmpeg && \
14+
apt-get clean && \
15+
rm -rf /var/lib/apt/lists/*
716

817
WORKDIR /work/
9-
COPY anyproxy/ ./anyproxy/
1018
COPY package.json package-lock.json .
11-
RUN npm install
12-
19+
RUN npm ci && npm cache clean --force
1320

14-
COPY gui/ ./gui/
15-
WORKDIR /work/gui
16-
RUN npm install && npm run build
21+
COPY anyproxy/ ./anyproxy/
22+
COPY --from=gui-builder /work/gui/dist /work/gui/dist
1723

18-
WORKDIR /work/
1924
COPY utils.js api-server.js server.js database.js docker-entrypoint.sh .
20-
RUN /work/anyproxy/bin/anyproxy-ca --generate \
21-
&& mkdir /work/ssl/ \
22-
&& cp /root/.anyproxy/certificates/rootCA.* /work/ssl/
23-
RUN apt-get clean && npm cache clean -f
24-
25-
26-
27-
ENTRYPOINT ["/work/docker-entrypoint.sh"]
25+
ENTRYPOINT ["/work/docker-entrypoint.sh"]

Dockerfile_CN

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1-
FROM node:12.16.2-stretch
1+
ARG NPM_REGISTRY=https://registry.npm.taobao.org
2+
FROM node:12-slim AS gui-builder
3+
COPY gui/package.json gui/package-lock.json /work/gui/
4+
RUN cd /work/gui && npm config set registry ${NPM_REGISTRY} && npm ci && npm cache clean --force
5+
COPY gui /work/gui
6+
RUN cd /work/gui && npm run build && npm cache clean --force
27

38

9+
FROM node:12-slim AS production
410
COPY sources.list /etc/apt/sources.list
5-
RUN apt update && apt install ffmpeg -y
6-
11+
RUN apt-get update && \
12+
apt-get install -y --no-install-recommends ffmpeg && \
13+
apt-get clean && \
14+
rm -rf /var/lib/apt/lists/*
715

816
WORKDIR /work/
9-
COPY anyproxy/ ./anyproxy/
1017
COPY package.json package-lock.json .
11-
RUN npm config set registry https://registry.npm.taobao.org && npm install
18+
RUN npm config set registry ${NPM_REGISTRY} && npm ci && npm cache clean --force
1219

20+
COPY anyproxy/ ./anyproxy/
21+
COPY --from=gui-builder /work/gui/dist /work/gui/dist
1322

14-
COPY gui/ ./gui/
15-
WORKDIR /work/gui
16-
RUN npm install && npm run build
17-
18-
WORKDIR /work/
1923
COPY utils.js api-server.js server.js database.js docker-entrypoint.sh .
20-
RUN /work/anyproxy/bin/anyproxy-ca --generate \
21-
&& mkdir /work/ssl/ \
22-
&& cp /root/.anyproxy/certificates/rootCA.* /work/ssl/
23-
RUN apt-get clean && npm cache clean -f
24-
25-
26-
27-
ENTRYPOINT ["/work/docker-entrypoint.sh"]
24+
ENTRYPOINT ["/work/docker-entrypoint.sh"]

api-server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ async function get_api_server(proxy_utils) {
627627
* Serve up the CA cert for download
628628
*/
629629
app.get(API_BASE_PATH + "/download_ca", async (req, res) => {
630-
res.download(`${__dirname}/ssl/rootCA.crt`, "CursedChromeCA.crt");
630+
res.download(`${__dirname}/cassl/rootCA.crt`, "CursedChromeCA.crt");
631631
});
632632

633633
/*

database.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ function get_default_user_created_banner(username, password) {
297297
return `
298298
============================================================================
299299
300-
█████╗ ████████╗████████╗███████╗███╗ ██╗████████╗██╗ ████���█╗ ███╗ ██╗
300+
█████╗ ████████╗████████╗███████╗███╗ ██╗████████╗██╗ █████╗ ███╗ ██╗
301301
██╔══██╗╚══██╔══╝╚══██╔══╝██╔════╝████╗ ██║╚══██╔══╝██║██╔═══██╗████╗ ██║
302302
███████║ ██║ ██║ █████╗ ██╔██╗ ██║ ██║ ██║██║ ██║██╔██╗ ██║
303303
██╔══██║ ██║ ██║ ██╔══╝ ██║╚██╗██║ ██║ ██║██║ ██║██║╚██╗██║

docker-entrypoint.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
#!/bin/bash
22
sleep 3
3-
cp /work/ssl/* /work/cassl/
3+
4+
if [ ! -d /work/cassl ]; then
5+
echo "Error: The /work/cassl directory does not exist!"
6+
echo "Please mount this directory before running the Docker container."
7+
exit 1
8+
fi
9+
10+
if [ ! -f /work/cassl/rootCA.crt ] || [ ! -f /work/cassl/rootCA.key ]; then
11+
echo "The certificate and key files are missing in /work/cassl. Generating new CA..."
12+
/work/anyproxy/bin/anyproxy-ca --generate
13+
cp -a /root/.anyproxy/certificates/rootCA.* /work/cassl/
14+
else
15+
echo "Using existing certificate and key files..."
16+
mkdir -p /root/.anyproxy/certificates
17+
cp -a /work/cassl/rootCA.* /root/.anyproxy/certificates/
18+
fi
19+
420
node /work/server.js

0 commit comments

Comments
 (0)