This repository has been archived by the owner on Jan 22, 2024. It is now read-only.
Deploy Uttak to Q1 by @thomashwi #64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy Uttak | |
on: | |
workflow_dispatch: | |
inputs: | |
environment: | |
description: "Hvilket miljø skal vi deploye til?" | |
required: true | |
default: "Q1" | |
type: choice | |
options: | |
- Q1 | |
- Prod | |
repository_dispatch: | |
types: ["deploy-uttak"] | |
run-name: Deploy Uttak to ${{ inputs.environment || github.event.client_payload.environment }} by @${{ github.actor }} | |
env: | |
IMAGE_BASE: ghcr.io/${{ github.repository }}/psb-uttak-frontend | |
package-name: psb-uttak-frontend | |
jobs: | |
deploy-docker-image: | |
name: Deploy Docker image | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
contents: write | |
outputs: | |
image: ${{ steps.docker-push.outputs.image }} | |
steps: | |
- name: Hente kode | |
uses: actions/checkout@v4 | |
- name: Setup .yarnrc.yml | |
run: | | |
yarn config set npmScopes.navikt.npmRegistryServer "https://npm.pkg.github.com" | |
yarn config set npmScopes.navikt.npmAlwaysAuth true | |
yarn config set npmScopes.navikt.npmAuthToken $NPM_AUTH_TOKEN | |
env: | |
NPM_AUTH_TOKEN: ${{ secrets.READER_TOKEN }} | |
- name: Sette opp Node | |
uses: actions/setup-node@v3 | |
- name: Installere dependencies | |
run: yarn install --immutable | |
- name: Bygg k9-frontend-modules | |
run: yarn build-frontend-modules | |
- name: Kjøre linter | |
run: yarn lerna run lint --scope ${{env.package-name}} | |
- name: Valider typescript | |
run: yarn lerna run ts-check --scope ${{env.package-name}} | |
- name: Kjøre enhetstester | |
run: yarn lerna run test --scope ${{env.package-name}} | |
- name: Kjøre bygg | |
run: yarn lerna run build --scope ${{env.package-name}} | |
- name: Sette versjon | |
working-directory: ./packages/uttak | |
run: | | |
echo "MAJOR_VERSION=$(npm run majorVersion --silent)" >> $GITHUB_ENV | |
- name: Sette tag | |
run: | | |
echo "TAG=$(date "+%Y.%m.%d-%m")-$(git rev-parse --short HEAD)" >> $GITHUB_ENV | |
- name: Sette miljøvariabler | |
working-directory: ./packages/uttak | |
run: | | |
echo "IMAGE=${IMAGE_BASE}:${TAG}" >> $GITHUB_ENV | |
echo "LATEST=${IMAGE_BASE}:latest" >> $GITHUB_ENV | |
echo "CSS_HASH=$(shasum -b -a 384 build/${MAJOR_VERSION}/styles.css | awk '{ print $1 }' | xxd -r -p | base64)" >> $GITHUB_ENV | |
echo "JS_HASH=$(shasum -b -a 384 build/${MAJOR_VERSION}/app.js | awk '{ print $1 }' | xxd -r -p | base64)" >> $GITHUB_ENV | |
- name: Set image output | |
id: docker-push | |
run: echo "IMAGE=$IMAGE_BASE:$TAG" >> $GITHUB_OUTPUT | |
- uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Bygg og laste opp docker-image | |
working-directory: ./packages/uttak | |
run: | | |
docker build --tag ${IMAGE} --tag ${LATEST} . | |
docker push ${IMAGE} | |
docker push ${LATEST} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Deploy til dev-fss | |
uses: nais/deploy/actions/deploy@v1 | |
if: github.event.inputs.environment == 'Q1' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} | |
CLUSTER: dev-fss | |
RESOURCE: ./packages/uttak/nais/naiserator.yml | |
VARS: ./packages/uttak/nais/dev-fss.json | |
- name: Deploy til prod-fss | |
if: (github.ref == 'refs/heads/main' && github.event.inputs.environment == 'Prod') || (github.event.client_payload.ref == 'main' && github.event.client_payload.environment == 'Prod') | |
uses: nais/deploy/actions/deploy@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} | |
CLUSTER: prod-fss | |
RESOURCE: ./packages/uttak/nais/naiserator.yml | |
VARS: ./packages/uttak/nais/prod-fss.json | |
- name: Create Release | |
id: create_release | |
if: (github.ref == 'refs/heads/main' && github.event.inputs.environment == 'Prod') || (github.event.client_payload.ref == 'main' && github.event.client_payload.environment == 'Prod') | |
uses: actions/create-release@latest | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: Uttak.${{ env.TAG }} | |
release_name: Uttak ${{ env.TAG }} | |
body: | | |
For JS, add this to your app: | |
``` | |
<script | |
type="text/javascript" | |
src="https://psb-uttak-frontend.dev.adeo.no/${{ env.MAJOR_VERSION }}/app.js" | |
integrity="sha384-${{ env.JS_HASH }}" | |
crossorigin="anonymous" | |
></script> | |
``` | |
For CSS, add this to the `<head>` of your app: | |
``` | |
<link | |
rel="stylesheet" | |
href="https://psb-uttak-frontend.dev.adeo.no/${{ env.MAJOR_VERSION }}/styles.css" | |
integrity="sha384-${{ env.CSS_HASH }}" | |
crossorigin="anonymous" | |
> | |
``` | |
draft: false | |
prerelease: false | |
trivy: | |
needs: [ deploy-docker-image ] | |
uses: navikt/sif-gha-workflows/.github/workflows/trivy-ghcr.yml@main | |
if: (github.ref == 'refs/heads/main') | |
permissions: | |
contents: write | |
security-events: write | |
actions: read | |
secrets: inherit | |
with: | |
image: ${{ needs.deploy-docker-image.outputs.image }} |