diff --git a/.env.example b/.env.example index 62a3d851a4..ae905632b3 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,4 @@ -VITE_HOST_URL=http://localhost:1234 +API_URL=http://localhost:1234 VITE_DESCOPE_PROJECT_ID=descopeProjectId TESTS_JWT_AUTH_TOKEN=jwtAuthTokenToRunE2ETests OPEN_AI_KEY=openAiKey diff --git a/Dockerfile b/Dockerfile index 73c486058f..e654317d77 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,29 @@ -FROM node:latest AS builder +# Build stage +FROM node:21-alpine AS build WORKDIR /app -COPY package*.json ./ -RUN npm ci +COPY package.json package-lock.json ./ +RUN npm ci --ignore-scripts --include=dev COPY . . -RUN git submodule update --init -RUN npm run build -EXPOSE 8000 -CMD ["npm", "run", "dev"] +ENV NODE_ENV=production +RUN npm run build:prod +RUN ls -l /app/dist && cat /app/dist/index.html + +# Production stage +FROM nginx:alpine AS production +WORKDIR /app +COPY --from=build /app/dist /usr/share/nginx/html + +# Copy Nginx template (not the final config) +COPY nginx.conf.template /app/nginx.conf.template + +# Copy entrypoint script +COPY docker-entrypoint.sh /app/docker-entrypoint.sh + +# Make entrypoint executable +RUN chmod +x /app/docker-entrypoint.sh + +EXPOSE 80 + +ENTRYPOINT ["/app/docker-entrypoint.sh"] + +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/README.md b/README.md index b8daaea35a..69817bed5d 100644 --- a/README.md +++ b/README.md @@ -44,11 +44,11 @@ Create a `.env` file in the root of the project directory and add the necessary `sh cp .env.example .env` Then edit .env with your environment-specific settings -`VITE_HOST_URL` +`API_URL` - Default: A predefined default host URL mentioned in [getApiBaseUrlFile](https://github.com/autokitteh/web-platform/blob/main/src/utilities/getApiBaseUrl.utils.ts) - Description: Defines the backend URL that the application will use as its host. If not set, the application will use a default host URL. -- Example: VITE_HOST_URL=http://localhost:1234 +- Example: API_URL=http://localhost:1234 `VITE_DESCOPE_PROJECT_ID` diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000000..bf5ce67e41 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# Patching index.html +API_URL=${API_URL:-"/api"} +sed -i 's|appBaseUrl=""|appBaseUrl="'"$API_URL"'"|' /usr/share/nginx/html/index.html +echo "Added appBaseUrl="$API_URL" configuration for react app" + +# Patchng NGINX +if [ -n "$NGNIX_PROXY_API_URL" ]; then + if [ "${NGNIX_PROXY_API_URL: -1}" != "/" ]; then + NGNIX_PROXY_API_URL="${NGNIX_PROXY_API_URL}/" + echo "Added trailing slash to NGNIX_PROXY_API_URL: $NGNIX_PROXY_API_URL" + fi + + sed -i 's|https://api.autokitteh.cloud|'"${NGNIX_PROXY_API_URL}"'|' /app/nginx.conf.template + echo "Added NGINX API routing configuration for $NGNIX_PROXY_API_URL" +fi + +cp /app/nginx.conf.template /etc/nginx/conf.d/default.conf + +exec "$@" diff --git a/index.html b/index.html index 76998e298e..12db4aaed8 100644 --- a/index.html +++ b/index.html @@ -1,6 +1,7 @@
+ <% if (env.VITE_GTM_ID) { %>