From 421133de81f39b9e2762c4b63a08395a36eec728 Mon Sep 17 00:00:00 2001 From: CryoTechnic Date: Fri, 22 May 2026 21:03:23 -0400 Subject: [PATCH 1/2] feat: enhance CI/CD workflow with environment-specific configurations and API base URL setup --- .github/workflows/cd.yml | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 21b2cec..85c625f 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -5,10 +5,20 @@ on: branches: - main tags: - - 'v*' + - "v*" pull_request: branches: - main + workflow_dispatch: + inputs: + environment: + description: Target environment + required: true + type: choice + options: + - staging + - dev + - prod env: REGISTRY: ghcr.io @@ -17,6 +27,7 @@ env: jobs: docker: runs-on: ubuntu-latest + environment: ${{ inputs.environment }} permissions: contents: read packages: write @@ -33,8 +44,12 @@ jobs: type=ref,event=pr,prefix=pr- type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} - type=sha,prefix=main-,format=short,enable={{is_default_branch}} - type=raw,value=latest,enable={{is_default_branch}} + type=sha,prefix=main-,format=short,enable=${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} + type=sha,prefix=staging-,format=short,enable=${{ inputs.environment == 'staging' }} + type=sha,prefix=dev-,format=short,enable=${{ inputs.environment == 'dev' }} + type=raw,value=latest,enable=${{ inputs.environment == 'prod' }} + type=raw,value=staging,enable=${{ inputs.environment == 'staging' }} + type=raw,value=dev,enable=${{ inputs.environment == 'dev' }} - name: Login to Registry uses: docker/login-action@v3 @@ -48,6 +63,18 @@ jobs: shell: bash run: echo "SHORT_SHA=$(git rev-parse --short=7 HEAD)" >> "$GITHUB_ENV" + - name: Set API base URL + id: api-url + shell: bash + run: | + if [ "${{ inputs.environment }}" = "staging" ]; then + echo "url=https://planifets.staging.cedille.club" >> "$GITHUB_OUTPUT" + elif [ "${{ inputs.environment }}" = "dev" ]; then + echo "url=https://planifets.dev.cedille.club" >> "$GITHUB_OUTPUT" + else + echo "url=https://planifets.prodv2.cedille.club" >> "$GITHUB_OUTPUT" + fi + - name: Build and push uses: docker/build-push-action@v5 with: From b4b0d4333633b1d6af7d4fb2523b91633e896af6 Mon Sep 17 00:00:00 2001 From: CryoTechnic Date: Wed, 27 May 2026 19:42:32 -0400 Subject: [PATCH 2/2] feat: update environment variable handling and add backend info to footer --- .env.example | 3 ++- .github/workflows/cd.yml | 1 + Dockerfile | 7 +++++-- docker-compose.yml | 4 ++-- next.config.ts | 5 +---- src/app/layout.tsx | 2 +- src/components/Footer.tsx | 32 ++++++++++++++++++++++++++++++++ src/lib/api/endpoints.ts | 1 + src/messages/en.json | 5 ++++- src/messages/fr.json | 5 ++++- 10 files changed, 53 insertions(+), 12 deletions(-) diff --git a/.env.example b/.env.example index 8d198f8..64ebd2b 100644 --- a/.env.example +++ b/.env.example @@ -3,7 +3,8 @@ NEXT_PUBLIC_API_BASE_URL=http://localhost:3001/api # Optional ## Environment -APP_ENV=development +NEXT_PUBLIC_APP_ENV=development +NEXT_PUBLIC_APP_GIT_SHORT_SHA=$(git rev-parse --short=7 HEAD) PORT=3000 CI=false diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 85c625f..59da9ef 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -85,6 +85,7 @@ jobs: labels: ${{ steps.meta.outputs.labels }} build-args: | NEXT_PUBLIC_APP_GIT_SHORT_SHA=${{ env.SHORT_SHA }} + NEXT_PUBLIC_APP_ENV=${{ inputs.environment == 'prod' && 'production' || inputs.environment || 'production' }} NEXT_PUBLIC_API_BASE_URL=https://planifets.prodv2.cedille.club NEXT_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com NEXT_PUBLIC_POSTHOG_UI_HOST=https://us.posthog.com diff --git a/Dockerfile b/Dockerfile index 91b8afc..fbe2512 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,13 +21,14 @@ RUN \ # Development FROM base AS dev WORKDIR /app +RUN apk add --no-cache git COPY --from=deps /app/node_modules ./node_modules ENV NODE_ENV=development ENV NEXT_TELEMETRY_DISABLED=1 EXPOSE 3000 ENV PORT=3000 ENV HOSTNAME="0.0.0.0" -CMD ["yarn", "dev"] +CMD ["sh", "-c", "export NEXT_PUBLIC_APP_GIT_SHORT_SHA=$(git rev-parse --short=7 HEAD 2>/dev/null || echo localdev) && yarn dev"] # Rebuild the source code only when needed FROM base AS builder @@ -42,12 +43,14 @@ ENV NEXT_TELEMETRY_DISABLED=1 ARG NEXT_PUBLIC_API_BASE_URL ARG NEXT_PUBLIC_APP_GIT_SHORT_SHA +ARG NEXT_PUBLIC_APP_ENV ARG NEXT_PUBLIC_POSTHOG_HOST ARG NEXT_PUBLIC_POSTHOG_UI_HOST ARG NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN ARG NEXT_PUBLIC_UMAMI_WEBSITE_ID ENV NEXT_PUBLIC_API_BASE_URL=${NEXT_PUBLIC_API_BASE_URL} ENV NEXT_PUBLIC_APP_GIT_SHORT_SHA=${NEXT_PUBLIC_APP_GIT_SHORT_SHA} +ENV NEXT_PUBLIC_APP_ENV=${NEXT_PUBLIC_APP_ENV} ENV NEXT_PUBLIC_POSTHOG_HOST=${NEXT_PUBLIC_POSTHOG_HOST} ENV NEXT_PUBLIC_POSTHOG_UI_HOST=${NEXT_PUBLIC_POSTHOG_UI_HOST} ENV NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN=${NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN} @@ -64,7 +67,7 @@ RUN \ FROM base AS runner WORKDIR /app -ENV APP_ENV=production +ENV NEXT_PUBLIC_APP_ENV=production ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 diff --git a/docker-compose.yml b/docker-compose.yml index a4af75d..ca76039 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: ports: - '${PORT:-3500}:3000' environment: - APP_ENV: production + NEXT_PUBLIC_APP_ENV: production NODE_ENV: production profiles: - production @@ -26,8 +26,8 @@ services: - /app/node_modules - /app/.next environment: - APP_ENV: development NODE_ENV: development NEXT_PUBLIC_API_BASE_URL: ${NEXT_PUBLIC_API_BASE_URL:-http://localhost:3001/api} + NEXT_PUBLIC_APP_ENV: ${NEXT_PUBLIC_APP_ENV:-development} profiles: - dev diff --git a/next.config.ts b/next.config.ts index 3825b12..81cb58b 100644 --- a/next.config.ts +++ b/next.config.ts @@ -3,15 +3,12 @@ import createNextIntlPlugin from 'next-intl/plugin'; const withNextIntl = createNextIntlPlugin(); -const appEnv = process.env.APP_ENV ?? 'development'; +const appEnv = process.env.NEXT_PUBLIC_APP_ENV ?? 'development'; const posthogApiHost = process.env.NEXT_PUBLIC_POSTHOG_HOST ?? 'https://us.i.posthog.com'; const posthogAssetsHost = posthogApiHost.replace(/\/\/(\w+)\./, '//$1-assets.'); // https://eu.i.posthog.com → https://eu-assets.i.posthog.com const baseConfig: NextConfig = { output: 'standalone', - env: { - NEXT_PUBLIC_APP_ENV: appEnv, - }, // Required for PostHog // SDK sends requests with trailing slashes that Next.js would otherwise redirect, breaking the proxy. skipTrailingSlashRedirect: true, diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 647bfa6..7e01d57 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -23,7 +23,7 @@ export default async function RootLayout({ children }: { children: React.ReactNo - {process.env.APP_ENV !== 'development' + {process.env.NEXT_PUBLIC_APP_ENV !== 'development' ? (