From 95ddb3236c7c099ee13b3075bd4800993e85b38c Mon Sep 17 00:00:00 2001 From: Carl Tibule Date: Thu, 21 Mar 2024 21:01:58 -0500 Subject: [PATCH] Fixed issue with Web Docker image not getting proper environment variable substitution As ReactJS does not seem to support reading environment variables from Docker runtime variables, we'll pull it instead from buildtime. Also added copying of nginx config file in the Dockerfile Modified API Dockerfile to accept WebUri for CORS, also removed duplicate setting of CORS in Program.cs --- API/YABA.API/Dockerfile | 1 + API/YABA.API/Program.cs | 7 +------ API/YABA.API/appsettings.json | 2 +- Web/Dockerfile | 18 ++++++------------ nginx.conf => Web/nginx.conf | 0 5 files changed, 9 insertions(+), 19 deletions(-) rename nginx.conf => Web/nginx.conf (100%) diff --git a/API/YABA.API/Dockerfile b/API/YABA.API/Dockerfile index 17c5b1d..fd43b2b 100644 --- a/API/YABA.API/Dockerfile +++ b/API/YABA.API/Dockerfile @@ -13,6 +13,7 @@ ENV ASPNETCORE_Authentication__Auth0__Domain= ENV ASPNETCORE_Authentication__Auth0__Identifier= ENV ASPNETCORE_ConnectionStrings__YABAReadOnlyDbConnectionString= ENV ASPNETCORE_ConnectionStrings__YABAReadWriteDbConnectionString= +ENV ASPNETCORE_WebClient__Url= FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build WORKDIR /src diff --git a/API/YABA.API/Program.cs b/API/YABA.API/Program.cs index 919bc9f..5d27bf3 100644 --- a/API/YABA.API/Program.cs +++ b/API/YABA.API/Program.cs @@ -120,13 +120,8 @@ app.MapControllers(); app.UseMiddleware(); app.UseMiddleware(); -app.UseCors(x => x - .AllowAnyOrigin() - .AllowAnyMethod() - .AllowAnyHeader()); - var webClientUrl = configuration.GetSection("WebClient").GetValue("Url"); -app.UseCors(x => x.AllowAnyHeader().AllowAnyMethod().WithOrigins(webClientUrl)); +app.UseCors(x => x.WithOrigins(webClientUrl).AllowAnyMethod().AllowAnyHeader()); app.MapHealthChecks("/Pulse"); app.Run(); diff --git a/API/YABA.API/appsettings.json b/API/YABA.API/appsettings.json index 136f450..b31f10b 100644 --- a/API/YABA.API/appsettings.json +++ b/API/YABA.API/appsettings.json @@ -41,6 +41,6 @@ "Enrich": ["FromLogContext", "WithMachineName", "WithProcessId", "WithThreadId"] }, "WebClient": { - "Url": "https://localhost:3000" + "Url": "http://localhost:3000" } } diff --git a/Web/Dockerfile b/Web/Dockerfile index 258ae40..0fb0d8c 100644 --- a/Web/Dockerfile +++ b/Web/Dockerfile @@ -1,22 +1,15 @@ FROM node:17-alpine as builder # Set the environment variables -ENV API_BASE_URL= -ENV AUTH0_DOMAIN= -ENV AUTH0_CLIENT_ID= -ENV AUTH0_CALLBACK_URL= -ENV AUTH0_AUDIENCE= +ARG REACT_APP_API_BASE_URL +ARG REACT_APP_AUTH0_DOMAIN +ARG REACT_APP_AUTH0_CLIENT_ID +ARG REACT_APP_AUTH0_CALLBACK_URL +ARG REACT_APP_AUTH0_AUDIENCE WORKDIR /app COPY package.json . RUN npm install - -RUN echo 'DEBUG': $API_BASE_URL -RUN echo 'DEBUG': $AUTH0_DOMAIN -RUN echo 'DEBUG': $AUTH0_CLIENT_ID -RUN echo 'DEBUG': $AUTH0_CALLBACK_URL -RUN echo 'DEBUG': $AUTH0_AUDIENCE - COPY . . RUN npm run build @@ -24,5 +17,6 @@ FROM nginx:mainline-alpine WORKDIR /usr/share/nginx/html RUN rm -rf ./* COPY --from=builder /app/build . +COPY nginx.conf /etc/nginx/conf.d/default.conf EXPOSE 80 ENTRYPOINT ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/nginx.conf b/Web/nginx.conf similarity index 100% rename from nginx.conf rename to Web/nginx.conf