Skip to content

Commit

Permalink
Refaktorer resten av github workflows til å gjenbruke workflows/actions
Browse files Browse the repository at this point in the history
  • Loading branch information
hestad committed Sep 5, 2023
1 parent 0300c6f commit 4f307aa
Show file tree
Hide file tree
Showing 16 changed files with 251 additions and 244 deletions.
8 changes: 7 additions & 1 deletion .github/actions/build-and-test/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: 'Build and test'
description: 'Checkout, download java and assemble and test'

inputs:
gradle-arguments:
required: false
description: 'Gradle arguments to pass to gradle build'
default: build
runs:
using: "composite"
steps:
Expand All @@ -9,4 +15,4 @@ runs:
uses: gradle/[email protected]
with:
gradle-version: wrapper
arguments: build
arguments: ${{ inputs.gradle-arguments }}
27 changes: 18 additions & 9 deletions .github/actions/deploy/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@ name: 'Deploy'
description: 'Deploy'

inputs:
nav-environment:
required: true
description: 'dev or prod'
NAIS_DEPLOY_APIKEY:
required: true
description: 'secrets.NAIS_DEPLOY_APIKEY'
image:
cluster:
required: true
description: 'full image url'
description: 'dev-fss/prod-fss'
var:
required: false
description: 'Optional, default empty, format: key1=value1,key2=value2'
default: ''
resource:
required: false
description: 'path to nais.yml'
default: 'nais.yml'
vars:
required: false
description: 'Optional, default empty, path to nais-dev.json/nais-prod.json'
default: ''

runs:
using: "composite"
Expand All @@ -20,7 +29,7 @@ runs:
- uses: nais/deploy/actions/deploy@v1
env:
APIKEY: ${{ inputs.NAIS_DEPLOY_APIKEY }}
CLUSTER: ${{ inputs.nav-environment }}-fss
RESOURCE: nais.yml
VARS: nais-${{ inputs.nav-environment }}.json
VAR: image=${{ inputs.image }}
CLUSTER: ${{ inputs.cluster }}
RESOURCE: ${{ inputs.resource }}
VARS: ${{ inputs.vars }}
VAR: ${{ inputs.var }}
11 changes: 11 additions & 0 deletions .github/actions/push-image/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ inputs:
tag:
required: true
description: 'github.sha'
dockerfile:
required: false
description: 'Optional dockerfile path, default: Dockerfile
default: 'Dockerfile'
image_suffix:
required: false
description: 'Optional, default empty'
default: ''
outputs:
image:
description: "Docker image in GAR"
Expand All @@ -26,3 +34,6 @@ runs:
tag: ${{ inputs.tag }}
identity_provider: ${{ inputs.identity_provider }}
project_id: ${{ inputs.project_id }}
dockerfile: ${{ inputs.dockerfile }}
image_suffix: ${{ inputs.image_suffix }}

41 changes: 21 additions & 20 deletions .github/workflows/alerts-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@ on:
paths:
- 'alerts.yml'
- '.github/workflows/alerts-deploy.yml'

permissions: { }

jobs:
apply-alerts:
name: Apply alerts to cluster
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: deploy to dev
uses: nais/deploy/actions/deploy@v1
env:
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
CLUSTER: dev-fss
RESOURCE: alerts.yml
VAR: SLACK_ALERTS_CHANNEL=#su_alerts_dev,LOGS_URL=https://logs.adeo.no/goto/10065d0eff34c88407beb46993e0d729
- name: deploy to prod
uses: nais/deploy/actions/deploy@v1
env:
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
CLUSTER: prod-fss
RESOURCE: alerts.yml
VAR: SLACK_ALERTS_CHANNEL=#su_alerts,LOGS_URL=https://logs.adeo.no/goto/6af62b00d098b7ef2d7cb769c53379b5
deploy_to_dev:
name: Deploy to dev
uses: navikt/su-se-bakover/.github/workflows/reusable-deploy.yml@master
with:
var: SLACK_ALERTS_CHANNEL=#su_alerts_dev,LOGS_URL=https://logs.adeo.no/goto/10065d0eff34c88407beb46993e0d729
cluster: dev-fss
resource: alerts.yml
secrets:
NAIS_DEPLOY_APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
deploy_to_prod:
name: Deploy to prod
uses: navikt/su-se-bakover/.github/workflows/reusable-deploy.yml@master
with:
var: SLACK_ALERTS_CHANNEL=#su_alerts,LOGS_URL=https://logs.adeo.no/goto/6af62b00d098b7ef2d7cb769c53379b5
cluster: prod-fss
resource: alerts.yml
secrets:
NAIS_DEPLOY_APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
80 changes: 0 additions & 80 deletions .github/workflows/branch-deploy.yml

This file was deleted.

42 changes: 0 additions & 42 deletions .github/workflows/branch.yml

This file was deleted.

86 changes: 31 additions & 55 deletions .github/workflows/datapakker.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@

on:
push:
branches:
- master
paths:
- '.github/workflows/datapakker.yml'
- 'datapakker/**'
- 'common/**'

env:
IMAGE: ghcr.io/${{ github.repository }}/datapakker/soknad:${{ github.sha }}
permissions: {}

jobs:
build:
build-test-push-image:
name: Build and push Docker container
runs-on: ubuntu-latest
permissions:
Expand All @@ -20,62 +19,39 @@ jobs:
id-token: 'write'
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-v2-${{ hashFiles('gradle.properties', 'settings.gradle.kts', '**/build.gradle.kts', 'gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- uses: actions/setup-java@v3
with:
java-version: '19'
distribution: 'temurin'
- name: test and build
run: ./gradlew --no-build-cache :datapakker:soknad:build
env:
ORG_GRADLE_PROJECT_githubUser: x-access-token
ORG_GRADLE_PROJECT_githubPassword: ${{ secrets.GITHUB_TOKEN }}
- name: Login to DockerHub
uses: docker/[email protected]
- name: Build and test
uses: ./.github/actions/build-and-test
with:
registry: ghcr.io
username: ${{ github.repository }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and publish Docker image
uses: docker/[email protected]
gradle-arguments: :datapakker:soknad:build
- name: Push image
uses: ./.github/actions/push-image
with:
context: .
file: ./datapakker/soknad/Dockerfile
push: true
pull: true
tags: ${{env.IMAGE}}
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
tag: ${{ github.sha }}
dockerfile: ./datapakker/soknad/Dockerfile
image_suffix: 'datapakker-job'

deploy_to_dev:
name: Deploy to dev
needs: build
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: nais/deploy/actions/deploy@v1
env:
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
CLUSTER: dev-fss
RESOURCE: datapakker/soknad/nais.yml
VARS: datapakker/soknad/nais-dev.json
uses: navikt/su-se-bakover/.github/workflows/reusable-deploy.yml@master
needs: build-test-push-image
with:
tag: ${{ github.sha }}
cluster: dev-fss
vars: datapakker/soknad/nais-dev.json
resource: datapakker/soknad/nais.yml
secrets:
NAIS_DEPLOY_APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}

deploy_to_prod:
name: Deploy to prod
needs: build
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: nais/deploy/actions/deploy@v1
env:
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
CLUSTER: prod-fss
RESOURCE: datapakker/soknad/nais.yml
VARS: datapakker/soknad/nais-prod.json
uses: navikt/su-se-bakover/.github/workflows/reusable-deploy.yml@master
needs: build-test-push-image
with:
tag: ${{ github.sha }}
cluster: prod-fss
vars: datapakker/soknad/nais-prod.json
resource: datapakker/soknad/nais.yml
secrets:
NAIS_DEPLOY_APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
21 changes: 0 additions & 21 deletions .github/workflows/prod-deploy.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .github/workflows/reusable-codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: CodeQL
on:
workflow_call:

permissions: {}

jobs:
draft-release:
permissions:
Expand Down
Loading

0 comments on commit 4f307aa

Please sign in to comment.