Visning av Sec. Champ på forside til komponent/system #617
Workflow file for this run
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: Build | |
on: | |
workflow_dispatch: | |
push: | |
branches: ['main'] | |
# Publish semver tags as releases. | |
tags: ['v*.*.*'] | |
paths-ignore: | |
- README.md | |
- CONTRIBUTING.md | |
- CODEOWNERS | |
- 'docs/**' | |
- 'terraform/**' | |
- '.gitignore' | |
- 'mkdocs.yml' | |
pull_request: | |
branches: ['main'] | |
paths-ignore: | |
- README.md | |
- CONTRIBUTING.md | |
- CODEOWNERS | |
- 'docs/**' | |
- 'terraform/**' | |
- '.gitignore' | |
- 'mkdocs.yml' | |
env: | |
# Use docker.io for Docker Hub if empty | |
REGISTRY: ghcr.io | |
# github.repository as <account>/<repo> | |
IMAGE_NAME: ${{ github.repository }} | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
# This is used to complete the identity challenge | |
# with sigstore/fulcio when running outside of PRs. | |
id-token: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.x | |
cache: 'npm' | |
- run: corepack enable | |
- run: yarn install --immutable | |
# tsc outputs type definitions to dist-types/ in the repo root, which are then consumed by the build | |
- run: yarn tsc | |
# Build the backend, which bundles it all up into the packages/backend/dist folder. | |
# The configuration files here should match the one you use inside the Dockerfile below. | |
- run: yarn build:backend --config ../../app-config.yaml --config ../../app-config.production.yaml | |
# Install the cosign tool except on PR | |
# https://github.com/sigstore/cosign-installer | |
- name: Install cosign | |
if: github.event_name != 'pull_request' | |
uses: sigstore/cosign-installer@v3.4.0 | |
with: | |
cosign-release: 'v2.2.3' | |
# Set up BuildKit Docker container builder to be able to build | |
# multi-platform images and export cache | |
# https://github.com/docker/setup-buildx-action | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 | |
# Login against a Docker registry except on PR | |
# https://github.com/docker/login-action | |
- name: Log into registry ${{ env.REGISTRY }} | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Extract metadata (tags, labels) for Docker | |
# https://github.com/docker/metadata-action | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
# Use sha for tags | |
type=sha,format=long | |
# set latest tag for default branch | |
type=raw,value=latest,enable={{is_default_branch}} | |
# Build and push Docker image with Buildx (don't push on PR) | |
# https://github.com/docker/build-push-action | |
- name: Build and push Docker image | |
id: build-and-push | |
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 | |
with: | |
context: . | |
file: packages/backend/Dockerfile | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
# Sign the resulting Docker image digest except on PRs. | |
# This will only write to the public Rekor transparency log when the Docker | |
# repository is public to avoid leaking data. If you would like to publish | |
# transparency data even for private images, pass --force to cosign below. | |
# https://github.com/sigstore/cosign | |
- name: Sign the published Docker image | |
if: ${{ github.event_name != 'pull_request' }} | |
env: | |
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable | |
TAGS: ${{ steps.meta.outputs.tags }} | |
DIGEST: ${{ steps.build-and-push.outputs.digest }} | |
# This step uses the identity token to provision an ephemeral certificate | |
# against the sigstore community Fulcio instance. | |
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} | |
outputs: | |
image_digest: ${{ steps.build-and-push.outputs.digest }} | |
dev-deploy-argo: | |
needs: build | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
environment: | |
name: dev | |
strategy: | |
matrix: | |
env: | |
- atgcp1-dev | |
permissions: | |
id-token: write | |
steps: | |
- uses: octo-sts/action@6177b4481c00308b3839969c3eca88c96a91775f # v1.0.0 | |
id: octo-sts | |
with: | |
scope: kartverket/skip-apps | |
identity: utviklerportal | |
- name: Checkout apps repo | |
uses: actions/checkout@v4 | |
with: | |
repository: kartverket/skip-apps | |
token: ${{ steps.octo-sts.outputs.token }} | |
- name: Deploy to ${{ matrix.env }} | |
run: | | |
kubectl patch --type=merge --local \ | |
-f ./env/${{ matrix.env }}/backstage/patches/application.yaml \ | |
-p '{"spec":{"image":"ghcr.io/kartverket/kartverket.dev@${{needs.build.outputs.image_digest}}"}}' \ | |
-o yaml > ./env/${{ matrix.env }}/backstage/patches/application.yaml.new | |
mv ./env/${{ matrix.env }}/backstage/patches/application.yaml.new ./env/${{ matrix.env }}/backstage/patches/application.yaml | |
git add ./env/${{ matrix.env }}/backstage/patches/application.yaml | |
git config --global user.email "noreply@kartverket.no" | |
git config --global user.name "GitHub Actions" | |
git commit -m "Deploy ${{ matrix.env }} version ${{github.ref_name}}" | |
git fetch origin | |
git rebase origin/main | |
git push | |
prod-deploy-argo: | |
needs: [build, dev-deploy-argo] | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
environment: | |
name: prod | |
strategy: | |
matrix: | |
env: | |
- atgcp1-prod | |
permissions: | |
id-token: write | |
steps: | |
- uses: octo-sts/action@6177b4481c00308b3839969c3eca88c96a91775f # v1.0.0 | |
id: octo-sts | |
with: | |
scope: kartverket/skip-apps | |
identity: utviklerportal | |
- name: Checkout apps repo | |
uses: actions/checkout@v4 | |
with: | |
repository: kartverket/skip-apps | |
token: ${{ steps.octo-sts.outputs.token }} | |
- name: Deploy to ${{ matrix.env }} | |
run: | | |
kubectl patch --type=merge --local \ | |
-f ./env/${{ matrix.env }}/backstage/patches/application.yaml \ | |
-p '{"spec":{"image":"ghcr.io/kartverket/kartverket.dev@${{needs.build.outputs.image_digest}}"}}' \ | |
-o yaml > ./env/${{ matrix.env }}/backstage/patches/application.yaml.new | |
mv ./env/${{ matrix.env }}/backstage/patches/application.yaml.new ./env/${{ matrix.env }}/backstage/patches/application.yaml | |
git add ./env/${{ matrix.env }}/backstage/patches/application.yaml | |
git config --global user.email "noreply@kartverket.no" | |
git config --global user.name "GitHub Actions" | |
git commit -m "Deploy ${{ matrix.env }} version ${{github.ref_name}}" | |
git fetch origin | |
git rebase origin/main | |
git push |