diff --git a/docker-compose.yml b/docker-compose.yml index 9d1b361..b95171b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,6 +39,10 @@ services: args: - API_URL=${API_URL} - SCORO_URL=${SCORO_URL} + environment: + - API_URL=http://back:3000/ + - SCOROMETER_URL=http://scorometer:6543/ + - NGINX_PORT=80 ports: - "80:80" depends_on: diff --git a/front/Dockerfile b/front/Dockerfile index 4b4c054..cd9b918 100644 --- a/front/Dockerfile +++ b/front/Dockerfile @@ -3,12 +3,14 @@ # Build the app FROM node:16-alpine as build WORKDIR /app -COPY package.json yarn.lock ./ -RUN yarn install # install expo cli RUN yarn global add expo-cli@6.0.5 # add sharp-cli (^2.1.0) for faster image processing RUN yarn global add sharp-cli@^2.1.0 + +COPY package.json yarn.lock ./ +RUN yarn install + COPY . . ARG API_URL ENV API_URL=$API_URL @@ -20,4 +22,6 @@ RUN expo build:web # Serve the app FROM nginx:1.21-alpine COPY --from=build /app/web-build /usr/share/nginx/html -COPY nginx.conf /etc/nginx/conf.d/default.conf +COPY nginx.conf.template /etc/nginx/conf.d/default.conf.template + +CMD envsubst '$API_URL $SCOROMETER_URL $NGINX_PORT' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;' diff --git a/front/nginx.conf b/front/nginx.conf deleted file mode 100644 index acd2787..0000000 --- a/front/nginx.conf +++ /dev/null @@ -1,22 +0,0 @@ -server { - listen 80; - root /usr/share/nginx/html; - - index index.html; - - location / { - try_files $uri $uri/ /index.html; - } - - location /api/ { - proxy_pass http://back:3000/; - } - - location /ws/ { - proxy_pass http://scorometer:6543/; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "Upgrade"; - proxy_set_header Host $host; - } -} \ No newline at end of file diff --git a/front/nginx.conf.template b/front/nginx.conf.template new file mode 100644 index 0000000..d2e1042 --- /dev/null +++ b/front/nginx.conf.template @@ -0,0 +1,25 @@ +server { + listen ${NGINX_PORT}; + root /usr/share/nginx/html; + + index index.html; + + location / { + try_files $uri $uri/ /index.html; + } + + location /api/ { + proxy_pass ${API_URL}; + } + + location /ws { + proxy_set_header Host $host; + proxy_set_header X-Forwarded-Scheme $scheme; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_pass ${SCOROMETER_URL}; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $http_connection; + proxy_http_version 1.1; + } +} \ No newline at end of file