Skip to content

Commit

Permalink
Cdn upload (#135)
Browse files Browse the repository at this point in the history
* Bruk CDN for statiske filer
* Legg til Faro variabler i ENV istedet for å bruke black magic nais.js
  • Loading branch information
ssaegrov authored Dec 11, 2024
1 parent 68cfa50 commit c0d8576
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ SANITY_PROJECT_ID="rt6o382n"
SANITY_ACCESS_TOKEN=""
SANITY_DATASET="development"

FARO_URL="http://localhost:12347/collect"
GITHUB_SHA="local"

UNLEASH_SERVER_API_TOKEN="" # Finn token her https://dagpenger-unleash-web.iap.nav.cloud.nais.io/admin/api
UNLEASH_SERVER_API_URL=https://dagpenger-unleash-api.nav.cloud.nais.io/api
19 changes: 17 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ jobs:
packages: "write"
outputs:
image: ${{ steps.docker-build-push.outputs.image }}
version_tag: ${{ steps.version-tag.outputs.VERSION_TAG}}

steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: actions/setup-node@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: "22.x"

Expand All @@ -40,6 +40,21 @@ jobs:
dockerfile: Dockerfile
docker_context: .

- name: Build static files
uses: docker/build-push-action@v6
with:
target: build-export
outputs: type=local,dest=build
secrets: NODE_AUTH_TOKEN=${{ secrets.READER_TOKEN }}

- name: Upload static files
uses: nais/deploy/actions/cdn-upload/v2@master
with:
team: teamdagpenger
source: ./build/client
destination: "/dp-saksbehandling-frontend/"
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}


playwright:
Expand Down
5 changes: 5 additions & 0 deletions .nais/nais.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ spec:
- name: UNLEASH_SERVER_API_URL
value: {{unleash.url}}

- name: FARO_URL
value: {{faro_url}}
- name: GITHUB_SHA
value: {{githubSha}}

envFrom:
- secret: dp-saksbehandling-frontend-unleash-api-token

Expand Down
2 changes: 2 additions & 0 deletions .nais/vars-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ sanity_project_id: "rt6o382n"
sanity_access_token: ""
sanity_dataset: "production"

faro_url: "https://telemetry.ekstern.dev.nav.no/collect"

unleash:
url: https://dagpenger-unleash-api.nav.cloud.nais.io/api
environment: development
Expand Down
2 changes: 2 additions & 0 deletions .nais/vars-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ sanity_project_id: "rt6o382n"
sanity_access_token: ""
sanity_dataset: "production"

faro_url: "https://telemetry.nav.no/collect"

unleash:
url: https://dagpenger-unleash-api.nav.cloud.nais.io/api
environment: production
Expand Down
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ COPY ./package-lock.json ./
RUN npm ci --ignore-scripts --omit dev


# export build to filesystem (GitHub)
FROM scratch AS build-export
COPY --from=app-build /app/build ./


# runtime
FROM gcr.io/distroless/nodejs22-debian12 AS runtime
WORKDIR /app
Expand Down
7 changes: 6 additions & 1 deletion app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ if (getEnv("USE_MSW") === "true") {

const csp = {
"script-src": ["blob:"],
"img-src": ["'self'", "data:", "blob:"],
"img-src": [
"'self'",
"data:",
"blob:",
"https://cdn.nav.no/teamdagpenger/dp-saksbehandling-frontend/",
],
"connect-src": [
"'self'",
"*.nav.no",
Expand Down
9 changes: 5 additions & 4 deletions app/faro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { TracingInstrumentation } from "@grafana/faro-web-tracing";

import { getEnv } from "~/utils/env.utils";

import nais from "./nais.js";

let faro: Faro | null = null;

export function initFaro() {
Expand All @@ -14,8 +12,11 @@ export function initFaro() {

faro = initializeFaro({
paused: getEnv("IS_LOCALHOST") === "true",
url: nais.telemetryCollectorURL,
app: nais.app,
url: getEnv("FARO_URL"),
app: {
name: "dp-saksbehandling-frontend",
version: getEnv("GITHUB_SHA"),
},
sessionTracking: {
enabled: true,
persistent: true,
Expand Down
7 changes: 0 additions & 7 deletions app/nais.js

This file was deleted.

8 changes: 5 additions & 3 deletions app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ export function links() {
rel: "icon",
type: "image/png",
sizes: "32x32",
href: `${getEnv("BASE_PATH")}/favicon-32x32.png`,
href: `${getEnv("IS_LOCALHOST") ? "/saksbehandling" : "https://cdn.nav.no/teamdagpenger/dp-saksbehandling-frontend/client"}/favicon-32x32.png`,
},
{
rel: "icon",
type: "image/png",
sizes: "16x16",
href: `${getEnv("BASE_PATH")}/favicon-16x16.png`,
href: `${getEnv("IS_LOCALHOST") ? "/saksbehandling" : "https://cdn.nav.no/teamdagpenger/dp-saksbehandling-frontend/client"}/favicon-16x16.png`,
},
{
rel: "icon",
type: "image/x-icon",
href: `${getEnv("BASE_PATH")}/favicon.ico`,
href: `${getEnv("IS_LOCALHOST") ? "/saksbehandling" : "https://cdn.nav.no/teamdagpenger/dp-saksbehandling-frontend/client"}/favicon.ico`,
},
];
}
Expand Down Expand Up @@ -118,6 +118,8 @@ export async function loader({ request }: LoaderFunctionArgs) {
INNTEKTREDIGERING_URL: process.env.INNTEKTREDIGERING_URL,
GRISEN_URL: process.env.GRISEN_URL,
DAGPENGER_NORGE_URL: process.env.DAGPENGER_NORGE_URL,
GITHUB_SHA: process.env.GITHUB_SHA,
FARO_URL: process.env.FARO_URL,
},
});
}
Expand Down
2 changes: 2 additions & 0 deletions app/utils/env.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ interface IEnv {
NAIS_FRONTEND_TELEMETRY_COLLECTOR_URL: string;
UNLEASH_SERVER_API_URL: string;
UNLEASH_SERVER_API_TOKEN: string;
FARO_URL: string;
GITHUB_SHA: string;
}

export function getEnv(value: keyof IEnv) {
Expand Down
8 changes: 4 additions & 4 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import tsconfigPaths from "vite-tsconfig-paths";
installGlobals();

export default defineConfig({
base: "/saksbehandling/",
base:
process.env.NODE_ENV === "production"
? "https://cdn.nav.no/teamdagpenger/dp-saksbehandling-frontend/client/"
: "/saksbehandling/",
server: {
port: 3000,
},
Expand All @@ -20,9 +23,6 @@ export default defineConfig({
build: {
manifest: true,
sourcemap: true,
rollupOptions: {
external: ["./nais.js"],
},
},
resolve: {
alias: {
Expand Down

0 comments on commit c0d8576

Please sign in to comment.