Skip to content

Commit 89ff50c

Browse files
committed
chore: 12 factor - get config from env
Insert env at build time with Docker build args
1 parent 266b2eb commit 89ff50c

File tree

7 files changed

+30
-42
lines changed

7 files changed

+30
-42
lines changed

.github/workflows/frontend.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ permissions:
1212

1313
jobs:
1414
build:
15-
name: Build and push Docker image to GHCR
15+
name: Build and push prod Docker image to GHCR
1616
runs-on: ubuntu-latest
1717

1818
steps:
@@ -45,6 +45,9 @@ jobs:
4545
- name: Build and (if not PR) push
4646
uses: docker/build-push-action@v5
4747
with:
48+
build-args: |
49+
NEXT_PUBLIC_DJANGO_URL="https://frikanalen.no/api/"
50+
NEXT_PUBLIC_UPLOAD_URL="https://upload.frikanalen.no/files"
4851
push: ${{ github.event_name != 'pull_request' }}
4952
tags: ${{ steps.meta.outputs.tags }}
5053
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ COPY . .
1212
ENV NEXT_TELEMETRY_DISABLED 1
1313
ENV NEXT_PUBLIC_ENV production
1414

15+
ARG NEXT_PUBLIC_DJANGO_URL
16+
ARG NEXT_PUBLIC_UPLOAD_URL
17+
18+
ENV NEXT_PUBLIC_DJANGO_URL=$NEXT_PUBLIC_DJANGO_URL
19+
ENV NEXT_PUBLIC_UPLOAD_URL=$NEXT_PUBLIC_UPLOAD_URL
1520
RUN yarn build
1621

1722
FROM node:18-bullseye AS runner

modules/core/env.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as z from "zod"
2+
3+
const PublicEnvSchema = z.object({
4+
NEXT_PUBLIC_DJANGO_URL: z.string(),
5+
NEXT_PUBLIC_UPLOAD_URL: z.string(),
6+
})
7+
8+
export const env = PublicEnvSchema.parse({
9+
NEXT_PUBLIC_DJANGO_URL: process.env.NEXT_PUBLIC_DJANGO_URL,
10+
NEXT_PUBLIC_UPLOAD_URL: process.env.NEXT_PUBLIC_UPLOAD_URL,
11+
})

modules/network/config.ts

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

modules/network/stores/networkStore.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import axios, { AxiosInstance } from "axios";
2-
import configs from "../config";
32
import { IS_SERVER } from "modules/core/constants";
43
import { createStoreFactory, Store } from "modules/state/classes/Store";
54
import { NextPageContext } from "next";
65
import cookie from "cookie";
76
import { THE_END_OF_TIMES } from "../constants";
7+
import { env } from "../../core/env";
88

99
export class NetworkStore extends Store {
1010
public incomingHeaders: Record<string, string> = {};
@@ -60,15 +60,15 @@ export class NetworkStore extends Store {
6060

6161
this.apiInstance = this.addInterceptors(
6262
axios.create({
63-
baseURL: configs.api,
63+
baseURL: env.NEXT_PUBLIC_DJANGO_URL,
6464
withCredentials: true,
6565
headers, // FIXME: JUST TO GET BUILD RUNNING
6666
})
6767
);
6868

6969
this.uploadInstance = this.addInterceptors(
7070
axios.create({
71-
baseURL: configs.upload,
71+
baseURL: env.NEXT_PUBLIC_UPLOAD_URL,
7272
withCredentials: true,
7373
headers,
7474
})

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
"react-transition-group": "^4.4.2",
4242
"react-twitter-widgets": "^1.10.0",
4343
"shaka-player": "^4.1.1",
44-
"shaka-player-react": "^1.0.1"
44+
"shaka-player-react": "^1.0.1",
45+
"zod": "^3.25.76"
4546
},
4647
"devDependencies": {
4748
"@babel/plugin-proposal-decorators": "^7.15.8",

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3378,3 +3378,8 @@ yaml@^2.1.1:
33783378
version "2.1.1"
33793379
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.1.1.tgz#1e06fb4ca46e60d9da07e4f786ea370ed3c3cfec"
33803380
integrity sha512-o96x3OPo8GjWeSLF+wOAbrPfhFOGY0W00GNaxCDv+9hkcDJEnev1yh8S7pgHF0ik6zc8sQLuL8hjHjJULZp8bw==
3381+
3382+
zod@^3.25.76:
3383+
version "3.25.76"
3384+
resolved "https://registry.yarnpkg.com/zod/-/zod-3.25.76.tgz#26841c3f6fd22a6a2760e7ccb719179768471e34"
3385+
integrity sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==

0 commit comments

Comments
 (0)