From cc7010c8d2a9fb90719131803a2b9931d88aebd0 Mon Sep 17 00:00:00 2001 From: Eirik Vigeland Date: Mon, 11 Mar 2024 13:35:22 +0100 Subject: [PATCH] feat. Sette opp ny workflow med nais/docker-build-push@v0 og bygg av branch (#1205) --- .editorconfig | 6 + .github/workflows/bygg-branch.yml | 34 +++ ...ploy-dev.yml => bygg-og-deploy-branch.yml} | 82 +++--- .github/workflows/bygg-og-deploy-master.yml | 271 +++++++++--------- .github/workflows/dispatch.yml | 17 -- 5 files changed, 223 insertions(+), 187 deletions(-) create mode 100644 .github/workflows/bygg-branch.yml rename .github/workflows/{bygg-og-deploy-dev.yml => bygg-og-deploy-branch.yml} (57%) delete mode 100644 .github/workflows/dispatch.yml diff --git a/.editorconfig b/.editorconfig index 9e0acf914..c38dec9a3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,3 +5,9 @@ indent_size = 4 indent_style = space insert_final_newline = true max_line_length = 120 + +[*.yml] +indent_size = 2 + +[*.yaml] +indent_size = 2 diff --git a/.github/workflows/bygg-branch.yml b/.github/workflows/bygg-branch.yml new file mode 100644 index 000000000..f696b6157 --- /dev/null +++ b/.github/workflows/bygg-branch.yml @@ -0,0 +1,34 @@ +name: Bygg branch + +on: + push: + branches: + - '**' + - '!master' + +jobs: + build: + name: Bygg branch + runs-on: ubuntu-latest + steps: + - name: Sjekk ut kode + uses: actions/checkout@v4 + - name: Setup node.js + uses: actions/setup-node@v3 + with: + registry-url: 'https://npm.pkg.github.com' + - name: Install + run: npm ci + env: + NODE_AUTH_TOKEN: ${{ secrets.READER_TOKEN }} + - name: Server install + working-directory: ./server + run: npm ci + env: + NODE_AUTH_TOKEN: ${{ secrets.READER_TOKEN }} + - name: Typescript + run: npm run ts + - name: Prettier + run: npm run prettier + - name: Kjør tester + run: npm run test diff --git a/.github/workflows/bygg-og-deploy-dev.yml b/.github/workflows/bygg-og-deploy-branch.yml similarity index 57% rename from .github/workflows/bygg-og-deploy-dev.yml rename to .github/workflows/bygg-og-deploy-branch.yml index ead9fb584..c781a0019 100644 --- a/.github/workflows/bygg-og-deploy-dev.yml +++ b/.github/workflows/bygg-og-deploy-branch.yml @@ -1,23 +1,19 @@ -name: Bygg og deploy dev +name: Bygg og deploy branch -on: - workflow_dispatch: - -env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_REPOSITORY: ${{ github.repository }} - IMAGE: ghcr.io/${{ github.repository }}/tiltaksgjennomforing:${{ github.sha }} - SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} +on: workflow_dispatch jobs: - bygg: + build: + name: Bygg permissions: - packages: write - name: Bygg og deploy - runs-on: ubuntu-20.04 + contents: read + id-token: write + outputs: + image: ${{ steps.docker-build-push.outputs.image }} + runs-on: ubuntu-latest steps: - name: Sjekk ut kode - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup node.js uses: actions/setup-node@v3 with: @@ -47,56 +43,64 @@ jobs: - name: Remove source maps run: | rm dist/client/assets/*.map - - name: Bygg, tag og push Docker-image - run: | - echo ${GITHUB_TOKEN} | docker login ghcr.io -u ${GITHUB_REPOSITORY} --password-stdin - docker build --tag ${IMAGE} . - docker push ${IMAGE} + - name: Push docker image to GAR + uses: nais/docker-build-push@v0 + id: docker-build-push + with: + team: arbeidsgiver + identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }} + project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }} deploy-dev-gcp-intern: name: Deploy til dev-gcp intern - runs-on: ubuntu-20.04 - needs: bygg + runs-on: ubuntu-latest + needs: build + permissions: + contents: read + id-token: write steps: - name: Sjekk ut kode - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Deploy til dev-gcp intern - uses: nais/deploy/actions/deploy@v1 + uses: nais/deploy/actions/deploy@v2 env: - APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} CLUSTER: dev-gcp RESOURCE: nais/nais-gcp-intern.yaml - PRINT_PAYLOAD: true VARS: nais/dev-gcp-intern.yaml - + VAR: image=${{ needs.build.outputs.image }} + deploy-dev-gcp-ekstern: name: Deploy til dev-gcp ekstern - runs-on: ubuntu-20.04 - needs: bygg + runs-on: ubuntu-latest + needs: build + permissions: + contents: read + id-token: write steps: - name: Sjekk ut kode - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Deploy til dev-gcp ekstern - uses: nais/deploy/actions/deploy@v1 + uses: nais/deploy/actions/deploy@v2 env: - APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} CLUSTER: dev-gcp RESOURCE: nais/nais-gcp-ekstern.yaml - PRINT_PAYLOAD: true VARS: nais/dev-gcp-ekstern.yaml - + VAR: image=${{ needs.build.outputs.image }} + deploy-dev-gcp-labs: name: Deploy til dev-gcp (labs) - runs-on: ubuntu-20.04 - needs: bygg + runs-on: ubuntu-latest + needs: build + permissions: + contents: read + id-token: write steps: - name: Sjekk ut kode - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Deploy til dev-gcp - uses: nais/deploy/actions/deploy@v1 + uses: nais/deploy/actions/deploy@v2 env: - APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} CLUSTER: dev-gcp RESOURCE: nais/dev-gcp-labs.yaml - PRINT_PAYLOAD: true VARS: nais/dev-gcp-labs.json + VAR: image=${{ needs.build.outputs.image }} diff --git a/.github/workflows/bygg-og-deploy-master.yml b/.github/workflows/bygg-og-deploy-master.yml index a0d880cb8..8255c511f 100644 --- a/.github/workflows/bygg-og-deploy-master.yml +++ b/.github/workflows/bygg-og-deploy-master.yml @@ -1,136 +1,145 @@ name: Bygg og deploy master on: - push: - branches: - - 'master' - -env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_REPOSITORY: ${{ github.repository }} - IMAGE: ghcr.io/${{ github.repository }}/tiltaksgjennomforing:${{ github.sha }} - SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + push: + branches: + - 'master' jobs: - bygg: - permissions: - packages: write - name: Bygg - runs-on: ubuntu-20.04 - steps: - - name: Sjekk ut kode - uses: actions/checkout@v3 - - name: Setup node.js - uses: actions/setup-node@v3 - with: - registry-url: 'https://npm.pkg.github.com' - - name: Install - run: npm ci - env: - NODE_AUTH_TOKEN: ${{ secrets.READER_TOKEN }} - - name: Server install - working-directory: ./server - run: npm ci - env: - NODE_AUTH_TOKEN: ${{ secrets.READER_TOKEN }} - - name: Typescript - run: npm run ts - - name: Prettier - run: npm run prettier - - name: Kjør tester - run: npm run test - - name: Build - run: npm run build - - name: Server build - working-directory: ./server - run: npm run build - - name: Sentry release - run: npm run release - - name: Fjerne source maps - run: | - rm dist/client/assets/*.map - - name: Bygg, tag og push Docker-image - run: | - echo ${GITHUB_TOKEN} | docker login ghcr.io -u ${GITHUB_REPOSITORY} --password-stdin - docker build --tag ${IMAGE} . - docker push ${IMAGE} - - deploy-prod-gcp-intern: - name: Deploy til prod-gcp intern - runs-on: ubuntu-20.04 - needs: bygg - steps: - - name: Sjekk ut kode - uses: actions/checkout@v3 - - name: Deploy til prod-gcp intern - uses: nais/deploy/actions/deploy@v1 - env: - APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} - CLUSTER: prod-gcp - RESOURCE: nais/nais-gcp-intern.yaml - PRINT_PAYLOAD: true - VARS: nais/prod-gcp-intern.yaml - - deploy-prod-gcp-ekstern: - name: Deploy til prod-gcp ekstern - runs-on: ubuntu-20.04 - needs: bygg - steps: - - name: Sjekk ut kode - uses: actions/checkout@v3 - - name: Deploy til prod-gcp ekstern - uses: nais/deploy/actions/deploy@v1 - env: - APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} - CLUSTER: prod-gcp - RESOURCE: nais/nais-gcp-ekstern.yaml - PRINT_PAYLOAD: true - VARS: nais/prod-gcp-ekstern.yaml - - deploy-dev-gcp-intern: - name: Deploy til dev-gcp intern - runs-on: ubuntu-20.04 - needs: bygg - steps: - - name: Sjekk ut kode - uses: actions/checkout@v3 - - name: Deploy til dev-gcp intern - uses: nais/deploy/actions/deploy@v1 - env: - APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} - CLUSTER: dev-gcp - RESOURCE: nais/nais-gcp-intern.yaml - PRINT_PAYLOAD: true - VARS: nais/dev-gcp-intern.yaml - - deploy-dev-gcp-ekstern: - name: Deploy til dev-gcp ekstern - runs-on: ubuntu-20.04 - needs: bygg - steps: - - name: Sjekk ut kode - uses: actions/checkout@v3 - - name: Deploy til dev-gcp ekstern - uses: nais/deploy/actions/deploy@v1 - env: - APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} - CLUSTER: dev-gcp - RESOURCE: nais/nais-gcp-ekstern.yaml - PRINT_PAYLOAD: true - VARS: nais/dev-gcp-ekstern.yaml - - deploy-dev-gcp-labs: - name: Deploy til dev-gcp (labs) - runs-on: ubuntu-20.04 - needs: bygg - steps: - - name: Sjekk ut kode - uses: actions/checkout@v3 - - name: Deploy til dev-gcp - uses: nais/deploy/actions/deploy@v1 - env: - APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} - CLUSTER: dev-gcp - RESOURCE: nais/dev-gcp-labs.yaml - PRINT_PAYLOAD: true - VARS: nais/dev-gcp-labs.json + build: + name: Bygg + permissions: + contents: read + id-token: write + outputs: + image: ${{ steps.docker-build-push.outputs.image }} + runs-on: ubuntu-latest + steps: + - name: Sjekk ut kode + uses: actions/checkout@v4 + - name: Setup node.js + uses: actions/setup-node@v3 + with: + registry-url: 'https://npm.pkg.github.com' + - name: Install + run: npm ci + env: + NODE_AUTH_TOKEN: ${{ secrets.READER_TOKEN }} + - name: Server install + working-directory: ./server + run: npm ci + env: + NODE_AUTH_TOKEN: ${{ secrets.READER_TOKEN }} + - name: Typescript + run: npm run ts + - name: Prettier + run: npm run prettier + - name: Kjør tester + run: npm run test + - name: Build + run: npm run build + - name: Server build + working-directory: ./server + run: npm run build + - name: Sentry release + run: npm run release + - name: Fjerne source maps + run: | + rm dist/client/assets/*.map + - name: Push docker image to GAR + uses: nais/docker-build-push@v0 + id: docker-build-push + with: + team: arbeidsgiver + identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }} + project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }} + + deploy-prod-gcp-intern: + name: Deploy til prod-gcp intern + runs-on: ubuntu-latest + needs: build + permissions: + contents: read + id-token: write + steps: + - name: Sjekk ut kode + uses: actions/checkout@v4 + - name: Deploy til prod-gcp intern + uses: nais/deploy/actions/deploy@v2 + env: + CLUSTER: prod-gcp + RESOURCE: nais/nais-gcp-intern.yaml + VARS: nais/prod-gcp-intern.yaml + VAR: image=${{ needs.build.outputs.image }} + + deploy-prod-gcp-ekstern: + name: Deploy til prod-gcp ekstern + runs-on: ubuntu-latest + needs: build + permissions: + contents: read + id-token: write + steps: + - name: Sjekk ut kode + uses: actions/checkout@v4 + - name: Deploy til prod-gcp ekstern + uses: nais/deploy/actions/deploy@v2 + env: + CLUSTER: prod-gcp + RESOURCE: nais/nais-gcp-ekstern.yaml + VARS: nais/prod-gcp-ekstern.yaml + VAR: image=${{ needs.build.outputs.image }} + + deploy-dev-gcp-intern: + name: Deploy til dev-gcp intern + runs-on: ubuntu-latest + needs: build + permissions: + contents: read + id-token: write + steps: + - name: Sjekk ut kode + uses: actions/checkout@v4 + - name: Deploy til prod-gcp intern + uses: nais/deploy/actions/deploy@v2 + env: + CLUSTER: dev-gcp + RESOURCE: nais/nais-gcp-intern.yaml + VARS: nais/dev-gcp-intern.yaml + VAR: image=${{ needs.build.outputs.image }} + + deploy-dev-gcp-ekstern: + name: Deploy til dev-gcp ekstern + runs-on: ubuntu-latest + needs: build + permissions: + contents: read + id-token: write + steps: + - name: Sjekk ut kode + uses: actions/checkout@v4 + - name: Deploy til dev-gcp ekstern + uses: nais/deploy/actions/deploy@v2 + env: + CLUSTER: dev-gcp + RESOURCE: nais/nais-gcp-ekstern.yaml + VARS: nais/dev-gcp-ekstern.yaml + VAR: image=${{ needs.build.outputs.image }} + + deploy-dev-gcp-labs: + name: Deploy til dev-gcp (labs) + runs-on: ubuntu-latest + needs: build + permissions: + contents: read + id-token: write + steps: + - name: Sjekk ut kode + uses: actions/checkout@v4 + - name: Deploy til dev-gcp + uses: nais/deploy/actions/deploy@v2 + env: + CLUSTER: dev-gcp + RESOURCE: nais/dev-gcp-labs.yaml + VARS: nais/dev-gcp-labs.json + VAR: image=${{ needs.build.outputs.image }} diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml deleted file mode 100644 index eaa5069b0..000000000 --- a/.github/workflows/dispatch.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Slash command dispatch -on: - issue_comment: - types: [created] -jobs: - dispatcher: - runs-on: ubuntu-latest - steps: - - name: Slash command dispatch - uses: peter-evans/slash-command-dispatch@v1 - with: - reaction-token: ${{ secrets.GITHUB_TOKEN }} - token: ${{ secrets.NOTIFICATION }} - commands: deploy - issue-type: issue - allow_edits: true - reactions: false