Skip to content

Commit 7899af2

Browse files
committed
GAR and refactor of workflows.
1 parent 823bf4c commit 7899af2

File tree

5 files changed

+192
-164
lines changed

5 files changed

+192
-164
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: Manual deploy to dev
2+
3+
on:
4+
workflow_call:
5+
secrets:
6+
NAIS_DEPLOY_API_KEY:
7+
description: "API key for nais/deploy"
8+
required: true
9+
NAIS_WORKLOAD_IDENTITY_PROVIDER:
10+
description: "Identity provider for nais/docker-build-push"
11+
required: true
12+
workflow_dispatch:
13+
14+
run-name: Dev deploy of ${{ github.ref_name }}
15+
16+
jobs:
17+
build:
18+
name: Build
19+
permissions:
20+
contents: read
21+
id-token: write
22+
outputs:
23+
image: ${{ steps.docker-build-push.outputs.image }}
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v3
28+
29+
- name: Cache
30+
uses: actions/cache@v3
31+
with:
32+
path: ~/.gradle/caches
33+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts') }}
34+
restore-keys: |
35+
${{ runner.os }}-gradle-
36+
37+
- name: Install Java 17
38+
uses: actions/setup-java@v3
39+
with:
40+
java-version: 17
41+
distribution: temurin
42+
43+
- name: Test and build
44+
run: ./gradlew test bootJar
45+
env:
46+
ORG_GRADLE_PROJECT_githubUser: x-access-token
47+
ORG_GRADLE_PROJECT_githubPassword: ${{ secrets.GITHUB_TOKEN }}
48+
49+
- name: Build & push Docker image
50+
uses: nais/docker-build-push@v0
51+
id: docker-build-push
52+
with:
53+
team: klage # required
54+
tag: ${{ github.sha }} # optional
55+
push_image: true # optional, default true
56+
dockerfile: Dockerfile # optional, default Dockerfile
57+
docker_context: . # optional, default .
58+
image_suffix: # optional, default empty
59+
cache_from: type=gha # optional, default type=gha
60+
cache_to: type=gha,mode=max # optional, default type=gha,mode=max
61+
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }} # required, but is defined as an organization secret
62+
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }} # required, but is defined as an organization variable
63+
build_args: |
64+
VERSION=${CI}
65+
66+
- name: Post failures to Slack
67+
if: failure()
68+
run: |
69+
curl -X POST --data-urlencode "payload={\"channel\": \"$CHANNEL\", \"text\": \"$MESSAGE\", \"icon_emoji\": \":ghost:\"}" $WEBHOOK_URL
70+
env:
71+
MESSAGE: "Bygg feilet"
72+
CHANNEL: "#klage-notifications"
73+
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
74+
75+
deploy_to_dev:
76+
name: Deploy
77+
needs: build
78+
permissions:
79+
contents: read
80+
id-token: write
81+
runs-on: ubuntu-latest
82+
steps:
83+
- uses: actions/checkout@v3
84+
name: Checkout code
85+
86+
- name: Deploy to dev
87+
uses: nais/deploy/actions/deploy@v1
88+
env:
89+
TEAM: klage
90+
CLUSTER: dev-gcp
91+
VARS: deploy/dev.yaml
92+
RESOURCE: deploy/nais.yaml
93+
APIKEY: ${{ secrets.NAIS_DEPLOY_API_KEY }}
94+
VAR: image=${{ needs.build.outputs.image }}
95+
IMAGE: ${{ needs.build.outputs.image }}
96+
97+
- name: Post failures to Slack
98+
if: failure()
99+
run: |
100+
curl -X POST --data-urlencode "payload={\"channel\": \"$CHANNEL\", \"text\": \"$MESSAGE\", \"icon_emoji\": \":ghost:\"}" $WEBHOOK_URL
101+
env:
102+
MESSAGE: "Deploy til dev feilet"
103+
CHANNEL: "#klage-notifications"
104+
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Manual deploy to prod
2+
3+
on:
4+
workflow_call:
5+
secrets:
6+
NAIS_DEPLOY_API_KEY:
7+
description: "API key for nais/deploy"
8+
required: true
9+
NAIS_WORKLOAD_IDENTITY_PROVIDER:
10+
description: "Identity provider for nais/docker-build-push"
11+
required: true
12+
workflow_dispatch:
13+
14+
run-name: Prod deploy of ${{ github.ref_name }}
15+
16+
jobs:
17+
deploy_to_prod:
18+
name: Deploy
19+
if: github.ref == 'refs/heads/main'
20+
permissions:
21+
contents: write
22+
id-token: write
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v3
26+
name: Checkout code
27+
28+
- name: Get image registry
29+
id: image-registry
30+
uses: nais/login@v0
31+
with:
32+
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
33+
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
34+
team: klage
35+
36+
- name: Generate image name
37+
id: image
38+
shell: bash
39+
run: echo "image=${{ steps.image-registry.outputs.registry }}/kabal-smart-editor-api:${{ github.sha }}" >> $GITHUB_OUTPUT
40+
41+
- name: Deploy to prod
42+
uses: nais/deploy/actions/deploy@v1
43+
env:
44+
TEAM: klage
45+
CLUSTER: prod-gcp
46+
VARS: deploy/prod.yaml
47+
RESOURCE: deploy/nais.yaml
48+
APIKEY: ${{ secrets.NAIS_DEPLOY_API_KEY }}
49+
VAR: image=${{ steps.image.outputs.image }}
50+
IMAGE: ${{ steps.image.outputs.image }}
51+
52+
- name: Generate release version
53+
id: version
54+
run: |
55+
TIME=$(TZ="Europe/Oslo" date +%Y.%m.%d-%H.%M)
56+
COMMIT=$(git rev-parse --short=7 HEAD)
57+
VERSION=$TIME-$COMMIT
58+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
59+
60+
- uses: ncipollo/release-action@main
61+
with:
62+
tag: ${{ steps.version.outputs.version }}
63+
64+
- name: Post failures to Slack
65+
if: failure()
66+
run: |
67+
curl -X POST --data-urlencode "payload={\"channel\": \"$CHANNEL\", \"text\": \"$MESSAGE\", \"icon_emoji\": \":ghost:\"}" $WEBHOOK_URL
68+
env:
69+
MESSAGE: "Deploy til prod feilet"
70+
CHANNEL: "#klage-notifications"
71+
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}

.github/workflows/main.yaml

Lines changed: 16 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,24 @@
1-
name: Main - Build, deploy to dev, deploy to prod
1+
name: Deploy (dev -> e2e -> prod)
2+
23
on:
3-
workflow_dispatch:
44
push:
55
branches:
66
- main
77
paths-ignore:
88
- '.github/dependabot.yml'
99

10-
env:
11-
IMAGE: ghcr.io/${{ github.repository }}/kabal-smart-editor-api:${{ github.sha }}
12-
1310
jobs:
14-
build:
15-
runs-on: ubuntu-latest
16-
steps:
17-
- name: Checkout
18-
uses: actions/checkout@main
19-
- name: Cache
20-
uses: actions/cache@main
21-
with:
22-
path: ~/.gradle/caches
23-
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts') }}
24-
restore-keys: |
25-
${{ runner.os }}-gradle-
26-
- name: Install Java 17
27-
uses: actions/setup-java@main
28-
with:
29-
java-version: 17
30-
distribution: temurin
31-
- name: test and build
32-
run: ./gradlew test bootJar
33-
env:
34-
ORG_GRADLE_PROJECT_githubUser: x-access-token
35-
ORG_GRADLE_PROJECT_githubPassword: ${{ secrets.GITHUB_TOKEN }}
36-
- name: Build docker image
37-
run: docker build -t $IMAGE .
38-
- name: Login to Github package registry
39-
run: docker login ghcr.io -u ${GITHUB_REPOSITORY} -p ${GITHUB_TOKEN}
40-
env:
41-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42-
- name: Push docker image
43-
run: docker push $IMAGE
44-
- name: Post failures to Slack
45-
if: failure()
46-
run: |
47-
curl -X POST --data-urlencode "payload={\"channel\": \"$CHANNEL\", \"text\": \"$MESSAGE\", \"icon_emoji\": \":ghost:\"}" $WEBHOOK_URL
48-
env:
49-
MESSAGE: "Bygg feilet"
50-
CHANNEL: "#klage-notifications"
51-
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
52-
deploytodev:
53-
name: Deploy to dev
54-
needs: build
55-
if: github.ref == 'refs/heads/main'
56-
runs-on: ubuntu-latest
57-
steps:
58-
- uses: actions/checkout@main
59-
name: Checkout code
60-
- uses: nais/deploy/actions/deploy@master
61-
env:
62-
APIKEY: ${{ secrets.NAIS_DEPLOY_API_KEY }}
63-
CLUSTER: dev-gcp
64-
RESOURCE: deploy/nais.yaml
65-
VARS: deploy/dev.yaml
66-
- name: Post failures to Slack
67-
if: failure()
68-
run: |
69-
curl -X POST --data-urlencode "payload={\"channel\": \"$CHANNEL\", \"text\": \"$MESSAGE\", \"icon_emoji\": \":ghost:\"}" $WEBHOOK_URL
70-
env:
71-
MESSAGE: "Deploy til dev feilet"
72-
CHANNEL: "#klage-notifications"
73-
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
74-
deploytoprod:
75-
name: Deploy to prod
76-
needs: deploytodev
77-
if: github.ref == 'refs/heads/main'
78-
runs-on: ubuntu-latest
79-
steps:
80-
- uses: actions/checkout@main
81-
name: Checkout code
82-
- uses: nais/deploy/actions/deploy@master
83-
env:
84-
APIKEY: ${{ secrets.NAIS_DEPLOY_API_KEY }}
85-
CLUSTER: prod-gcp
86-
RESOURCE: deploy/nais.yaml
87-
VARS: deploy/prod.yaml
88-
- name: Generate release version
89-
run: |
90-
TIME=$(TZ="Europe/Oslo" date +%Y.%m.%d-%H.%M)
91-
COMMIT=$(git rev-parse --short=7 HEAD)
92-
VERSION=$TIME-$COMMIT
93-
echo "VERSION=${VERSION}" >> $GITHUB_ENV
94-
- uses: ncipollo/release-action@main
95-
with:
96-
tag: ${{ env.VERSION }}
97-
- name: Post failures to Slack
98-
if: failure()
99-
run: |
100-
curl -X POST --data-urlencode "payload={\"channel\": \"$CHANNEL\", \"text\": \"$MESSAGE\", \"icon_emoji\": \":ghost:\"}" $WEBHOOK_URL
101-
env:
102-
MESSAGE: "Deploy til prod feilet"
103-
CHANNEL: "#klage-notifications"
104-
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
11+
deploy_to_dev:
12+
name: Dev
13+
uses: ./.github/workflows/deploy-to-dev.yaml
14+
secrets:
15+
NAIS_DEPLOY_API_KEY: ${{ secrets.NAIS_DEPLOY_API_KEY }}
16+
NAIS_WORKLOAD_IDENTITY_PROVIDER: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
17+
18+
deploy_to_prod:
19+
name: Prod
20+
needs: deploy_to_dev
21+
uses: ./.github/workflows/deploy-to-prod.yaml
22+
secrets:
23+
NAIS_DEPLOY_API_KEY: ${{ secrets.NAIS_DEPLOY_API_KEY }}
24+
NAIS_WORKLOAD_IDENTITY_PROVIDER: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}

.github/workflows/manual-to-dev.yaml

Lines changed: 0 additions & 67 deletions
This file was deleted.

.github/workflows/pull-requests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ jobs:
2424
ORG_GRADLE_PROJECT_githubUser: x-access-token
2525
ORG_GRADLE_PROJECT_githubPassword: ${{ secrets.GITHUB_TOKEN }}
2626
- name: build docker image
27-
run: docker build . --pull
27+
run: docker build . --pull

0 commit comments

Comments
 (0)