-
Notifications
You must be signed in to change notification settings - Fork 5
149 lines (122 loc) · 4.37 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: alpha on gcp-k8s
on:
push:
branches:
- gcp-k8s
env:
DOCKER_USERNAME: ${{ github.actor }}
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
DOCKER_REGISTRY: ghcr.io # if you change this, change it in the .env file as well
REPO_NAME: ${{ github.event.repository.name }}
# KOSLI_CLI_VERSION: 2.10.10
# KOSLI_HOST: https://app.kosli.com
# KOSLI_ORG: <your-kosli-org>
# KOSLI_API_TOKEN: ${{ secrets.KOSLI_API_TOKEN }}
jobs:
setup:
name: Setup job variables
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.variables.outputs.image_tag }}
image_name: ${{ steps.variables.outputs.image_name }}
tagged_image_previous: ${{ steps.variables.outputs.tagged_image_previous }}
image_tar_filename: ${{ steps.variables.outputs.image_tar_filename }}
steps:
- uses: actions/[email protected]
- name: Set outputs
id: variables
run: |
export $(cat .env | grep -o '^[^#]*') # to get DOCKER_ORG_NAME
image_tag="${GITHUB_SHA:0:7}"
image_uri="${{ env.DOCKER_REGISTRY }}/${DOCKER_ORG_NAME}/${{ env.REPO_NAME }}-alpha"
image_name="${image_uri}:${image_tag}"
tagged_image_previous="${image_uri}:previous"
image_tar_filename="/tmp/${{ env.REPO_NAME }}-alpha:previous.tar"
echo "image_tag=${image_tag}" >> ${GITHUB_OUTPUT}
echo "image_name=${image_name}" >> ${GITHUB_OUTPUT}
echo "tagged_image_previous=${tagged_image_previous}" >> ${GITHUB_OUTPUT}
echo "image_tar_filename=${image_tar_filename}" >> ${GITHUB_OUTPUT}
build-image:
name: Build docker image, push it to registry, attest to Kosli
runs-on: ubuntu-latest
needs: [setup]
permissions:
id-token: write
contents: read
packages: write
# outputs:
# artifact_digest: ${{ steps.variables.outputs.artifact_digest }}
steps:
- uses: actions/[email protected]
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_PASSWORD }}
- name: Build and push Docker image to the GHCR
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ needs.setup.outputs.image_name }},${{ needs.setup.outputs.tagged_image_previous }}
cache-from: type=registry,ref=${{ needs.setup.outputs.tagged_image_previous }}
cache-to: type=inline,mode=max
- name: Tar Docker image
run: |
docker pull ${{ needs.setup.outputs.image_name }}
docker image save ${{ needs.setup.outputs.image_name }} --output ${{ needs.setup.outputs.image_tar_filename }}
- name: Cache Docker image
uses: actions/[email protected]
with:
path: ${{ needs.setup.outputs.image_tar_filename }}
key: ${{ needs.setup.outputs.image_name }}
# - name: Make the image digest available to following jobs
# id: variables
# run: |
# DIGEST=$(echo ${{ steps.docker_build.outputs.digest }} | sed 's/.*://')
# echo "artifact_digest=${DIGEST}" >> ${GITHUB_OUTPUT}
lint:
name: Run rubocop linter and attest to Kosli
needs: [build-image]
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Run Rubocop linter on source
run:
make lint
unit-test:
name: Run unit-tests and attest to Kosli
needs: [build-image]
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Run unit-tests
run:
make test
deploy:
runs-on: ubuntu-latest
needs: [setup, build-image, lint]
steps:
- uses: actions/[email protected]
- uses: azure/setup-kubectl@v3
- id: 'auth'
uses: 'google-github-actions/auth@v2'
with:
project_id: 'test-kubernetes-environment'
credentials_json: '${{ secrets.GCP_CREDENTIALS_JSON }}'
- id: 'get-credentials'
uses: 'google-github-actions/get-gke-credentials@v2'
with:
cluster_name: 'db-playground-2'
location: 'europe-west1-b'
- uses: Azure/k8s-deploy@v5
env:
IMAGE_NAME: ${{ needs.setup.outputs.image_name }}
with:
manifests: |
deployment/gke
images: '${{ env.IMAGE_NAME }}'