Skip to content

Commit

Permalink
Konverterer til standalone og med cdn
Browse files Browse the repository at this point in the history
  • Loading branch information
almyy committed Nov 21, 2024
1 parent da81f9b commit 6cb3476
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 96 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/build_deploy_gcp_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,30 @@ jobs:
permissions:
contents: read
id-token: write

env:
NEXT_PUBLIC_DIGISOS_ENV: ${{ matrix.environment }}
steps:
- uses: actions/checkout@v4

- name: 'Build npm project'
uses: navikt/sosialhjelp-ci/actions/build-npm@main
with:
node-version: 20
build-less: 'false'
reader-token: ${{ secrets.READER_TOKEN }}
run-test: 'false'
run-orval: 'true'

- name: 'Upload static files to cdn'
id: upload
uses: nais/deploy/actions/cdn-upload/v2@master
with:
team: teamdigisos
source: ./build/static
destination: "/sosialhjelp-soknad/_next"
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}

- name: Build and push docker image to GAR
uses: nais/docker-build-push@v0
id: docker-build-push
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/build_deploy_gcp_prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: 'Build npm project'
uses: navikt/sosialhjelp-ci/actions/build-npm@main
env:
NEXT_PUBLIC_DIGISOS_ENV: prod
with:
node-version: 20
build-less: 'false'
reader-token: ${{ secrets.READER_TOKEN }}
run-test: 'false'
run-orval: 'true'

- name: 'Upload static files to cdn'
id: upload
uses: nais/deploy/actions/cdn-upload/v2@master
with:
team: teamdigisos
source: ./build/static
destination: "/sosialhjelp-soknad/_next"
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}

- name: Build and push docker image to GAR
uses: nais/docker-build-push@v0
id: docker-build-push
Expand Down
33 changes: 20 additions & 13 deletions .github/workflows/build_deploy_mock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ env:
NEXT_PUBLIC_DIGISOS_ENV: mock

jobs:
build-image:
name: "Build Artifact and Image"
build-deploy:
name: "Build image and deploy"
runs-on: ubuntu-latest
outputs:
docker-tag: ${{ steps.docker-image.outputs.full-tag }}
artifact-version: ${{ steps.docker-image.outputs.artifact-version }}
permissions:
contents: write
packages: write
Expand All @@ -21,25 +20,33 @@ jobs:
READER_TOKEN: ${{ secrets.READER_TOKEN }}
WORKFLOW_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: 'Build npm project'
uses: navikt/sosialhjelp-ci/actions/build-npm@main
with:
node-version: 20
build-less: 'false'
reader-token: ${{ secrets.READER_TOKEN }}
run-test: 'false'
run-orval: 'true'
- name: "Build Docker Image"
id: docker-image
uses: navikt/sosialhjelp-soknad/.github/actions/build-image@master
with:
prefix: ${{ env.NEXT_PUBLIC_DIGISOS_ENV }}

deploy-app:
name: "Deploy Application"
runs-on: ubuntu-latest
needs: build-image
permissions:
packages: write
contents: write
steps:
- uses: actions/checkout@v4
- name: 'Upload static files to cdn'
id: upload
uses: nais/deploy/actions/cdn-upload/v2@master
with:
team: teamdigisos
source: ./build/static
destination: "/sosialhjelp-soknad/_next"
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}

- id: docker-image-tag
run: |
echo "IMAGE_TAG=${{ env.DOCKER_IMAGE }}:${{ needs.build-image.outputs.docker-tag }}" >> $GITHUB_ENV
echo "IMAGE_TAG=${{ env.DOCKER_IMAGE }}:${{ steps.docker-image.outputs.full-tag }}" >> $GITHUB_ENV
- name: Deploy til ${{ env.NEXT_PUBLIC_DIGISOS_ENV }}
uses: nais/deploy/actions/deploy@v2
Expand Down
55 changes: 37 additions & 18 deletions .github/workflows/build_dev_image.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
name: "Build dev-sbs Image"
on:
workflow_dispatch:
workflow_dispatch:

jobs:
build-image:
name: "Build dev-sbs Image"
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
actions: write
env:
NEXT_PUBLIC_DIGISOS_ENV: dev-sbs
DOCKER_IMAGE: ghcr.io/${{ github.repository }}/${{ github.event.repository.name }}
READER_TOKEN: ${{ secrets.READER_TOKEN }}
WORKFLOW_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: "Build Docker Image"
uses: navikt/sosialhjelp-soknad/.github/actions/build-image@master
with:
prefix: ${{ env.NEXT_PUBLIC_DIGISOS_ENV }}
build-image:
name: "Build dev-sbs Image"
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
actions: write
env:
NEXT_PUBLIC_DIGISOS_ENV: dev-sbs
DOCKER_IMAGE: ghcr.io/${{ github.repository }}/${{ github.event.repository.name }}
READER_TOKEN: ${{ secrets.READER_TOKEN }}
WORKFLOW_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: 'Build npm project'
uses: navikt/sosialhjelp-ci/actions/build-npm@main
with:
node-version: 20
build-less: 'false'
reader-token: ${{ secrets.READER_TOKEN }}
run-test: 'false'
run-orval: 'true'

- name: 'Upload static files to cdn'
id: upload
uses: nais/deploy/actions/cdn-upload/v2@master
with:
team: teamdigisos
source: ./build/static
destination: "/sosialhjelp-soknad/_next"
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}

- name: "Build Docker Image"
uses: navikt/sosialhjelp-soknad/.github/actions/build-image@master
with:
prefix: ${{ env.NEXT_PUBLIC_DIGISOS_ENV }}
65 changes: 41 additions & 24 deletions .github/workflows/build_prod_image.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
name: Build prod-sbs image - HUSK MANUELL DEPLOY TIL PROD!
on:
workflow_run:
workflows: ["Build code and run test"]
branches:
- master
- 'pre-next'
types:
- completed
workflow_run:
workflows: [ "Build code and run test" ]
branches:
- master
- 'pre-next'
types:
- completed

jobs:
build-image:
name: "Build prod-sbs Image"
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
actions: write
env:
NEXT_PUBLIC_DIGISOS_ENV: prod-sbs
DOCKER_IMAGE: ghcr.io/${{ github.repository }}/${{ github.event.repository.name }}
READER_TOKEN: ${{ secrets.READER_TOKEN }}
WORKFLOW_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: "Build Docker Image"
uses: navikt/sosialhjelp-soknad/.github/actions/build-image@master
with:
prefix: ${{ env.NEXT_PUBLIC_DIGISOS_ENV }}
build-image:
name: "Build prod-sbs Image"
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
actions: write
env:
NEXT_PUBLIC_DIGISOS_ENV: prod-sbs
DOCKER_IMAGE: ghcr.io/${{ github.repository }}/${{ github.event.repository.name }}
READER_TOKEN: ${{ secrets.READER_TOKEN }}
WORKFLOW_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: 'Build npm project'
uses: navikt/sosialhjelp-ci/actions/build-npm@main
with:
node-version: 20
build-less: 'false'
reader-token: ${{ secrets.READER_TOKEN }}
run-test: 'false'
run-orval: 'true'
- name: 'Upload static files to cdn'
id: upload
uses: nais/deploy/actions/cdn-upload/v2@master
with:
team: teamdigisos
source: ./build/static
destination: "/sosialhjelp-soknad/_next"
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
- name: "Build Docker Image"
uses: navikt/sosialhjelp-soknad/.github/actions/build-image@master
with:
prefix: ${{ env.NEXT_PUBLIC_DIGISOS_ENV }}
50 changes: 10 additions & 40 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,51 +1,21 @@
# NB: Når Node-versjon endres, bør samme endring også gjøres i:
# - .nvmrc
# - .github/dependabot.yml (fjern versjonspin for docker)
# - packages.json under "engines" (her leter dependabot npm)
# - .ncurc.js (automatiske oppdateringer for node-types)
# pt er vi på node 18 fordi ellers plager dekoratoren oss med "body has already been consumed"
FROM node:18-alpine AS dependencies

WORKDIR /app
COPY package.json .
COPY package-lock.json .
COPY .npmrc.dockerbuild .npmrc

RUN --mount=type=secret,id=NODE_AUTH_TOKEN NODE_AUTH_TOKEN=$(cat /run/secrets/NODE_AUTH_TOKEN) \
npm ci --prefer-offline --no-audit

FROM node:18-alpine AS builder
FROM gcr.io/distroless/nodejs20-debian11 AS runtime

ARG DIGISOS_ENV
ARG LOGIN_SESSION_API_URL
ARG LOGOUT_URL

ENV NEXT_PUBLIC_DIGISOS_ENV=${DIGISOS_ENV}
ENV LOGIN_SESSION_API_URL=${LOGIN_SESSION_API_URL}
ENV LOGOUT_URL=${LOGOUT_URL}

WORKDIR /app
COPY --from=dependencies /app/node_modules/ node_modules/
COPY . .

RUN npm run orval
RUN npm run build
RUN npm prune --production


FROM gcr.io/distroless/nodejs18-debian12 AS runner
COPY package.json /app/
COPY next-logger.config.js /app/
COPY build/standalone /app/
COPY public /app/public/

ARG DIGISOS_ENV
EXPOSE 8080

ENV NEXT_PUBLIC_DIGISOS_ENV=${DIGISOS_ENV}
ENV NODE_ENV=production
ENV PORT=8080
ENV HOSTNAME=0.0.0.0
ENV NODE_ENV=production

WORKDIR /app

COPY --from=builder --chown=1069:1069 /app/build build
COPY --from=builder /app/node_modules/ node_modules/
COPY package.json .
COPY . .
#ENV NODE_OPTIONS '-r next-logger'

CMD ["./node_modules/next/dist/bin/next", "start"]
CMD ["server.js"]
2 changes: 2 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const nextConfig = {
basePath: "/sosialhjelp/soknad",
// For å unngå issues med nginx
trailingSlash: false,
output: "standalone",
assetPrefix: process.env.DIGISOS_ENV === "localhost" ? undefined : "https://cdn.nav.no/teamdigisos/sosialhjelp-soknad",
experimental: {
optimizePackageImports: ["@navikt/ds-react", "@navikt/aksel-icons"],
},
Expand Down

0 comments on commit 6cb3476

Please sign in to comment.