-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (82 loc) · 3.17 KB
/
deploy-store-consumer.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
name: Build and Deploy the Store Consumer to GKE
on:
workflow_dispatch:
push:
branches:
- 'main'
paths:
- 'store-consumer/**'
env:
PROJECT_ID: ${{ secrets.GKE_PROJECT }}
GAR_LOCATION: europe-west2
GKE_CLUSTER: cspr-events-store-cluster
GKE_ZONE: europe-west2
DEPLOYMENT_NAME: store-consumer
IMAGE: store-consumer
NAMESPACE: events
KUSTOMIZE_DIR: deploy
jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
defaults:
run:
working-directory: store-consumer
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Checkout
uses: actions/checkout@v3
# Setup gcloud CLI
- uses: google-github-actions/setup-gcloud@94337306dda8180d967a56932ceb4ddcf01edae7
with:
service_account_key: ${{ secrets.GKE_SA_KEY }}
project_id: ${{ secrets.GKE_PROJECT }}
# Configure Docker to use the gcloud command-line tool as a credential
# helper for authentication
- run: |-
gcloud --quiet auth configure-docker
# Get the GKE credentials so we can deploy to the cluster
- uses: google-github-actions/get-gke-credentials@fb08709ba27618c31c09e014e1d8364b02e5042e
with:
cluster_name: ${{ env.GKE_CLUSTER }}
location: ${{ env.GKE_ZONE }}
credentials: ${{ secrets.GKE_SA_KEY }}
# Build the Docker image
- name: Get Version
run: echo "GITHUB_APP_VERSION=$(../gradlew properties -q | grep -w 'version:' | awk '{print $2}')" >> $GITHUB_ENV
- name: Build Docker Image
run: |-
../gradlew clean build -x test
docker build \
--tag "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" \
--build-arg GITHUB_SHA="$GITHUB_SHA" \
--build-arg GITHUB_REF="$GITHUB_REF" \
--build-arg GITHUB_APP_VERSION="$GITHUB_APP_VERSION" \
--build-arg GITHUB_APP_NAME="$DEPLOYMENT_NAME" \
--build-arg CSPR_POSTGRES_PASSWORD=${{ secrets.CSPR_POSTGRES_PASSWORD }} \
.
# Push the Docker image to Google Container Registry
- name: Publish
run: |-
docker push "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA"
# Set up kustomize
- name: Set up Kustomize
run: |-
cd $KUSTOMIZE_DIR
curl -sfLo kustomize https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64
chmod u+x ./kustomize
# Deploy the Docker image to the GKE cluster
- name: Deploy
run: |-
cd $KUSTOMIZE_DIR
./kustomize edit set image LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE:TAG=gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA
./kustomize build . | kubectl apply -f -
kubectl rollout status deployment/$DEPLOYMENT_NAME -n $NAMESPACE
kubectl get services -o wide