Skip to content

Commit 5690ec6

Browse files
authored
Get https working for production deployment (#125)
* Change non-secret env vars to variables instead of secrets to be easier to work with. * We no longer need the debug parameter since we use env vars instead of secrets. * Use the new NEXT_PUBLIC_BACKEND_SERVICE_API_PATH env var to make backend API requests. * No longer leave .env checked into the repo * Add 2 missing env vars * Hard code USER_SESSIONS_LOGINURL to prove it out * Fix up BACKEND_PORT --> BACKEND_SERVICE_PORT, and restore the fully dynamic USER_SESSIONS_LOGINURL * Adds a new GitHub workflow file that allows the backend deploy_to_do.yml to determine where the frontend env vars come from when deploying the application. * Set the right list of env vars. * Set NEXT_PUBLIC_TIPTAP_APP_ID * Remove 2 unused env vars * Provide a default value for the backend API path * Undo last commit, no good. * Hard code /api path * Found the issue with NEXT_PUBLIC_BACKEND_SERVICE_API_PATH not being passed through to the frontend app at build time. * Remove extra network debug tools from Dockerfile. * Trigger backend deploy workflow isn't needed. * Make sure production image build also has the backend service API path set * Clean up debug statements for USER_SESSIONS_LOGINURL * Reduce the minimum width on the CoachingSessionList component on the Dashboard page so it fits better in mobile portrait screen sizes.
1 parent 4de6431 commit 5690ec6

File tree

8 files changed

+47
-70
lines changed

8 files changed

+47
-70
lines changed

.env

Lines changed: 0 additions & 15 deletions
This file was deleted.

.github/workflows/build_and_push_nonproduction_images.yml

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ on:
77
branches: [main]
88
types: [opened, synchronize, reopened]
99
workflow_dispatch:
10-
inputs:
11-
enable_env_var_debugging: # Optional debugging parameter useful to debug the build args and env vars
12-
description: 'Enable build args & env vars debugging' # Help text shown in UI
13-
required: false # Not required to run the workflow
14-
default: false # Disabled by default
15-
type: boolean # Simple checkbox in the UI
1610

1711
env:
1812
REGISTRY: ghcr.io
@@ -42,18 +36,6 @@ jobs:
4236
username: ${{ github.actor }}
4337
password: ${{ secrets.GITHUB_TOKEN }}
4438

45-
- name: Debug Environment Variables
46-
if: ${{ inputs.enable_env_var_debugging == true }} # Only run when debugging is enabled
47-
run: |
48-
echo "Building with the following environment variables:" && \
49-
echo "NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL: ${NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL}" && \
50-
echo "NEXT_PUBLIC_BACKEND_SERVICE_HOST: ${NEXT_PUBLIC_BACKEND_SERVICE_HOST}" && \
51-
echo "NEXT_PUBLIC_BACKEND_SERVICE_PORT: ${NEXT_PUBLIC_BACKEND_SERVICE_PORT}" && \
52-
echo "NEXT_PUBLIC_BACKEND_API_VERSION: ${NEXT_PUBLIC_BACKEND_API_VERSION}" && \
53-
echo "FRONTEND_SERVICE_INTERFACE: ${FRONTEND_SERVICE_INTERFACE}" && \
54-
echo "FRONTEND_SERVICE_PORT: ${FRONTEND_SERVICE_PORT}"
55-
56-
5739
- name: Set Image Tag
5840
id: vars
5941
run: |
@@ -73,12 +55,14 @@ jobs:
7355
provenance: true
7456
sbom: true
7557
build-args: |
76-
NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL=${{ secrets.BACKEND_SERVICE_PROTOCOL }}
77-
NEXT_PUBLIC_BACKEND_SERVICE_HOST=${{ secrets.BACKEND_SERVICE_HOST }}
78-
NEXT_PUBLIC_BACKEND_SERVICE_PORT=${{ secrets.BACKEND_PORT }}
79-
NEXT_PUBLIC_BACKEND_API_VERSION=${{ secrets.BACKEND_API_VERSION }}
80-
FRONTEND_SERVICE_PORT=${{ secrets.FRONTEND_SERVICE_PORT }}
81-
FRONTEND_SERVICE_INTERFACE=${{ secrets.FRONTEND_SERVICE_INTERFACE }}
58+
NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL=${{ vars.BACKEND_SERVICE_PROTOCOL }}
59+
NEXT_PUBLIC_BACKEND_SERVICE_HOST=${{ vars.BACKEND_SERVICE_HOST }}
60+
NEXT_PUBLIC_BACKEND_SERVICE_PORT=${{ vars.BACKEND_SERVICE_PORT }}
61+
NEXT_PUBLIC_BACKEND_SERVICE_API_PATH=${{ vars.BACKEND_SERVICE_API_PATH }}
62+
NEXT_PUBLIC_BACKEND_API_VERSION=${{ vars.BACKEND_API_VERSION }}
63+
NEXT_PUBLIC_TIPTAP_APP_ID=${{ vars.TIPTAP_APP_ID }}
64+
FRONTEND_SERVICE_PORT=${{ vars.FRONTEND_SERVICE_PORT }}
65+
FRONTEND_SERVICE_INTERFACE=${{ vars.FRONTEND_SERVICE_INTERFACE }}
8266
tags: ${{ steps.vars.outputs.tag }}
8367
cache-from: type=gha,scope=amd64
8468
cache-to: type=gha,mode=max,scope=amd64
@@ -124,12 +108,14 @@ jobs:
124108
provenance: true
125109
sbom: true
126110
build-args: |
127-
NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL=${{ secrets.BACKEND_SERVICE_PROTOCOL }}
128-
NEXT_PUBLIC_BACKEND_SERVICE_HOST=${{ secrets.BACKEND_SERVICE_HOST }}
129-
NEXT_PUBLIC_BACKEND_SERVICE_PORT=${{ secrets.BACKEND_PORT }}
130-
NEXT_PUBLIC_BACKEND_API_VERSION=${{ secrets.BACKEND_API_VERSION }}
131-
FRONTEND_SERVICE_PORT=${{ secrets.FRONTEND_SERVICE_PORT }}
132-
FRONTEND_SERVICE_INTERFACE=${{ secrets.FRONTEND_SERVICE_INTERFACE }}
111+
NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL=${{ vars.BACKEND_SERVICE_PROTOCOL }}
112+
NEXT_PUBLIC_BACKEND_SERVICE_HOST=${{ vars.BACKEND_SERVICE_HOST }}
113+
NEXT_PUBLIC_BACKEND_SERVICE_PORT=${{ vars.BACKEND_SERVICE_PORT }}
114+
NEXT_PUBLIC_BACKEND_SERVICE_API_PATH=${{ vars.BACKEND_SERVICE_API_PATH }}
115+
NEXT_PUBLIC_BACKEND_API_VERSION=${{ vars.BACKEND_API_VERSION }}
116+
NEXT_PUBLIC_TIPTAP_APP_ID=${{ vars.TIPTAP_APP_ID }}
117+
FRONTEND_SERVICE_PORT=${{ vars.FRONTEND_SERVICE_PORT }}
118+
FRONTEND_SERVICE_INTERFACE=${{ vars.FRONTEND_SERVICE_INTERFACE }}
133119
tags: ${{ steps.vars.outputs.tag }}
134120
cache-from: type=gha,scope=arm64
135121
cache-to: type=gha,mode=max,scope=arm64

.github/workflows/build_and_push_production_images.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,13 @@ jobs:
8585
provenance: true # Enable provenance metadata
8686
sbom: true # Generate Software Bill of Materials
8787
build-args: | # Environment variables for the build
88-
NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL=${{ secrets.BACKEND_SERVICE_PROTOCOL }}
89-
NEXT_PUBLIC_BACKEND_SERVICE_HOST=${{ secrets.BACKEND_SERVICE_HOST }}
90-
NEXT_PUBLIC_BACKEND_SERVICE_PORT=${{ secrets.BACKEND_PORT }}
91-
NEXT_PUBLIC_BACKEND_API_VERSION=${{ secrets.BACKEND_API_VERSION }}
92-
FRONTEND_SERVICE_PORT=${{ secrets.FRONTEND_SERVICE_PORT }}
93-
FRONTEND_SERVICE_INTERFACE=${{ secrets.FRONTEND_SERVICE_INTERFACE }}
88+
NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL=${{ vars.BACKEND_SERVICE_PROTOCOL }}
89+
NEXT_PUBLIC_BACKEND_SERVICE_HOST=${{ vars.BACKEND_SERVICE_HOST }}
90+
NEXT_PUBLIC_BACKEND_SERVICE_PORT=${{ vars.BACKEND_SERVICE_PORT }}
91+
NEXT_PUBLIC_BACKEND_SERVICE_API_PATH=${{ vars.BACKEND_SERVICE_API_PATH }}
92+
NEXT_PUBLIC_BACKEND_API_VERSION=${{ vars.BACKEND_API_VERSION }}
93+
FRONTEND_SERVICE_PORT=${{ vars.FRONTEND_SERVICE_PORT }}
94+
FRONTEND_SERVICE_INTERFACE=${{ vars.FRONTEND_SERVICE_INTERFACE }}
9495
tags: ${{ steps.tags.outputs.frontend_tags }} # Use "stable" tag from previous step
9596
cache-from: type=gha # Use GitHub Actions cache
9697
cache-to: type=gha,mode=max # Cache for future builds

.github/workflows/deploy_to_do.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u ${{ secrets.GHCR_USERNAME }} --password-stdin
5252
5353
# Pull the latest frontend image
54-
docker pull ${{ secrets.FRONTEND_IMAGE_NAME }}
54+
docker pull ${{ vars.FRONTEND_IMAGE_NAME }}
5555
5656
# Stop and remove existing container if it exists
5757
docker stop nextjs-app 2>/dev/null || true
@@ -60,15 +60,15 @@ jobs:
6060
# Run new container with environment variables
6161
docker run -d --name nextjs-app \
6262
--restart unless-stopped \
63-
-p ${{ secrets.FRONTEND_SERVICE_PORT }}:${{ secrets.FRONTEND_SERVICE_PORT }} \
64-
-e NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL=${{ secrets.NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL }} \
65-
-e NEXT_PUBLIC_BACKEND_SERVICE_HOST=${{ secrets.NEXT_PUBLIC_BACKEND_SERVICE_HOST }} \
66-
-e NEXT_PUBLIC_BACKEND_SERVICE_PORT=${{ secrets.NEXT_PUBLIC_BACKEND_SERVICE_PORT }} \
67-
-e NEXT_PUBLIC_BACKEND_API_VERSION=${{ secrets.NEXT_PUBLIC_BACKEND_API_VERSION }} \
63+
-p ${{ vars.FRONTEND_SERVICE_PORT }}:${{ vars.FRONTEND_SERVICE_PORT }} \
64+
-e NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL=${{ vars.NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL }} \
65+
-e NEXT_PUBLIC_BACKEND_SERVICE_HOST=${{ vars.NEXT_PUBLIC_BACKEND_SERVICE_HOST }} \
66+
-e NEXT_PUBLIC_BACKEND_SERVICE_PORT=${{ vars.NEXT_PUBLIC_BACKEND_SERVICE_PORT }} \
67+
-e NEXT_PUBLIC_BACKEND_API_VERSION=${{ vars.NEXT_PUBLIC_BACKEND_API_VERSION }} \
6868
-e NEXT_PUBLIC_TIPTAP_APP_ID=${{ secrets.NEXT_PUBLIC_TIPTAP_APP_ID }} \
69-
-e FRONTEND_SERVICE_INTERFACE=${{ secrets.FRONTEND_SERVICE_INTERFACE }} \
70-
-e FRONTEND_SERVICE_PORT=${{ secrets.FRONTEND_SERVICE_PORT }} \
71-
${{ secrets.FRONTEND_IMAGE_NAME }}
69+
-e FRONTEND_SERVICE_INTERFACE=${{ vars.FRONTEND_SERVICE_INTERFACE }} \
70+
-e FRONTEND_SERVICE_PORT=${{ vars.FRONTEND_SERVICE_PORT }} \
71+
${{ vars.FRONTEND_IMAGE_NAME }}
7272
7373
# Verify the container is running
7474
echo "⏳ Waiting for container to initialize..." # Wait for startup

.gitignore

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ npm-debug.log*
2525
yarn-debug.log*
2626
yarn-error.log*
2727

28-
# local env files
29-
.env*.local
30-
3128
# vercel
3229
.vercel
3330

@@ -38,6 +35,6 @@ next-env.d.ts
3835
# vscode
3936
.vscode/
4037

41-
# environment file
42-
.env
38+
# environment files
39+
.env*
4340

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ARG TARGETPLATFORM
99
ARG NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL
1010
ARG NEXT_PUBLIC_BACKEND_SERVICE_HOST
1111
ARG NEXT_PUBLIC_BACKEND_SERVICE_PORT
12+
ARG NEXT_PUBLIC_BACKEND_SERVICE_API_PATH
1213
ARG NEXT_PUBLIC_BACKEND_API_VERSION
1314
ARG FRONTEND_SERVICE_INTERFACE
1415
ARG FRONTEND_SERVICE_PORT
@@ -27,6 +28,9 @@ RUN npm install
2728

2829
# Stage 2: Builder
2930
FROM base AS builder
31+
32+
RUN apk update && apk upgrade --no-cache && apk add --no-cache bash vim
33+
3034
WORKDIR /app
3135
COPY --from=deps /app/node_modules ./node_modules
3236
COPY . .
@@ -35,6 +39,7 @@ COPY . .
3539
ENV NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL=$NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL
3640
ENV NEXT_PUBLIC_BACKEND_SERVICE_HOST=$NEXT_PUBLIC_BACKEND_SERVICE_HOST
3741
ENV NEXT_PUBLIC_BACKEND_SERVICE_PORT=$NEXT_PUBLIC_BACKEND_SERVICE_PORT
42+
ENV NEXT_PUBLIC_BACKEND_SERVICE_API_PATH=$NEXT_PUBLIC_BACKEND_SERVICE_API_PATH
3843
ENV NEXT_PUBLIC_BACKEND_API_VERSION=$NEXT_PUBLIC_BACKEND_API_VERSION
3944

4045
# Build the Next.js application
@@ -63,6 +68,7 @@ EXPOSE 3000
6368
ENV NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL=$NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL
6469
ENV NEXT_PUBLIC_BACKEND_SERVICE_HOST=$NEXT_PUBLIC_BACKEND_SERVICE_HOST
6570
ENV NEXT_PUBLIC_BACKEND_SERVICE_PORT=$NEXT_PUBLIC_BACKEND_SERVICE_PORT
71+
ENV NEXT_PUBLIC_BACKEND_SERVICE_API_PATH=$NEXT_PUBLIC_BACKEND_SERVICE_API_PATH
6672
ENV NEXT_PUBLIC_BACKEND_API_VERSION=$NEXT_PUBLIC_BACKEND_API_VERSION
6773

6874
# Runtime ENV for Compose

src/lib/api/user-sessions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ export const UserSessionApi = {
7373
* @returns Promise resolving to the deleted UserSession object
7474
*/
7575
delete: async (_id: Id): Promise<UserSession> =>
76-
// TODO we are not using the id here as the backend extracts the user's ID from the session cookie
77-
// at some point it may make sense to decouple user session related network operations from
78-
// entity related network operations.
76+
// TODO we are not using the id here as the backend extracts the user's ID from the session cookie
77+
// at some point it may make sense to decouple user session related network operations from
78+
// entity related network operations.
7979
EntityApi.deleteFn<null, UserSession>(`${USER_SESSIONS_LOGOUTURL}`),
8080

8181
/**

src/site.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const siteConfig = {
22
name: "Refactor Coaching Platform",
3-
url: "https://refactorcoach.com",
3+
url: "https://refactor.engineer",
44
ogImage: "https://ui.shadcn.com/og.jpg",
55
locale: "us",
66
titleStyle: SessionTitleStyle.CoachFirstLastCoacheeFirstLast,
@@ -18,7 +18,9 @@ export const siteConfig = {
1818
"://" +
1919
process.env.NEXT_PUBLIC_BACKEND_SERVICE_HOST +
2020
":" +
21-
process.env.NEXT_PUBLIC_BACKEND_SERVICE_PORT,
21+
process.env.NEXT_PUBLIC_BACKEND_SERVICE_PORT +
22+
"/" +
23+
process.env.NEXT_PUBLIC_BACKEND_SERVICE_API_PATH,
2224
backendApiVersion: process.env.NEXT_PUBLIC_BACKEND_API_VERSION,
2325
frontendServicePort: process.env.FRONTEND_SERVICE_PORT,
2426
frontendServiceInterface: process.env.FRONTEND_SERVICE_INTERFACE,

0 commit comments

Comments
 (0)