From 189d6024d06f0000e13107647beb7478ac28cb02 Mon Sep 17 00:00:00 2001 From: dabico Date: Fri, 7 Jun 2024 13:48:52 +0200 Subject: [PATCH] Improve front-end setup to match that of GHS --- deployment/.env.template | 2 -- deployment/docker-compose.yml | 17 ++++++++-------- deployment/website/Dockerfile | 38 +++++++++++++++++++++-------------- nginx/nginx.conf | 16 --------------- nginx/nginx.conf.template | 19 ++++++++++++++++++ 5 files changed, 51 insertions(+), 41 deletions(-) delete mode 100644 nginx/nginx.conf create mode 100644 nginx/nginx.conf.template diff --git a/deployment/.env.template b/deployment/.env.template index 18f898c4..21cdd155 100644 --- a/deployment/.env.template +++ b/deployment/.env.template @@ -8,5 +8,3 @@ SERVER_MAIL_PASS=$SERVER_MAIL_PASS SERVER_SECURITY_USER=$SERVER_SECURITY_USER SERVER_SECURITY_PASS=$SERVER_SECURITY_PASS SERVER_JWT_SECRET=$SERVER_JWT_SECRET - -WEBSITE_PORT=$WEBSITE_PORT diff --git a/deployment/docker-compose.yml b/deployment/docker-compose.yml index 2f90ff66..31a73eb1 100644 --- a/deployment/docker-compose.yml +++ b/deployment/docker-compose.yml @@ -87,7 +87,7 @@ services: SERVER_SECURITY_USER: ${SERVER_SECURITY_USER} SERVER_SECURITY_PASS: ${SERVER_SECURITY_PASS} SERVER_JWT_SECRET: ${SERVER_JWT_SECRET} - WEBSITE_URL: http://localhost:${WEBSITE_PORT} + WEBSITE_URL: http://localhost:7031 volumes: - ./logs:/logs - server-tmp:/tmp @@ -98,8 +98,7 @@ services: restart_policy: condition: on-failure max_attempts: 3 - ports: - - "${SERVER_PORT}:${SERVER_PORT}" + ports: [ "48002:8080" ] dl4se-website: container_name: dl4se-website @@ -107,16 +106,18 @@ services: build: context: ../ dockerfile: deployment/website/Dockerfile - args: - WEBSITE_PORT: ${WEBSITE_PORT} networks: - default - restart: always + environment: + BASE_URL: http://localhost:48002 depends_on: dl4se-server: condition: service_healthy - ports: - - "${WEBSITE_PORT}:80" + deploy: + restart_policy: + condition: on-failure + max_attempts: 3 + ports: [ "7031:80" ] volumes: data: diff --git a/deployment/website/Dockerfile b/deployment/website/Dockerfile index 10345aac..9c6b338c 100644 --- a/deployment/website/Dockerfile +++ b/deployment/website/Dockerfile @@ -1,20 +1,28 @@ -FROM node:18.18.2-alpine AS install -ARG WEBSITE_PORT -ARG SERVER_URL -COPY ./dl4se-website/package*.json ./ -RUN npm install +FROM node:18.20.3-alpine AS build + COPY ./dl4se-website . -FROM install AS build -ARG WEBSITE_PORT -ARG SERVER_URL -ARG NODE_ENV=production -RUN apk update --quiet && \ - apk add --no-cache --quiet gettext && \ - envsubst < .env.template > .env && \ - npm run build +COPY <<-EOF .env +VUE_APP_API_BASE_URL=http://localhost:8080/api +EOF + +RUN npm ci && npm run build + +FROM nginx:1.26.0-alpine-slim AS production + +ENV TZ=UTC -FROM nginx:1.25.3-alpine AS production COPY --from=build /dist /usr/share/nginx/html -COPY ./nginx/nginx.conf /etc/nginx/conf.d/default.conf +COPY ./nginx/nginx.conf.template /etc/nginx/templates/default.conf.template + +ENTRYPOINT ["/docker-entrypoint.sh"] CMD ["nginx", "-g", "daemon off;"] + +EXPOSE 80 8000 + +HEALTHCHECK \ + --start-period=10s \ + --interval=60s \ + --timeout=30s \ + --retries=5 \ + CMD nc -z 127.0.0.1 80 || exit 1 diff --git a/nginx/nginx.conf b/nginx/nginx.conf deleted file mode 100644 index 6f9531cf..00000000 --- a/nginx/nginx.conf +++ /dev/null @@ -1,16 +0,0 @@ -server { - listen 80; - server_name localhost; - - location / { - root /usr/share/nginx/html; - index index.html; - try_files $uri $uri/ /index.html; - } - - error_page 500 502 503 504 /50x.html; - - location = /50x.html { - root /usr/share/nginx/html; - } -} \ No newline at end of file diff --git a/nginx/nginx.conf.template b/nginx/nginx.conf.template new file mode 100644 index 00000000..3bf9fb66 --- /dev/null +++ b/nginx/nginx.conf.template @@ -0,0 +1,19 @@ +server { + listen 80; + server_name localhost; + + location / { + root /usr/share/nginx/html; + index index.html; + try_files $uri $uri/ /index.html; + sub_filter_once off; + sub_filter_types application/javascript; + sub_filter "http://localhost:8080" "${BASE_URL}"; + } +} + +server { + listen 8000; + server_name localhost; + stub_status on; +}