diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index cd15247e..0588384e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,20 +1,16 @@ -name: Build +name: Build PR on: pull_request: - types: [opened, synchronize, reopened, ready_for_review] workflow_dispatch: env: - IMAGE: ghcr.io/navikt/familie-tilbake-frontend:${{ github.sha }} VERSION: familie-tilbake-frontend:${{ github.sha }} jobs: build: - name: Build and push Docker container + name: Build runs-on: ubuntu-latest - permissions: - packages: write steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 @@ -22,20 +18,15 @@ jobs: node-version: '18' cache: yarn registry-url: "https://npm.pkg.github.com" - - name: Login to GitHub Container Registry - uses: docker/login-action@3d58c274f17dffee475a5520cbe67f0a882c4dbb - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and publish Docker image + - name: Yarn install env: NODE_AUTH_TOKEN: ${{ secrets.READER_TOKEN }} + run: yarn --prefer-offline --frozen-lockfile + - name: Build + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} SENTRY_RELEASE: ${{ github.sha }} run: | - yarn yarn build yarn test - docker build . -t ${IMAGE} - docker push ${IMAGE} diff --git a/.github/workflows/build_n_deploy_dev.yaml b/.github/workflows/build_n_deploy_dev.yaml index 88c99170..5b7db8c3 100644 --- a/.github/workflows/build_n_deploy_dev.yaml +++ b/.github/workflows/build_n_deploy_dev.yaml @@ -4,7 +4,6 @@ on: workflow_dispatch: env: - IMAGE: ghcr.io/navikt/familie-tilbake-frontend:${{ github.sha }} VERSION: familie-tilbake-frontend:${{ github.sha }} jobs: @@ -12,7 +11,10 @@ jobs: name: Build and push Docker container runs-on: ubuntu-latest permissions: - packages: write + contents: read + id-token: write + outputs: + image: ${{ steps.docker-build-push.outputs.image }} steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 @@ -20,34 +22,40 @@ jobs: node-version: '18' cache: yarn registry-url: "https://npm.pkg.github.com" - - name: Login to GitHub Container Registry - uses: docker/login-action@3d58c274f17dffee475a5520cbe67f0a882c4dbb - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and publish Docker image + - name: Yarn install env: NODE_AUTH_TOKEN: ${{ secrets.READER_TOKEN }} + run: yarn --prefer-offline --frozen-lockfile + + - name: Build + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} SENTRY_RELEASE: ${{ github.sha }} run: | - yarn yarn build yarn test - docker build . -t ${IMAGE} - docker push ${IMAGE} - deploy: - if: github.event.pull_request.draft == false && github.actor != 'dependabot[bot]' - name: Deploy to NAIS / GCP + + - name: Push docker image to GAR + uses: nais/docker-build-push@v0 + id: docker-build-push + with: + team: teamfamilie + identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }} # Provided as Organization Secret + project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }} # Provided as Organization Variable + + deployDev: + name: Deploy to gcp-dev needs: build runs-on: ubuntu-latest + permissions: + contents: read + id-token: write steps: - uses: actions/checkout@v4 - - name: Deploy til dev-gcp + - name: Deploy til dev-gcp team namespace uses: nais/deploy/actions/deploy@v2 env: - APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} CLUSTER: dev-gcp RESOURCE: build_n_deploy/naiserator/naiserator_dev_gcp.yaml - VAR: VERSION=${{ env.VERSION }} + VAR: image=${{ needs.build.outputs.image }},VERSION=${{ env.VERSION }} diff --git a/.github/workflows/build_n_deploy_prod.yaml b/.github/workflows/build_n_deploy_prod.yaml index d3f83724..12c5d664 100644 --- a/.github/workflows/build_n_deploy_prod.yaml +++ b/.github/workflows/build_n_deploy_prod.yaml @@ -1,14 +1,11 @@ -name: Build&deploy to prod +name: Build&deploy to dev and prod on: - workflow_dispatch: push: branches: - - main + - 'main' env: - IMAGE: ghcr.io/navikt/familie-tilbake-frontend:${{ github.sha }} - IMAGE_LATEST: ghcr.io/navikt/familie-tilbake-frontend:latest VERSION: familie-tilbake-frontend:${{ github.sha }} jobs: @@ -16,7 +13,10 @@ jobs: name: Build and push Docker container runs-on: ubuntu-latest permissions: - packages: write + contents: read + id-token: write + outputs: + image: ${{ steps.docker-build-push.outputs.image }} steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 @@ -24,41 +24,56 @@ jobs: node-version: '18' cache: yarn registry-url: "https://npm.pkg.github.com" - - name: Login to GitHub Container Registry - uses: docker/login-action@3d58c274f17dffee475a5520cbe67f0a882c4dbb - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and publish Docker image + - name: Yarn install env: NODE_AUTH_TOKEN: ${{ secrets.READER_TOKEN }} + run: yarn --prefer-offline --frozen-lockfile + + - name: Build + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} SENTRY_RELEASE: ${{ github.sha }} run: | - yarn yarn build yarn test - docker build . -t ${IMAGE} -t ${IMAGE_LATEST} - docker push ${IMAGE} - docker push ${IMAGE_LATEST} - deploy: - name: Deploy to NAIS / GCP + + - name: Push docker image to GAR + uses: nais/docker-build-push@v0 + id: docker-build-push + with: + team: teamfamilie + identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }} # Provided as Organization Secret + project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }} # Provided as Organization Variable + + deployDev: + name: Deploy to gcp-dev needs: build runs-on: ubuntu-latest + permissions: + contents: read + id-token: write steps: - uses: actions/checkout@v4 - - name: Deploy til dev-gcp + - name: Deploy til dev-gcp team namespace uses: nais/deploy/actions/deploy@v2 env: - APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} CLUSTER: dev-gcp - RESOURCE: build_n_deploy/naiserator/naiserator_dev_gcp.yaml - VAR: VERSION=${{ env.VERSION }} - - name: Deploy til prod-gcp + RESOURCE: build_n_deploy/naiserator/gcp-dev.yaml + VAR: image=${{ needs.build.outputs.image }},VERSION=${{ env.VERSION }} + + deployProd: + name: Deploy to gcp-prod + needs: build + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v4 + - name: Deploy til prod-gcp team namespace uses: nais/deploy/actions/deploy@v2 env: - APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} CLUSTER: prod-gcp RESOURCE: build_n_deploy/naiserator/naiserator_prod_gcp.yaml - VAR: VERSION=${{ env.VERSION }} + VAR: image=${{ needs.build.outputs.image }},VERSION=${{ env.VERSION }}