From cef2064eaa01f5fe6c28e67b651e81481ff2882b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Vit=C3=B3ria=20Silva?= Date: Thu, 23 May 2024 09:58:24 +0100 Subject: [PATCH] Backend requirements bump [README] README file updated [frontend] Updated dockerfile for frontend image [backend] Updated dockerfile for backend image [backend] Removed .env file. Env variables loaded on docker build process [frontend] Fixed .env file for frontend docker image [frontend] Added nginx-custom.conf to fix reloads [frontend] Added frontend_env.sh to fix env variables loading on docker image start [docker] Updated docker compose example file --- Dockerfile_backend | 8 ++++---- Dockerfile_frontend | 7 +++++++ README.md | 4 ++-- backend/.env | 19 ------------------- docker-compose.yml | 8 ++------ frontend/.env | 4 ++-- frontend_env.sh | 12 ++++++++++++ nginx-custom.conf | 15 +++++++++++++++ 8 files changed, 44 insertions(+), 33 deletions(-) delete mode 100644 backend/.env create mode 100644 frontend_env.sh create mode 100644 nginx-custom.conf diff --git a/Dockerfile_backend b/Dockerfile_backend index 5dc99ce33..96077c237 100644 --- a/Dockerfile_backend +++ b/Dockerfile_backend @@ -17,13 +17,13 @@ RUN pip install --no-cache-dir --upgrade -r requirements.txt \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* -# Make port 80 available to the world outside this container -EXPOSE 80 - # Copy the directory backend contents to /app COPY backend /app -# Define environment variable +# Make port 80 available to the world outside this container +EXPOSE 80 + +# Define environment variables ENV DB_HOST="mariadb" ENV DB_PORT=3306 ENV DB_USER="endurain" diff --git a/Dockerfile_frontend b/Dockerfile_frontend index a70a00b3f..c4ae2f6b1 100644 --- a/Dockerfile_frontend +++ b/Dockerfile_frontend @@ -21,7 +21,14 @@ RUN npm run build FROM nginx:alpine as production-stage COPY --from=build-stage /app/dist /usr/share/nginx/html +COPY nginx-custom.conf /etc/nginx/conf.d/default.conf + +COPY frontend_env.sh /docker-entrypoint.d/frontend_env.sh +RUN chmod +x /docker-entrypoint.d/frontend_env.sh EXPOSE 80 +ENV MY_APP_BACKEND_PROTOCOL=http +ENV MY_APP_BACKEND_HOST=backend + CMD ["nginx", "-g", "daemon off;"] diff --git a/README.md b/README.md index d58126ea4..b6cfd96f5 100644 --- a/README.md +++ b/README.md @@ -59,8 +59,8 @@ Table bellow shows supported environemnt variables. Variables marked with option Environemnt variable | Default value | Optional --- | --- | --- -BACKEND_PROTOCOL* | http | Yes -BACKEND_HOST** | backend | Yes +MY_APP_BACKEND_PROTOCOL* | http | Yes +MY_APP_BACKEND_HOST** | backend | Yes *BACKEND_PROTOCOL needs to be https if you want to enable Strava integration **BACKEND_HOST needs to be set and be Internet faced/resolved if you want to enable Strava integration. Strava callback relies on this. diff --git a/backend/.env b/backend/.env deleted file mode 100644 index c2aaa5136..000000000 --- a/backend/.env +++ /dev/null @@ -1,19 +0,0 @@ -# .env -DB_HOST=mariadb -DB_PORT=3306 -DB_USER=endurain -DB_PASSWORD=changeme -DB_DATABASE=endurain -SECRET_KEY=changeme # openssl rand -hex 32 -ALGORITHM=HS256 -ACCESS_TOKEN_EXPIRE_MINUTES=30 -STRAVA_CLIENT_ID=changeme -STRAVA_CLIENT_SECRET=changeme -STRAVA_AUTH_CODE=changeme -JAEGER_ENABLED=true -JAEGER_PROTOCOL=http -JAEGER_HOST=jaeger -JAGGER_PORT=4317 -STRAVA_DAYS_ACTIVITIES_ONLINK=30 -FRONTEND_HOST=frontend -GEOCODES_MAPS_API=changeme \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 339a59aa2..76518b084 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,15 +5,13 @@ services: container_name: frontend image: ghcr.io/joaovitoriasilva/endurain/frontend:latest #environment: - #- VITE_BACKEND_PROTOCOL=http # http or https, default is http - #- VITE_BACKEND_HOST=backend # api host, default is backend + #- MY_APP_BACKEND_PROTOCOL=http # http or https, default is http + #- MY_APP_BACKEND_HOST=backend # api host, default is backend # Configure volume if you want to edit the code locally by clomming the repo #volumes: # - /endurain/frontend:/app ports: - "8080:80" # frontend port, change per your needs - env_file: - - ./frontend/.env restart: unless-stopped # API logic @@ -33,8 +31,6 @@ services: # Configure volume if you want to edit the code locally by clomming the repo #volumes: # - /endurain/backend:/app - env_file: - - ./backend/.env depends_on: - mariadb - jaeger diff --git a/frontend/.env b/frontend/.env index ecb1816fa..f9fd581a5 100644 --- a/frontend/.env +++ b/frontend/.env @@ -1,2 +1,2 @@ -VITE_BACKEND_PROTOCOL=http -VITE_BACKEND_HOST=backend \ No newline at end of file +VITE_BACKEND_PROTOCOL=MY_APP_BACKEND_PROTOCOL +VITE_BACKEND_HOST=MY_APP_BACKEND_HOST \ No newline at end of file diff --git a/frontend_env.sh b/frontend_env.sh new file mode 100644 index 000000000..47460b5fe --- /dev/null +++ b/frontend_env.sh @@ -0,0 +1,12 @@ +#!/bin/sh +for i in $(env | grep MY_APP_) +do + key=$(echo $i | cut -d '=' -f 1) + value=$(echo $i | cut -d '=' -f 2-) + echo $key=$value + # sed All files + # find /usr/share/nginx/html -type f -exec sed -i "s|${key}|${value}|g" '{}' + + + # sed JS and CSS only + find /usr/share/nginx/html -type f \( -name '*.js' -o -name '*.css' \) -exec sed -i "s|${key}|${value}|g" '{}' + +done \ No newline at end of file diff --git a/nginx-custom.conf b/nginx-custom.conf new file mode 100644 index 000000000..8db0bfd07 --- /dev/null +++ b/nginx-custom.conf @@ -0,0 +1,15 @@ +server { + listen 80; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ /index.html =404; + } + + error_page 500 502 503 504 /50x.html; + + location = /50x.html { + root /usr/share/nginx/html; + } +}