diff --git a/.env.sample b/.env.sample index 0b147590..74e17b29 100644 --- a/.env.sample +++ b/.env.sample @@ -17,8 +17,9 @@ EXTRA_CORS_ORIGINS=["http://localhost:3040"] # For Frontend SITE_NAME="DTM-Drone Tasking Manager" -BASE_URL=http://localhost:${BACKEND_WEB_APP_PORT:-8000} +BASE_URL=http://localhost:${BACKEND_WEB_APP_PORT:-8000}/api API_URL_V1=http://localhost:${BACKEND_WEB_APP_PORT:-8000}/api +STATIC_BASE_URL=${MINIO_HOST_URL:-http://localhost:9000}/${FRONTEND_BUCKET_NAME:-frontendstatic}/ # use development for frontend as dev else live DOCKER_TARGET=development diff --git a/.gitignore b/.gitignore index 3ecb3e51..ded39868 100644 --- a/.gitignore +++ b/.gitignore @@ -80,4 +80,4 @@ chart/charts DockerData/ #Backend Template -src/backend/templates/ +src/backend/templates/* diff --git a/docker-compose.yml b/docker-compose.yml index 136f1df3..91a1c041 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,14 +1,14 @@ version: "3" -volumes: - dtm_db_data: - services: backend: build: context: . dockerfile: src/backend/Dockerfile restart: always + depends_on: + - db + - minio ports: - ${BACKEND_WEB_APP_PORT:-8000}:8000 volumes: @@ -22,8 +22,12 @@ services: context: . dockerfile: src/frontend/Dockerfile target: ${DOCKER_TARGET:-development} + args: + - STATIC_BASE_URL=${STATIC_BASE_URL:-http://localhost:9000/frontendstatic/} ports: - ${FRONTEND_WEB_APP_PORT:-3040}:3040 + depends_on: + - minio env_file: .env networks: - dtm-network diff --git a/src/frontend/.env.example b/src/frontend/.env.example index e739342b..f93a0920 100644 --- a/src/frontend/.env.example +++ b/src/frontend/.env.example @@ -1,3 +1,3 @@ SITE_NAME="DTM-Drone Tasking Manager" BASE_URL=https://dronetm-api.naxa.com.np -API_URL_V1=https://dronetm-api.naxa.com.np \ No newline at end of file +API_URL_V1=https://dronetm-api.naxa.com.np/api diff --git a/src/frontend/Dockerfile b/src/frontend/Dockerfile index 22a1e730..9126f16f 100644 --- a/src/frontend/Dockerfile +++ b/src/frontend/Dockerfile @@ -1,5 +1,6 @@ # ARG for the base image ARG NODE_BASE=18.16.0-bullseye-slim +ARG STATIC_BASE_URL http://localhost:9000/frontendstatic/ # Base image with frontend code FROM node:${NODE_BASE} as base @@ -15,6 +16,8 @@ ENTRYPOINT ["/bin/sh", "-c" , "yarn && yarn start --host 0.0.0.0"] # Generate frontend build files FROM base as build +ARG STATIC_BASE_URL +ENV STATIC_BASE_URL ${STATIC_BASE_URL} RUN yarn RUN yarn build diff --git a/src/frontend/docker-entrypoint.sh b/src/frontend/docker-entrypoint.sh index e42fd1c1..568f2e90 100755 --- a/src/frontend/docker-entrypoint.sh +++ b/src/frontend/docker-entrypoint.sh @@ -11,56 +11,21 @@ if [[ -z "${S3_SECRET_KEY}" ]]; then fi MINIO_HOST_URL=${MINIO_HOST_URL:-http://localhost:9000} -FRONTEND_BUCKET_NAME=${FRONTEND_BUCKET_NAME:-frontend-static} +FRONTEND_BUCKET_NAME=${FRONTEND_BUCKET_NAME:-frontendstatic} -mcli config host add minio http://minio:9000 $S3_ACCESS_KEY $S3_SECRET_KEY - -mcli mb minio/${FRONTEND_BUCKET_NAME} || echo "Failed to create bucket in MinIO" -mcli anonymous set download minio/${FRONTEND_BUCKET_NAME}/staticfiles || echo "Failed setting staticfiles dir as public in MinIO" - -mcli cp --recursive /tmp/dist/* minio/${FRONTEND_BUCKET_NAME}/staticfiles +if [[ "${MINIO_HOST_URL}" == 'http://localhost:9000' ]]; then + CONFIG_MINIO=http://minio:9000 +fi -export MAIN_CSS=$(basename $(ls /tmp/dist/assets/index-*.css)) -export MAIN_JS=$(basename $(ls /tmp/dist/assets/index-*.js)) +mcli config host add minio ${CONFIG_MINIO:-MINIO_HOST_URL} $S3_ACCESS_KEY $S3_SECRET_KEY -cat </tmp/index.html -{% with s3_link="${MINIO_HOST_URL}/${FRONTEND_BUCKET_NAME}/staticfiles" %} - - - - - - - - - - Drone Tasking Manager - - - +mcli mb minio/${FRONTEND_BUCKET_NAME} || echo "Failed to create bucket in MinIO" +mcli anonymous set download minio/${FRONTEND_BUCKET_NAME} || echo "Failed setting staticfiles dir as public in MinIO" - -
-
-
- - - -{% endwith %} -EOF +mcli cp --recursive /tmp/dist/* minio/${FRONTEND_BUCKET_NAME} -# Copy index.html to all backend containers for container in $(docker ps -a -q --filter "label=com.docker.compose.service=backend"); do - docker cp /tmp/index.html $container:/project/src/backend/templates/index.html + docker cp /tmp/dist/index.html $container:/project/src/backend/templates/index.html done echo "======================================================" diff --git a/src/frontend/vite.config.ts b/src/frontend/vite.config.ts index f96d1469..2fefc8fc 100644 --- a/src/frontend/vite.config.ts +++ b/src/frontend/vite.config.ts @@ -5,6 +5,7 @@ import { defineConfig } from 'vite'; dotenv.config(); export default defineConfig({ + base: process.env.NODE_ENV === 'development' ? "./" : process.env.STATIC_BASE_URL, plugins: [ react(), process.env.NODE_ENV !== 'production' @@ -43,6 +44,7 @@ export default defineConfig({ BASE_URL: process.env.BASE_URL, API_URL_V1: process.env.API_URL_V1, SITE_NAME: process.env.SITE_NAME, + STATIC_BASE_URL: process.env.STATIC_BASE_URL }, }, server: {