Skip to content

Bytt til nyere workflow for å bygge docker image #2288

Bytt til nyere workflow for å bygge docker image

Bytt til nyere workflow for å bygge docker image #2288

Workflow file for this run

name: Build and deploy
on:
workflow_dispatch:
push:
env:
IMAGE: ghcr.io/${{ github.repository }}/dp-faktasider-frontend:${{ github.sha }}
LATEST_IMAGE: ghcr.io/${{ github.repository }}/dp-faktasider-frontend:latest
jobs:
jest-test:
name: Jest tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 'lts/*'
cache: "npm"
registry-url: "https://npm.pkg.github.com"
- run: npm install --no-save --no-audit --prefer-offline --ignore-scripts
env:
TZ: Europe/Oslo
NODE_AUTH_TOKEN: ${{ secrets.READER_TOKEN }}
- run: npm rebuild && npm run prepare --if-present
env:
TZ: Europe/Oslo
- run: |
npm test
npm run typeCheck
install:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache node_modules
uses: actions/cache@v4
id: node_modules
with:
path: ./node_modules
key: modules-${{ hashFiles('package-lock.json') }}
- uses: actions/setup-node@v4
if: steps.node_modules.outputs.cache-hit != 'true'
with:
node-version: 'lts/*'
cache: "npm"
registry-url: "https://npm.pkg.github.com"
- run: npm ci --ignore-scripts
if: steps.node_modules.outputs.cache-hit != 'true'
env:
NODE_AUTH_TOKEN: ${{ secrets.READER_TOKEN }}
build:
needs: [ install ]
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "lts/*"
- name: Cache node_modules
uses: actions/cache@v4
with:
path: ./node_modules
key: modules-${{ hashFiles('package-lock.json') }}
- name: Cache .next/cache
uses: actions/cache@v4
with:
path: ./.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
- run: npm run build
# Bygg docker image
- name: docker-build-push
uses: nais/docker-build-push@v0
id: docker-build-push
with:
team: teamdagpenger
tag: ${{ github.sha }}
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
salsa: false
- name: Cache static files
uses: actions/cache@v3
with:
path: ./.next/static
key: ${{ github.sha }}
outputs:
image: ${{ steps.docker-build-push.outputs.image }}
digest: ${{ steps.docker-build-push.outputs.digest }}
deploy-dev-gcp:
name: Deploy to dev gcp
needs: [ build, jest-test ]
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: nais/deploy/actions/deploy@v2
env:
CLUSTER: dev-gcp
RESOURCE: nais/nais.yaml
VARS: nais/dev-gcp/vars.yaml
VAR: KAFKA_POOL=nav-dev,image=${{ needs.build.outputs.image }}
PRINT_PAYLOAD: true
- name: Lag deployment i Sentry
uses: getsentry/action-release@v1
continue-on-error: true
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_URL: https://sentry.gc.nav.no
SENTRY_ORG: nav
SENTRY_PROJECT: dp-faktasider-frontend
with:
environment: development
version: ${{ github.sha }}
set_commits: skip
deploy-prod-gcp:
name: Deploy to prod gcp
needs: [ build, deploy-dev-gcp ]
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: nais/deploy/actions/deploy@v2
env:
CLUSTER: prod-gcp
RESOURCE: nais/nais.yaml
VARS: nais/prod-gcp/vars.yaml
VAR: image=${{ needs.build.outputs.image }}
PRINT_PAYLOAD: true
- name: Lag deployment i Sentry
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_URL: https://sentry.gc.nav.no
SENTRY_ORG: nav
SENTRY_PROJECT: dp-faktasider-frontend
with:
environment: production
version: ${{ github.sha }}
set_commits: skip