forked from apache/beam
-
Notifications
You must be signed in to change notification settings - Fork 1
187 lines (185 loc) · 9.58 KB
/
playground_deploy_examples.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Collect And Deploy Playground Examples
on:
pull_request:
types:
- closed
branches: ['master']
env:
BEAM_ROOT_DIR: ../../
BEAM_EXAMPLE_CATEGORIES: ../categories.yaml
BEAM_VERSION: 2.40.0
K8S_NAMESPACE: playground-backend
HELM_APP_NAME: playground-backend
jobs:
check_examples:
name: Check examples
runs-on: ubuntu-latest
outputs:
example_has_changed: ${{ steps.check_has_example.outputs.example_has_changed }}
steps:
- name: Check out the repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: '3.8'
- name: install deps
run: pip install -r requirements.txt
working-directory: playground/infrastructure
- shell: pwsh
name: get Difference
id: check_file_changed
run: |
$diff = git diff --name-only ${{ github.event.before }} ${{ github.event.after }}
echo "$diff"
Write-Host "::set-output name=example_diff::$diff"
- name: has Examples
run: |
output=$(python3 checker.py ${{ steps.check_file_changed.outputs.example_diff }})
echo "::set-output name=example_has_changed::$output"
id: check_has_example
working-directory: playground/infrastructure
- name: Print has_example
run: echo "${{ steps.check_has_example.outputs.example_has_changed }}"
deploy_examples:
name: Deploy examples
runs-on: ubuntu-latest
needs: [ check_examples ]
if: needs.check_examples.outputs.example_has_changed == 'True'
steps:
- name: Check out the repo
uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.8'
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '8'
- name: Install kubectl
run: |
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" &&\
chmod +x kubectl &&\
mv kubectl /usr/local/bin/
- name: Install helm
run: |
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 &&\
chmod 700 get_helm.sh &&\
./get_helm.sh
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0
- name: install deps
run: pip install -r requirements.txt
working-directory: playground/infrastructure
- name: Remove default github maven configuration
# This step is a workaround to avoid a decryption issue
run: rm ~/.m2/settings.xml
- name: Setup GCP account
run: |
echo "${{ secrets.GCP_PLAYGROUND_SA_KEY }}" | base64 -d > /tmp/gcp_access.json
which gcloud
gcloud auth activate-service-account --project=${{ secrets.GCP_PLAYGROUND_PROJECT_ID }} --key-file=/tmp/gcp_access.json
- name: Set Docker Tag
run: echo "DOCKERTAG=${GITHUB_SHA}" >> $GITHUB_ENV
- name: Set Docker Tag If Github Tag was trigger
run: echo "DOCKERTAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
if: startsWith(github.ref, 'refs/tags/')
- name: Get K8s Config
run: gcloud container clusters get-credentials --region us-central1-a playground-examples
- name: Login to Docker Registry
run: cat /tmp/gcp_access.json | docker login -u _json_key --password-stdin https://${{ secrets.PLAYGROUND_REGISTRY_NAME }}
- name: Build And Push Java Backend
run: |
./gradlew playground:backend:containers:java:dockerTagPush -Pdocker-repository-root='${{ secrets.PLAYGROUND_REGISTRY_NAME}}/${{ secrets.GCP_PLAYGROUND_PROJECT_ID }}/playground-repository' -Pbase-image='apache/beam_java8_sdk:${{ env.BEAM_VERSION }}' -Pdocker-tag=${{ env.DOCKERTAG }}
- name: Build And Push Go Backend
run: ./gradlew playground:backend:containers:go:dockerTagPush -Pdocker-repository-root='${{ secrets.PLAYGROUND_REGISTRY_NAME}}/${{ secrets.GCP_PLAYGROUND_PROJECT_ID }}/playground-repository' -Pdocker-tag=${{ env.DOCKERTAG }}
- name: Build And Push Python Backend
run: ./gradlew playground:backend:containers:python:dockerTagPush -Pdocker-repository-root='${{ secrets.PLAYGROUND_REGISTRY_NAME}}/${{ secrets.GCP_PLAYGROUND_PROJECT_ID }}/playground-repository' -Pdocker-tag=${{ env.DOCKERTAG }}
- name: Clean All Build directories
run: ./gradlew clean
- name: Install helm chart
run: |
kubectl create namespace $K8S_NAMESPACE --dry-run=client -o yaml | kubectl apply -f - &&\
helm install --namespace $K8S_NAMESPACE $HELM_APP_NAME . --set global.registry="${{ secrets.PLAYGROUND_REGISTRY_NAME }}/${{ secrets.GCP_PLAYGROUND_PROJECT_ID }}/playground-repository" --set global.tag=${{ env.DOCKERTAG }} &&\
sleep 120
working-directory: playground/infrastructure/helm
- name: Run Python Examples CI
run: |
K8S_SERVER_ADDRESS=$(kubectl get svc -n $K8S_NAMESPACE -l "app=service-python" -o jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}')
BEAM_ROOT_DIR="../../"
BEAM_EXAMPLE_CATEGORIES="../../playground/categories.yaml"
echo $K8S_SERVER_ADDRESS
export SERVER_ADDRESS="$K8S_SERVER_ADDRESS:8081" && python3 ci_cd.py --step CI --sdk SDK_PYTHON
working-directory: playground/infrastructure
- name: Run Python Examples CD
run: |
K8S_SERVER_ADDRESS=$(kubectl get svc -n $K8S_NAMESPACE -l "app=service-python" -o jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}')
BEAM_ROOT_DIR="../../"
BEAM_EXAMPLE_CATEGORIES="../../playground/categories.yaml"
GOOGLE_CLOUD_PROJECT_VALUE=${{ secrets.GCP_PLAYGROUND_PROJECT_ID }}
SDK_CONFIG_VALUE="../../playground/sdks.yaml"
export SDK_CONFIG="$SDK_CONFIG_VALUE"
export GOOGLE_CLOUD_PROJECT="$GOOGLE_CLOUD_PROJECT_VALUE"
export SERVER_ADDRESS="$K8S_SERVER_ADDRESS:8081" && python3 ci_cd.py --step CD --sdk SDK_PYTHON
working-directory: playground/infrastructure
env:
GOOGLE_APPLICATION_CREDENTIALS: /tmp/gcp_access.json
- name: Run Go Examples CI
run: |
K8S_SERVER_ADDRESS=$(kubectl get svc -n $K8S_NAMESPACE -l "app=service-go" -o jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}')
BEAM_ROOT_DIR="../../"
BEAM_EXAMPLE_CATEGORIES="../../playground/categories.yaml"
export SERVER_ADDRESS="$K8S_SERVER_ADDRESS:8082" && python3 ci_cd.py --step CI --sdk SDK_GO
working-directory: playground/infrastructure
- name: Run Go Examples CD
run: |
K8S_SERVER_ADDRESS=$(kubectl get svc -n $K8S_NAMESPACE -l "app=service-go" -o jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}')
BEAM_ROOT_DIR="../../"
BEAM_EXAMPLE_CATEGORIES="../../playground/categories.yaml"
GOOGLE_CLOUD_PROJECT_VALUE=${{ secrets.GCP_PLAYGROUND_PROJECT_ID }}
SDK_CONFIG_VALUE="../../playground/sdks.yaml"
export SDK_CONFIG="$SDK_CONFIG_VALUE"
export GOOGLE_CLOUD_PROJECT="$GOOGLE_CLOUD_PROJECT_VALUE"
export SERVER_ADDRESS="$K8S_SERVER_ADDRESS:8082" && python3 ci_cd.py --step CD --sdk SDK_GO
working-directory: playground/infrastructure
env:
GOOGLE_APPLICATION_CREDENTIALS: /tmp/gcp_access.json
- name: Run Java Examples CI
run: |
K8S_SERVER_ADDRESS=$(kubectl get svc -n $K8S_NAMESPACE -l "app=service-java" -o jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}')
BEAM_ROOT_DIR="../../"
BEAM_EXAMPLE_CATEGORIES="../../playground/categories.yaml"
export SERVER_ADDRESS="$K8S_SERVER_ADDRESS:8080" && python3 ci_cd.py --step CI --sdk SDK_JAVA
working-directory: playground/infrastructure
- name: Run Java Examples CD
run: |
K8S_SERVER_ADDRESS=$(kubectl get svc -n $K8S_NAMESPACE -l "app=service-java" -o jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}')
BEAM_ROOT_DIR="../../"
BEAM_EXAMPLE_CATEGORIES="../../playground/categories.yaml"
GOOGLE_CLOUD_PROJECT_VALUE=${{ secrets.GCP_PLAYGROUND_PROJECT_ID }}
SDK_CONFIG_VALUE="../../playground/sdks.yaml"
export SDK_CONFIG="$SDK_CONFIG_VALUE"
export GOOGLE_CLOUD_PROJECT="$GOOGLE_CLOUD_PROJECT_VALUE"
export SERVER_ADDRESS="$K8S_SERVER_ADDRESS:8080" && python3 ci_cd.py --step CD --sdk SDK_JAVA
working-directory: playground/infrastructure
env:
GOOGLE_APPLICATION_CREDENTIALS: /tmp/gcp_access.json
- name: Delete Helm Chart
if: always()
run: |
helm del --namespace $K8S_NAMESPACE $HELM_APP_NAME