Browse Source

feat: Docker 化运行

master
OhYee 12 months ago
parent
commit
eab3a54812
Signed by: OhYee
GPG Key ID: 5A9E1F63ED274FBB
  1. 20
      Dockerfile
  2. 33
      build.bash
  3. 6
      package.json

20
Dockerfile

@ -1,9 +1,23 @@ @@ -1,9 +1,23 @@
FROM node:15.14.0
FROM node:16.5.0 AS builder
COPY ./ /data/blotter_page
WORKDIR /data/blotter_page
RUN yarn
RUN yarn build
FROM node:16.5.0 AS prod
ENV backendURI="http://backend:50000"
COPY . /data/blotter_page
COPY --from=builder /data/blotter_page/.next /data/blotter_page/.next
# COPY --from=builder /data/blotter_page/node_modules /data/blotter_page/node_modules
COPY --from=builder /data/blotter_page/package.json /data/blotter_page/package.json
COPY --from=builder /data/blotter_page/yarn.lock /data/blotter_page/yarn.lock
COPY --from=builder /data/blotter_page/next.config.js /data/blotter_page/next.config.js
WORKDIR /data/blotter_page
RUN yarn --prod
ENTRYPOINT [ "yarn", "start"]
ENTRYPOINT [ "yarn", "start" ]

33
build.bash

@ -1,31 +1,6 @@ @@ -1,31 +1,6 @@
#!/bin/bash
SHELL_FOLDER=$(cd "$(dirname "$0")";pwd)
IMAGE="node:15.14.0"
# 拉取镜像
if [[ $(docker images ${IMAGE} | wc -l) -eq "1" ]]; then
echo "Pulling docker image ${IMAGE}..."
docker pull ${IMAGE}
fi
# 更新代码
echo "Pulling latest code..."
git pull
# 在 docker 中挂载当前目录编译
echo "Building execute in docker..."
docker run --rm \
-v ${SHELL_FOLDER}:/data/blotter_page \
${IMAGE} \
bash -c "cd /data/blotter_page && echo 'Generating...' && yarn && yarn build"
echo "Build finished"
docker build -t blotter_page .
echo "Docker image 'blotter' build finished."
echo 'Using `docker run --rm --name=frontend --link backend:backend blotter_page` to start server.'
TAG=$(git describe --abbrev=0 --tags 2>/dev/null || git rev-parse --short HEAD)
IMAGE="ohyee/blotter_page:${TAG}"
echo $IMAGE
docker build -t ${IMAGE} .

6
package.json

@ -20,14 +20,14 @@ @@ -20,14 +20,14 @@
"react": "^17.0.1",
"react-amap": "^1.2.8",
"react-dnd": "^11.1.3",
"react-dnd-html5-backend": "^11.1.3"
"react-dnd-html5-backend": "^11.1.3",
"moment": "^2.29.1",
"axios": "^0.21.0"
},
"devDependencies": {
"@types/node": "^14.14.9",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"axios": "^0.21.0",
"moment": "^2.29.1",
"react-dom": "^17.0.1",
"react-router": "^5.2.0",
"sass": "^1.29.0",

Loading…
Cancel
Save