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 ec5d73b commit f4b21d4
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 63 deletions.
24 changes: 22 additions & 2 deletions .github/workflows/build_deploy_gcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,30 @@ jobs:
permissions:
contents: read
id-token: write

steps:
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
19 changes: 19 additions & 0 deletions .github/workflows/build_deploy_mock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ jobs:
run: |
echo "IMAGE_TAG=${{ env.DOCKER_IMAGE }}:${{ needs.build-image.outputs.docker-tag }}" >> $GITHUB_ENV
- 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: Deploy til ${{ env.NEXT_PUBLIC_DIGISOS_ENV }}
uses: nais/deploy/actions/deploy@v2
env:
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/build_dev_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@ 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: '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:
Expand Down
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 }}
46 changes: 11 additions & 35 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,45 +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)
FROM node:20-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:20-alpine AS builder
FROM gcr.io/distroless/nodejs20-debian11 AS runtime

ARG DIGISOS_ENV

ENV NEXT_PUBLIC_DIGISOS_ENV=${DIGISOS_ENV}
WORKDIR /app
COPY --from=dependencies /app/node_modules/ node_modules/
COPY . .

RUN npm run orval
RUN npm run build
RUN npm prune --production
WORKDIR /app

COPY package.json /app/
COPY next-logger.config.js /app/
COPY .next/standalone /app/
COPY public /app/public/

FROM node:20-slim AS release
EXPOSE 8080

ARG DIGISOS_ENV

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 ["npm", "start"]
CMD ["server.js"]
5 changes: 3 additions & 2 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ const nextConfig = {
// For å unngå issues med nginx
trailingSlash: true,
swcMinify: false,
output: "standalone",
assetPrefix: process.env.DIGISOS_ENV === "localhost" ? undefined : "https://cdn.nav.no/teamdigisos/sosialhjelp-soknad",
experimental: {
instrumentationHook: true,
optimizePackageImports: ["@navikt/ds-react", "@navikt/aksel-icons"]
optimizePackageImports: ["@navikt/ds-react", "@navikt/aksel-icons"],
},

};

export default nextConfig;

0 comments on commit f4b21d4

Please sign in to comment.