Skip to content

Commit fd35644

Browse files
authored
build: add dockerfile (#216)
* build: add dockerfile Signed-off-by: lin594 <lin.yan@bupt.edu.cn> * Update .env.example --------- Signed-off-by: lin594 <lin.yan@bupt.edu.cn>
1 parent fd45dc9 commit fd35644

File tree

7 files changed

+81
-1
lines changed

7 files changed

+81
-1
lines changed

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
docs
3+
dist
4+
.vscode
5+
.idea

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
SERVICE_NAME=hinghwa-dict-uni-app
2+
BACKEND_URL=http://api.pxm.edialect.top # 代码暂不支持
3+
4+
# Traefik Only
5+
PORT=80
6+
HOST_ADDRESS=m.pxm.edialect.top

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM node:14-alpine AS build
2+
RUN mkdir -p /usr/src/app
3+
WORKDIR /usr/src/app
4+
COPY package*.json yarn.lock ./
5+
ENV NODE_ENV=production
6+
RUN yarn install --frozen-lockfile --production=false
7+
COPY . .
8+
RUN yarn build
9+
10+
FROM nginx:stable-alpine
11+
COPY nginx.conf /etc/nginx/conf.d/default.conf
12+
COPY scripts/replace_api_prod.sh /
13+
RUN chmod +x /replace_api_prod.sh
14+
COPY --from=build /usr/src/app/dist/build/h5 /usr/share/nginx/html
15+
16+
CMD ["sh", "/replace_api_prod.sh"]

docker-compose.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
services:
2+
hinghwa-dict-uni-app:
3+
build: .
4+
image: "${SERVICE_NAME}"
5+
container_name: "${SERVICE_NAME}"
6+
environment:
7+
VITE_BACKEND_URL: "${BACKEND_URL}"
8+
labels:
9+
- "traefik.http.routers.${SERVICE_NAME}.rule=${HOST_ADDRESS}"
10+
- "traefik.http.services.${SERVICE_NAME}.loadbalancer.server.port=${PORT:-80}"
11+
- "traefik.http.routers.${SERVICE_NAME}.entrypoints=websecure"
12+
- "traefik.http.routers.${SERVICE_NAME}.tls=true"
13+
- "traefik.http.routers.${SERVICE_NAME}.middlewares=${SERVICE_NAME}-compress"
14+
- "traefik.http.middlewares.${SERVICE_NAME}-compress.compress=true"
15+
networks:
16+
- traefik-global-proxy
17+
18+
networks:
19+
traefik-global-proxy:
20+
external: true

nginx.conf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
server {
2+
listen 80;
3+
server_name localhost;
4+
5+
location /assets/ {
6+
alias /usr/share/nginx/html/assets/;
7+
}
8+
9+
location / {
10+
root /usr/share/nginx/html;
11+
try_files $uri $uri/ /index.html;
12+
add_header Cache-Control "no-cache";
13+
}
14+
15+
error_page 500 502 503 504 /50x.html;
16+
location = /50x.html {
17+
root /usr/share/nginx/html;
18+
}
19+
20+
location ~* \.(?:css|js|ico)$ {
21+
root /usr/share/nginx/html;
22+
try_files $uri $uri/ /index.html;
23+
24+
expires 15d;
25+
add_header Pragma public;
26+
add_header Cache-Control "public";
27+
}
28+
}

scripts/replace_api_prod.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env sh
2+
echo "replacing URLs with $VITE_BACKEND_URL"
3+
find '/usr/share/nginx/html' -name '*.js' -exec sed -i -e 's,VITE_BACKEND_URL_RUNTIME_REPLACEMENT,'"$VITE_BACKEND_URL"',g' {} \;
4+
echo "result: $?, now starting nginx"
5+
nginx -g "daemon off;"

src/pages/quizzes/quizset/questionCard.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export default {
181181
}
182182
183183
.fixbutton {
184-
postion: fixed;
184+
position: fixed;
185185
width: 40%;
186186
margin-top: 100%;
187187

0 commit comments

Comments
 (0)