Legg til felt for diverseInfo #491
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 and deploy | |
on: | |
push: | |
branches: | |
- main | |
- takhoyde | |
env: | |
IMAGE: ghcr.io/${{ github.repository }}:${{ github.sha }} | |
jobs: | |
build: | |
name: Build app, docker image and push docker image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Java 17 | |
uses: actions/setup-java@v1 | |
with: | |
java-version: '17.x' | |
- name: Cache gradle dependencies | |
uses: actions/cache@v1 | |
with: | |
path: ~/.gradle/caches | |
key: ${{ runner.os }}-gradle-${{ hashFiles('build.gradle.kts') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Format code with spotless | |
run: ./gradlew spotlessApply | |
- name: Build with Gradle | |
run: ./gradlew clean build --info | |
env: | |
TESTCONTAINERS_RYUK_DISABLED: true | |
- name: Docker login | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Docker build and push | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
push: true | |
tags: ${{ env.IMAGE }} | |
trivy-imagescan: | |
name: Scan dockerimage with Trivy | |
needs: build | |
if: github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Run Trivy vulnerability scanner on docker image | |
uses: aquasecurity/trivy-action@master | |
with: | |
image-ref: ${{ env.IMAGE }} | |
ignore-unfixed: true | |
format: 'sarif' | |
output: 'trivy-results.sarif' | |
- name: Upload Trivy scan results to GitHub Security tab | |
uses: github/codeql-action/upload-sarif@v2 | |
with: | |
sarif_file: 'trivy-results.sarif' | |
deploy-dev: | |
name: Deploy to dev | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: nais/deploy/actions/deploy@v1 | |
env: | |
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} | |
CLUSTER: dev-gcp | |
RESOURCE: nais/nais-dev.yaml,nais/alerts-dev.yaml | |
deploy-prod: | |
name: Deploy to Production | |
needs: [build, deploy-dev] | |
if: github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: nais/deploy/actions/deploy@v1 | |
env: | |
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} | |
CLUSTER: prod-gcp | |
RESOURCE: nais/nais-prod.yaml,nais/alerts-prod.yaml |