From d2a2953a85b3f633b2a8ee90516b8d71ce1f73fe Mon Sep 17 00:00:00 2001 From: martintomas Date: Wed, 6 Dec 2023 13:18:08 +0100 Subject: [PATCH] refactoring: Set NEXT_PUBLIC_BASE_PATH via --build-args during deployment --- .github/workflows/deploy.yml | 2 +- client/Dockerfile.prod | 5 +++++ infrastructure/base/main.tf | 10 +++++----- infrastructure/base/modules/app/main.tf | 4 ++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 586f192..fa9ec4e 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -38,7 +38,7 @@ jobs: env: IMAGE_NAME: ${{ env.PROJECT_NAME }}-${{ steps.extract_branch.outputs.branch == 'main' && 'production' || 'staging' }}-client run: | - docker build -f client/Dockerfile.prod -t $IMAGE_REGISTRY/$IMAGE_NAME:$GITHUB_SHA . + docker build --build-arg NEXT_PUBLIC_BASE_PATH=/impact-sphere -f client/Dockerfile.prod -t $IMAGE_REGISTRY/$IMAGE_NAME:$GITHUB_SHA . - name: Install doctl uses: digitalocean/action-doctl@v2 diff --git a/client/Dockerfile.prod b/client/Dockerfile.prod index 27f8541..5f87942 100644 --- a/client/Dockerfile.prod +++ b/client/Dockerfile.prod @@ -4,6 +4,10 @@ RUN apt-get update -y && \ apt-get upgrade -y && \ apt-get install -y libc6 && \ apt-get clean + +ARG NEXT_PUBLIC_BASE_PATH +ENV NEXT_PUBLIC_BASE_PATH=$NEXT_PUBLIC_BASE_PATH + ENV NODE_ENV production ENV NEXT_TELEMETRY_DISABLED 1 @@ -17,6 +21,7 @@ RUN yarn install COPY ./client . +RUN echo "NEXT_PUBLIC_BASE_PATH=$NEXT_PUBLIC_BASE_PATH" RUN yarn build # Copy only the built files into the final image diff --git a/infrastructure/base/main.tf b/infrastructure/base/main.tf index d4d5401..dcb0468 100644 --- a/infrastructure/base/main.tf +++ b/infrastructure/base/main.tf @@ -40,8 +40,8 @@ locals { ADMIN_JWT_SECRET = random_password.admin_jwt_secret.result TRANSFER_TOKEN_SALT = random_password.transfer_token_salt.result JWT_SECRET = random_password.jwt_secret.result - CMS_URL = "${module.staging.app_url}/cms" - STRAPI_ADMIN_API_BASE_URL = "${module.staging.app_url}/cms/api" + CMS_URL = "${module.staging.app_url}/impact-sphere/cms" + STRAPI_ADMIN_API_BASE_URL = "${module.staging.app_url}/impact-sphere/cms/api" STRAPI_ADMIN_MAPBOX_ACCESS_TOKEN = var.mapbox_api_token STRAPI_MEDIA_LIBRARY_PROVIDER = "digitalocean" @@ -64,10 +64,10 @@ locals { } staging_client_env = { - NEXT_PUBLIC_URL = module.staging.app_url - NEXT_PUBLIC_BASE_PATH = "" + NEXT_PUBLIC_URL = "${module.staging.app_url}/impact-sphere" + NEXT_PUBLIC_BASE_PATH = "/impact-sphere" NEXT_PUBLIC_ENVIRONMENT = "production" - NEXT_PUBLIC_API_URL = "${module.staging.app_url}/cms/api" + NEXT_PUBLIC_API_URL = "${module.staging.app_url}/impact-sphere/cms/api" NEXT_PUBLIC_GA_TRACKING_ID = var.ga_tracking_id NEXT_PUBLIC_MAPBOX_API_TOKEN = var.mapbox_api_token LOG_LEVEL = "info" diff --git a/infrastructure/base/modules/app/main.tf b/infrastructure/base/modules/app/main.tf index 522ac70..98ef6ec 100644 --- a/infrastructure/base/modules/app/main.tf +++ b/infrastructure/base/modules/app/main.tf @@ -43,7 +43,7 @@ resource "digitalocean_app" "app" { } routes { - path = "/" + path = "/impact-sphere" preserve_path_prefix = false } } @@ -68,7 +68,7 @@ resource "digitalocean_app" "app" { } routes { - path = "/cms" + path = "/impact-sphere/cms" preserve_path_prefix = false } }