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
This commit is contained in:
João Vitória Silva
2024-05-23 09:58:24 +01:00
parent 07268af5ce
commit cef2064eaa
8 changed files with 44 additions and 33 deletions

View File

@@ -17,13 +17,13 @@ RUN pip install --no-cache-dir --upgrade -r requirements.txt \
&& apt-get clean \ && apt-get clean \
&& rm -rf /var/lib/apt/lists/* && 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 the directory backend contents to /app
COPY backend /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_HOST="mariadb"
ENV DB_PORT=3306 ENV DB_PORT=3306
ENV DB_USER="endurain" ENV DB_USER="endurain"

View File

@@ -21,7 +21,14 @@ RUN npm run build
FROM nginx:alpine as production-stage FROM nginx:alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html 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 EXPOSE 80
ENV MY_APP_BACKEND_PROTOCOL=http
ENV MY_APP_BACKEND_HOST=backend
CMD ["nginx", "-g", "daemon off;"] CMD ["nginx", "-g", "daemon off;"]

View File

@@ -59,8 +59,8 @@ Table bellow shows supported environemnt variables. Variables marked with option
Environemnt variable | Default value | Optional Environemnt variable | Default value | Optional
--- | --- | --- --- | --- | ---
BACKEND_PROTOCOL* | http | Yes MY_APP_BACKEND_PROTOCOL* | http | Yes
BACKEND_HOST** | backend | Yes MY_APP_BACKEND_HOST** | backend | Yes
*BACKEND_PROTOCOL needs to be https if you want to enable Strava integration *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. **BACKEND_HOST needs to be set and be Internet faced/resolved if you want to enable Strava integration. Strava callback relies on this.

View File

@@ -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

View File

@@ -5,15 +5,13 @@ services:
container_name: frontend container_name: frontend
image: ghcr.io/joaovitoriasilva/endurain/frontend:latest image: ghcr.io/joaovitoriasilva/endurain/frontend:latest
#environment: #environment:
#- VITE_BACKEND_PROTOCOL=http # http or https, default is http #- MY_APP_BACKEND_PROTOCOL=http # http or https, default is http
#- VITE_BACKEND_HOST=backend # api host, default is backend #- MY_APP_BACKEND_HOST=backend # api host, default is backend
# Configure volume if you want to edit the code locally by clomming the repo # Configure volume if you want to edit the code locally by clomming the repo
#volumes: #volumes:
# - <local_path>/endurain/frontend:/app # - <local_path>/endurain/frontend:/app
ports: ports:
- "8080:80" # frontend port, change per your needs - "8080:80" # frontend port, change per your needs
env_file:
- ./frontend/.env
restart: unless-stopped restart: unless-stopped
# API logic # API logic
@@ -33,8 +31,6 @@ services:
# Configure volume if you want to edit the code locally by clomming the repo # Configure volume if you want to edit the code locally by clomming the repo
#volumes: #volumes:
# - <local_path>/endurain/backend:/app # - <local_path>/endurain/backend:/app
env_file:
- ./backend/.env
depends_on: depends_on:
- mariadb - mariadb
- jaeger - jaeger

View File

@@ -1,2 +1,2 @@
VITE_BACKEND_PROTOCOL=http VITE_BACKEND_PROTOCOL=MY_APP_BACKEND_PROTOCOL
VITE_BACKEND_HOST=backend VITE_BACKEND_HOST=MY_APP_BACKEND_HOST

12
frontend_env.sh Normal file
View File

@@ -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

15
nginx-custom.conf Normal file
View File

@@ -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;
}
}