From 9e7bb0a19f6651d060d1a8f3b909b53a7ee0792e Mon Sep 17 00:00:00 2001 From: Jostein Holje Date: Thu, 19 Jan 2023 14:05:19 +0100 Subject: [PATCH 1/8] r Bygg assets utenfor Dockerfile + push til cdn --- .github/workflows/deploy.yml | 59 ++++++++++++++++++++++-------------- Dockerfile | 6 ++-- vite.config.js | 18 +++++------ 3 files changed, 48 insertions(+), 35 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d0b77e26..2dc14722 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -10,33 +10,48 @@ env: IMAGE_BASE: ghcr.io/${{github.repository}}/veientilarbeid jobs: - test-build-and-push: - name: Build, cdn-upload, docker push + push-to-cdn: + name: Build, cdn-upload runs-on: ubuntu-latest + permissions: + contents: 'read' + packages: 'write' + id-token: 'write' + + - uses: 'actions/checkout@v1' + name: Checkout + + - uses: 'actions/setup-node@v3' + with: + node-version: '18' + cache: 'npm' + + - name: 'Install dependencies' + run: 'npm ci' + + - name: 'Build application' + run: 'REACT_APP_MICRO="true" REACT_APP_VERSION_HASH=${{ github.sha }} REACT_APP_BUILD_TIMESTAMP=$(date +"%Y-%m-%dT%H:%M:%S") npm run build:cdn' + + - name: cdn-upload + uses: navikt/frontend/actions/cdn-upload/v1@main + with: + cdn-team-name: paw + source: ./dist/js + destination: '/aia/' + + build-and-push-docker: + name: Build and push docker image + runs-on: ubuntu-latest + needs: push-to-cdn -# permissions: -# contents: 'read' -# packages: 'write' -# id-token: 'write' + permissions: + contents: 'read' + packages: 'write' + id-token: 'write' steps: - uses: 'actions/checkout@v1' name: Checkout -# - uses: 'actions/setup-node@v3' -# with: -# node-version: '18' -# cache: 'npm' -# - name: 'Install dependencies' -# run: 'npm ci' -# - name: 'Build application' -# run: 'npm run build:cdn' -# -# - name: cdn-upload -# uses: navikt/frontend/actions/cdn-upload/v1@main -# with: -# cdn-team-name: paw -# source: ./dist/js -# destination: '/aia/' - name: Lag tag for image run: echo "TAG=$(git log -1 --pretty='%ad_%h' --date=format:'%Y%m%d%H%M%S')" >> $GITHUB_ENV @@ -57,7 +72,7 @@ jobs: deploy-dev: if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/dev') name: Deploy til dev - needs: test-build-and-push + needs: build-and-push-docker runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 diff --git a/Dockerfile b/Dockerfile index 26072c4d..10fe4b5d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ ENV CI=true WORKDIR /source # npm run build har blitt kjørt på github før docker build -# RUN cp -r /source/dist /cdn +RUN cp -r /source/dist /build RUN npm ci @@ -20,13 +20,11 @@ ENV REACT_APP_BUILD_TIMESTAMP=$REACT_APP_BUILD_TIMESTAMP RUN npm run build:demo RUN cp -r /source/dist /demo -ENV REACT_APP_MICRO="true" -RUN npm run build:cdn FROM nginx:1.23-alpine COPY nginx.conf /etc/nginx/nginx.conf -COPY --from=node-builder /source/dist /usr/share/nginx/html/esm +COPY --from=node-builder /build /usr/share/nginx/html/esm COPY --from=node-builder /demo /usr/share/nginx/html/demo RUN cp /usr/share/nginx/html/demo/mockServiceWorker.js /usr/share/nginx/html/mockServiceWorker.js diff --git a/vite.config.js b/vite.config.js index eb2a8835..2ced2ca6 100644 --- a/vite.config.js +++ b/vite.config.js @@ -38,14 +38,14 @@ const getPlugins = () => { const getConfig = () => ({ plugins: getPlugins(), - build: { - lib: { - entry: resolve(__dirname, 'src/main.tsx'), - name: 'veientilarbeid', - formats: ['es'], - fileName: () => `bundle.js`, - }, - }, + // build: { + // lib: { + // entry: resolve(__dirname, 'src/main.tsx'), + // name: 'veientilarbeid', + // formats: ['es'], + // fileName: () => `bundle.js`, + // }, + // }, server: { port: 3002, }, @@ -61,7 +61,7 @@ const getCdnConfig = () => ({ }, preserveEntrySignatures: 'exports-only', output: { - entryFileNames: 'aia.[hash].js', + entryFileNames: 'js/aia.[hash].js', format: 'esm', }, }, From 9d240c2a53c1eeec8192ca546503fbcf50f8eb0a Mon Sep 17 00:00:00 2001 From: Jostein Holje Date: Thu, 19 Jan 2023 14:14:32 +0100 Subject: [PATCH 2/8] r Rename job --- .github/workflows/deploy.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2dc14722..befa2d5e 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -10,9 +10,10 @@ env: IMAGE_BASE: ghcr.io/${{github.repository}}/veientilarbeid jobs: - push-to-cdn: + build-and-push-to-cdn: name: Build, cdn-upload runs-on: ubuntu-latest + permissions: contents: 'read' packages: 'write' @@ -42,7 +43,7 @@ jobs: build-and-push-docker: name: Build and push docker image runs-on: ubuntu-latest - needs: push-to-cdn + needs: build-and-push-to-cdn permissions: contents: 'read' From efcc71b6fdcc3f43d07bb56438e6c465d7782f9c Mon Sep 17 00:00:00 2001 From: Jostein Holje Date: Thu, 19 Jan 2023 14:21:53 +0100 Subject: [PATCH 3/8] r reformat yaml --- .github/workflows/deploy.yml | 44 ++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index befa2d5e..2ecbe6ab 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -10,8 +10,8 @@ env: IMAGE_BASE: ghcr.io/${{github.repository}}/veientilarbeid jobs: - build-and-push-to-cdn: - name: Build, cdn-upload + cdn: + name: Bygg og last opp til CDN runs-on: ubuntu-latest permissions: @@ -19,31 +19,31 @@ jobs: packages: 'write' id-token: 'write' - - uses: 'actions/checkout@v1' - name: Checkout + - uses: 'actions/checkout@v1' + name: Checkout - - uses: 'actions/setup-node@v3' - with: - node-version: '18' - cache: 'npm' + - uses: 'actions/setup-node@v3' + with: + node-version: '18' + cache: 'npm' - - name: 'Install dependencies' - run: 'npm ci' + - name: 'Install dependencies' + run: 'npm ci' - - name: 'Build application' - run: 'REACT_APP_MICRO="true" REACT_APP_VERSION_HASH=${{ github.sha }} REACT_APP_BUILD_TIMESTAMP=$(date +"%Y-%m-%dT%H:%M:%S") npm run build:cdn' + - name: 'Build application' + run: 'REACT_APP_MICRO="true" REACT_APP_VERSION_HASH=${{ github.sha }} REACT_APP_BUILD_TIMESTAMP=$(date +"%Y-%m-%dT%H:%M:%S") npm run build:cdn' - - name: cdn-upload - uses: navikt/frontend/actions/cdn-upload/v1@main - with: - cdn-team-name: paw - source: ./dist/js - destination: '/aia/' + - name: cdn-upload + uses: navikt/frontend/actions/cdn-upload/v1@main + with: + cdn-team-name: paw + source: ./dist/js + destination: '/aia/' - build-and-push-docker: - name: Build and push docker image + docker: + name: Bygg & push Docker runs-on: ubuntu-latest - needs: build-and-push-to-cdn + needs: cdn permissions: contents: 'read' @@ -73,7 +73,7 @@ jobs: deploy-dev: if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/dev') name: Deploy til dev - needs: build-and-push-docker + needs: docker runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 From 53bfb13effb3f269985c543292ebfa573d9bfd0f Mon Sep 17 00:00:00 2001 From: Jostein Holje Date: Thu, 19 Jan 2023 14:25:42 +0100 Subject: [PATCH 4/8] b fix yaml --- .github/workflows/deploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2ecbe6ab..fe0dcc0b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -19,6 +19,7 @@ jobs: packages: 'write' id-token: 'write' + steps: - uses: 'actions/checkout@v1' name: Checkout From 0348482993e8e8c06fbdf72727f225ce41c1e7a2 Mon Sep 17 00:00:00 2001 From: Jostein Holje Date: Thu, 19 Jan 2023 14:31:37 +0100 Subject: [PATCH 5/8] b cdn & docker i samme jobb --- .github/workflows/deploy.yml | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index fe0dcc0b..1d325d79 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -10,8 +10,8 @@ env: IMAGE_BASE: ghcr.io/${{github.repository}}/veientilarbeid jobs: - cdn: - name: Bygg og last opp til CDN + build-cdn-docker: + name: Build, CDN & Docker runs-on: ubuntu-latest permissions: @@ -41,20 +41,6 @@ jobs: source: ./dist/js destination: '/aia/' - docker: - name: Bygg & push Docker - runs-on: ubuntu-latest - needs: cdn - - permissions: - contents: 'read' - packages: 'write' - id-token: 'write' - - steps: - - uses: 'actions/checkout@v1' - name: Checkout - - name: Lag tag for image run: echo "TAG=$(git log -1 --pretty='%ad_%h' --date=format:'%Y%m%d%H%M%S')" >> $GITHUB_ENV @@ -74,7 +60,7 @@ jobs: deploy-dev: if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/dev') name: Deploy til dev - needs: docker + needs: build-cdn-docker runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 From ea18ec03b4c9e8b608fdff9633c01a8216e48c5a Mon Sep 17 00:00:00 2001 From: Jostein Holje Date: Fri, 20 Jan 2023 10:01:27 +0100 Subject: [PATCH 6/8] r Slett ubrukt fil --- app.json | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 app.json diff --git a/app.json b/app.json deleted file mode 100644 index 4b44ac45..00000000 --- a/app.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "veientilarbeid", - "scripts": {}, - "env": { - "NODE_ENV": { - "value": "development" - }, - "NPM_CONFIG_PRODUCTION": { - "value": "false" - }, - "YARN_PRODUCTION": { - "value": "false" - } - }, - "formation": {}, - "addons": [], - "buildpacks": [] -} \ No newline at end of file From 9c929a928b3445b5216bb200222ac1a447c22e82 Mon Sep 17 00:00:00 2001 From: Jostein Holje Date: Fri, 20 Jan 2023 10:02:08 +0100 Subject: [PATCH 7/8] r Fjern bruk av process.env.NODE_ENV --- src/{url.js => url.ts} | 10 ++++++---- vite.config.js | 1 - 2 files changed, 6 insertions(+), 5 deletions(-) rename src/{url.js => url.ts} (66%) diff --git a/src/url.js b/src/url.ts similarity index 66% rename from src/url.js rename to src/url.ts index 624da07d..3881b0a4 100644 --- a/src/url.js +++ b/src/url.ts @@ -1,9 +1,11 @@ +import { erProduksjon } from './utils/app-state-utils'; + function getEnvironment() { - let environment = 'development'; - if (process.env.NODE_ENV === 'production') { - environment = 'production'; + if (erProduksjon()) { + return 'production'; } - return environment; + + return 'development'; } const MINE_DAGPENGER_URL = { diff --git a/vite.config.js b/vite.config.js index 2ced2ca6..aac9360d 100644 --- a/vite.config.js +++ b/vite.config.js @@ -8,7 +8,6 @@ import svgr from 'vite-plugin-svgr'; import EnvironmentPlugin from 'vite-plugin-environment'; const getEnvironmentOpts = () => ({ - NODE_ENV: process.env.NODE_ENV || 'development', REACT_APP_VERSION_HASH: process.env.REACT_APP_VERSIOM_HASH || '', REACT_APP_BUILD_TIMESTAMP: process.env.REACT_APP_BUILD_TIMESTAMP || '', REACT_APP_MICRO: process.env.REACT_APP_MICRO || '', From 29600572d8bee59da578231ed6774e88066d19cd Mon Sep 17 00:00:00 2001 From: Jostein Holje Date: Fri, 20 Jan 2023 10:02:39 +0100 Subject: [PATCH 8/8] r Fjern utkommentert kode --- vite.config.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/vite.config.js b/vite.config.js index aac9360d..3b15e782 100644 --- a/vite.config.js +++ b/vite.config.js @@ -37,14 +37,6 @@ const getPlugins = () => { const getConfig = () => ({ plugins: getPlugins(), - // build: { - // lib: { - // entry: resolve(__dirname, 'src/main.tsx'), - // name: 'veientilarbeid', - // formats: ['es'], - // fileName: () => `bundle.js`, - // }, - // }, server: { port: 3002, },