From 383f52fac0ae00eb83632e7e50f93014d6450915 Mon Sep 17 00:00:00 2001 From: Ludvig Hozman Date: Fri, 3 May 2024 15:56:06 +0200 Subject: [PATCH] Separer configurasjon for gcp Egen dockerfil og build/deploy workflow --- .env.dev-gcp | 9 ++++++ .env.production | 2 -- .github/workflows/gcp.yaml | 56 ++++++++++++++++++++++++++++++++++++++ .github/workflows/main.yml | 21 +------------- Dockerfile | 8 +++--- Dockerfile.gcp | 6 ++++ Dockerfile_heroku | 27 ------------------ package.json | 1 + 8 files changed, 77 insertions(+), 53 deletions(-) create mode 100644 .env.dev-gcp create mode 100644 .github/workflows/gcp.yaml create mode 100644 Dockerfile.gcp delete mode 100644 Dockerfile_heroku diff --git a/.env.dev-gcp b/.env.dev-gcp new file mode 100644 index 0000000000..f094474274 --- /dev/null +++ b/.env.dev-gcp @@ -0,0 +1,9 @@ +VITE_MOCK_ENABLED=false +VITE_USE_HASH_ROUTER=false +VITE_HODE_URL=/internarbeidsflatedecorator +VITE_HODE_URL_V2=https://cdn.nav.no/personoversikt/internarbeidsflate-decorator-v3/dev +SKIP_PREFLIGHT_CHECK=true +VITE_AMPLITUDE_API_KEY=4b7349a378cfc18faf21e1fe6bea0cf2 +VITE_AMPLITUDE_API_KEY_DEV=716ce898b7143ffd7ff3e52dfe69bae7 + +VITE_DRAFT_URL=modiapersonoversikt-draft.intern.dev.nav.no/modiapersonoversikt-draft diff --git a/.env.production b/.env.production index f094474274..b1d6582314 100644 --- a/.env.production +++ b/.env.production @@ -5,5 +5,3 @@ VITE_HODE_URL_V2=https://cdn.nav.no/personoversikt/internarbeidsflate-decorator- SKIP_PREFLIGHT_CHECK=true VITE_AMPLITUDE_API_KEY=4b7349a378cfc18faf21e1fe6bea0cf2 VITE_AMPLITUDE_API_KEY_DEV=716ce898b7143ffd7ff3e52dfe69bae7 - -VITE_DRAFT_URL=modiapersonoversikt-draft.intern.dev.nav.no/modiapersonoversikt-draft diff --git a/.github/workflows/gcp.yaml b/.github/workflows/gcp.yaml new file mode 100644 index 0000000000..3e229fa88b --- /dev/null +++ b/.github/workflows/gcp.yaml @@ -0,0 +1,56 @@ +name: Build & deploy to GCP + +on: [push] + +env: + CI: true + TZ: Europe/Oslo + +jobs: + build: + name: Build + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + id-token: write + outputs: + image: ${{ steps.docker-build-push.outputs.image }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: '18' + cache: 'npm' + - name: Install dependencies + run: npm ci + - name: Test + run: npm run test + - name: Build + run: npm run build:gcp + - name: Publish Docker image + if: github.ref == 'refs/heads/dev' # || github.ref == 'refs/heads/master' + uses: nais/docker-build-push@v0 + id: docker-build-push + with: + dockerfile: Dockerfile.gcp + team: personoversikt + identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }} + project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }} + + deploy-dev: + name: Deploy to dev-gcp + needs: build + if: github.ref == 'refs/heads/dev' + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v4 + - uses: nais/deploy/actions/deploy@v2 + env: + PRINT_PAYLOAD: true + CLUSTER: dev-gcp + RESOURCE: .nais/dev.yaml + VAR: version=${{ github.sha }},image=${{ needs.build.outputs.image }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 15fa7cc178..9b6d493f56 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,10 +3,8 @@ name: Build, push, and deploy on: [push] env: - SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} CI: true TZ: Europe/Oslo - Q2_TEST_BRANCH: refs/heads/gcp jobs: build: @@ -31,7 +29,7 @@ jobs: - name: Build run: npm run build - name: Publish Docker image - if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/master' || github.ref == env.Q2_TEST_BRANCH + if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/master' uses: nais/docker-build-push@v0 id: docker-build-push with: @@ -59,23 +57,6 @@ jobs: RESOURCE: .nais/qa-template.yaml VAR: q_env=${{ matrix.q_env }},version=${{ github.sha }},image=${{ needs.build.outputs.image }} - deploy-dev: - name: Deploy to dev-gcp - needs: build - if: github.ref == 'refs/heads/gcp' - runs-on: ubuntu-latest - permissions: - contents: read - id-token: write - steps: - - uses: actions/checkout@v4 - - uses: nais/deploy/actions/deploy@v2 - env: - PRINT_PAYLOAD: true - CLUSTER: dev-gcp - RESOURCE: .nais/dev.yaml - VAR: version=${{ github.sha }},image=${{ needs.build.outputs.image }} - deploy-prod: name: Deploy to prod needs: build diff --git a/Dockerfile b/Dockerfile index 548a529f54..c9b7ad3d92 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM europe-north1-docker.pkg.dev/nais-management-233d/personoversikt/modia-frontend:0.10-node -ADD proxy-config-q2.json proxy-config.json -COPY build ./static -ENV STATIC_FILES_DIR=./static +FROM europe-north1-docker.pkg.dev/nais-management-233d/personoversikt/modialogin:2024.01.04-09.48-46cd9d7 +ADD proxy-config.json /proxy-config.json +ADD preprod-proxy-config.json /preprod-proxy-config.json +COPY build /www diff --git a/Dockerfile.gcp b/Dockerfile.gcp new file mode 100644 index 0000000000..9fedf62c02 --- /dev/null +++ b/Dockerfile.gcp @@ -0,0 +1,6 @@ +FROM europe-north1-docker.pkg.dev/nais-management-233d/personoversikt/modia-frontend:0.10-node +ADD proxy-config-q2.json proxy-config.json +COPY build ./static + +ENV STATIC_FILES_DIR=./static +ENV BASE_PATH=/ diff --git a/Dockerfile_heroku b/Dockerfile_heroku deleted file mode 100644 index e1a9aef153..0000000000 --- a/Dockerfile_heroku +++ /dev/null @@ -1,27 +0,0 @@ -FROM node:10.23.2-alpine as nodebuilder - -COPY /package.json /source/package.json -COPY /package-lock.json /source/package-lock.json - -WORKDIR /source -RUN npm ci - -COPY /tsconfig.json /source/tsconfig.json -COPY /craco.config.js /source/craco.config.js -COPY /.env.development /source/.env -COPY /.eslintrc.js /source/.eslintrc.js -COPY /src /source/src -COPY /public /source/public -RUN npm run build - -FROM nginx:1.18.0-alpine -RUN apk update && apk add bash - -COPY --from=nodebuilder /source/build /usr/share/nginx/html/modiapersonoversikt -COPY heroku/server.nginx /etc/nginx/conf.d/server.template -COPY heroku/run.sh /run.sh - -SHELL ["/bin/bash", "-c"] -RUN chmod +x /run.sh - -CMD /run.sh diff --git a/package.json b/package.json index 77d8f68cc9..d144161329 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "scripts": { "start": "vite", "build": "vite build", + "build:gcp": "vite build --base=/", "upload-sourcemaps": "cross-env GIT_COMMIT_HASH=$(git rev-parse HEAD) node _scripts/upload-sourcemaps.js", "test": "vitest", "lint": "eslint --ext js,jsx,ts,tsx src",