Use provision and dispose GKE action
parent
3ee15170fd
commit
8b22f62754
|
|
@ -94,34 +94,43 @@ jobs:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
lfs: true
|
lfs: true
|
||||||
- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
|
- name: Provision K8s Cluster
|
||||||
|
id: provision
|
||||||
|
uses: frostebite/Provision-GKE-Cluster@1.0
|
||||||
with:
|
with:
|
||||||
version: '288.0.0'
|
GOOGLE_SERVICE_ACCOUNT_EMAIL: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_EMAIL }}
|
||||||
service_account_email: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_EMAIL }}
|
GOOGLE_SERVICE_ACCOUNT_KEY: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_KEY }}
|
||||||
service_account_key: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_KEY }}
|
project: ${{ env.GKE_PROJECT }}
|
||||||
- run: ./ApplyClusterAndAcquireLock.sh ${{ env.GKE_PROJECT }} ${{ env.GKE_CLUSTER }} ${{ env.GKE_ZONE }}
|
cluster: ${{ env.GKE_CLUSTER }}
|
||||||
- uses: frostebite/File-To-Base64@master
|
zone: ${{ env.GKE_ZONE }}
|
||||||
id: read-base64
|
|
||||||
with:
|
|
||||||
filePath: ~/.kube/config
|
|
||||||
- uses: ./
|
- uses: ./
|
||||||
id: k8s-unity-build
|
id: k8s-unity-build
|
||||||
env:
|
env:
|
||||||
UNITY_LICENSE: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root>\n <License id=\"Terms\">\n <MachineBindings>\n <Binding Key=\"1\" Value=\"33bf639e81e54693a8f9bf57c8900e5a\"/>\n <Binding Key=\"2\" Value=\"33bf639e81e54693a8f9bf57c8900e5a\"/>\n </MachineBindings>\n <MachineID Value=\"xWka2iXdDJejhZdi/zU2RUeXUi4=\"/>\n <SerialHash Value=\"1efd68fa935192b6090ac03c77d289a9f588c55a\"/>\n <Features>\n <Feature Value=\"33\"/>\n <Feature Value=\"1\"/>\n <Feature Value=\"12\"/>\n <Feature Value=\"2\"/>\n <Feature Value=\"24\"/>\n <Feature Value=\"3\"/>\n <Feature Value=\"36\"/>\n <Feature Value=\"17\"/>\n <Feature Value=\"19\"/>\n <Feature Value=\"62\"/>\n </Features>\n <DeveloperData Value=\"AQAAAEY0LUg2WFMtUE00NS1SM0M4LUUyWlotWkdWOA==\"/>\n <SerialMasked Value=\"F4-H6XS-PM45-R3C8-E2ZZ-XXXX\"/>\n <StartDate Value=\"2018-05-02T00:00:00\"/>\n <UpdateDate Value=\"2020-06-14T13:49:47\"/>\n <InitialActivationDate Value=\"2018-05-02T14:21:28\"/>\n <LicenseVersion Value=\"6.x\"/>\n <ClientProvidedVersion Value=\"2019.3.15f1\"/>\n <AlwaysOnline Value=\"false\"/>\n <Entitlements>\n <Entitlement Ns=\"unity_editor\" Tag=\"UnityPersonal\" Type=\"EDITOR\" ValidTo=\"9999-12-31T00:00:00\"/>\n </Entitlements>\n </License>\n<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><SignedInfo><CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments\"/><SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/><Reference URI=\"#Terms\"><Transforms><Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"/></Transforms><DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/><DigestValue>bpzWx3PZ0lqWDo1m9aLQuZ4cweo=</DigestValue></Reference></SignedInfo><SignatureValue>QcDm4/qAXZuUMQbUVk63vO6u66Bp8PnqqWQcZZOcym/rGUZLj1sr66EquF3X3w1L7aqiwMGtbY2b\nkPttcalFeaBkc5NsJMrexWjuBCxQvhbmVFQnTjvC6vNS+k1wrkz7If1oPkz/XaDtCfUs8oxc9iPe\nPzzUJIVYLZoDtpPq2XbgVn9/TiVb3Zu6ldKgvtNRYUjrB3KywtvL9OcIFll3htRcBZPG43kxryJc\nDD2TL5Nw1JuX6MejBBuYTZsZNpGX9Pjop9+uFUZ4GI9h8a5g6wJUfXzsGw7j4gkvDkC9MvyWiksi\n2hNXw1QNeB6JfQsd4sAuhYh/CqTm2gCz9i9ZpA==</SignatureValue></Signature></root>"
|
UNITY_LICENSE: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root>\n <License id=\"Terms\">\n <MachineBindings>\n <Binding Key=\"1\" Value=\"33bf639e81e54693a8f9bf57c8900e5a\"/>\n <Binding Key=\"2\" Value=\"33bf639e81e54693a8f9bf57c8900e5a\"/>\n </MachineBindings>\n <MachineID Value=\"xWka2iXdDJejhZdi/zU2RUeXUi4=\"/>\n <SerialHash Value=\"1efd68fa935192b6090ac03c77d289a9f588c55a\"/>\n <Features>\n <Feature Value=\"33\"/>\n <Feature Value=\"1\"/>\n <Feature Value=\"12\"/>\n <Feature Value=\"2\"/>\n <Feature Value=\"24\"/>\n <Feature Value=\"3\"/>\n <Feature Value=\"36\"/>\n <Feature Value=\"17\"/>\n <Feature Value=\"19\"/>\n <Feature Value=\"62\"/>\n </Features>\n <DeveloperData Value=\"AQAAAEY0LUg2WFMtUE00NS1SM0M4LUUyWlotWkdWOA==\"/>\n <SerialMasked Value=\"F4-H6XS-PM45-R3C8-E2ZZ-XXXX\"/>\n <StartDate Value=\"2018-05-02T00:00:00\"/>\n <UpdateDate Value=\"2020-06-14T13:49:47\"/>\n <InitialActivationDate Value=\"2018-05-02T14:21:28\"/>\n <LicenseVersion Value=\"6.x\"/>\n <ClientProvidedVersion Value=\"2019.3.15f1\"/>\n <AlwaysOnline Value=\"false\"/>\n <Entitlements>\n <Entitlement Ns=\"unity_editor\" Tag=\"UnityPersonal\" Type=\"EDITOR\" ValidTo=\"9999-12-31T00:00:00\"/>\n </Entitlements>\n </License>\n<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><SignedInfo><CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments\"/><SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/><Reference URI=\"#Terms\"><Transforms><Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"/></Transforms><DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/><DigestValue>bpzWx3PZ0lqWDo1m9aLQuZ4cweo=</DigestValue></Reference></SignedInfo><SignatureValue>QcDm4/qAXZuUMQbUVk63vO6u66Bp8PnqqWQcZZOcym/rGUZLj1sr66EquF3X3w1L7aqiwMGtbY2b\nkPttcalFeaBkc5NsJMrexWjuBCxQvhbmVFQnTjvC6vNS+k1wrkz7If1oPkz/XaDtCfUs8oxc9iPe\nPzzUJIVYLZoDtpPq2XbgVn9/TiVb3Zu6ldKgvtNRYUjrB3KywtvL9OcIFll3htRcBZPG43kxryJc\nDD2TL5Nw1JuX6MejBBuYTZsZNpGX9Pjop9+uFUZ4GI9h8a5g6wJUfXzsGw7j4gkvDkC9MvyWiksi\n2hNXw1QNeB6JfQsd4sAuhYh/CqTm2gCz9i9ZpA==</SignatureValue></Signature></root>"
|
||||||
with:
|
with:
|
||||||
targetPlatform: ${{ matrix.targetPlatform }}
|
targetPlatform: ${{ matrix.targetPlatform }}
|
||||||
kubeConfig: ${{ steps.read-base64.outputs.base64 }}
|
kubeConfig: ${{ steps.provision.outputs.kubeConfig }}
|
||||||
githubToken: ${{ secrets.GITHUB_TOKEN }}
|
githubToken: ${{ secrets.GITHUB_TOKEN }}
|
||||||
projectPath: test-project
|
projectPath: test-project
|
||||||
unityVersion: 2019.3.15f1
|
unityVersion: 2019.3.15f1
|
||||||
- uses: frostebite/K8s-Download-Volume@master
|
- uses: frostebite/K8s-Download-Volume@master
|
||||||
with:
|
with:
|
||||||
kubeConfig: ${{ steps.read-base64.outputs.base64 }}
|
kubeConfig: ${{ steps.provision.outputs.kubeConfig }}
|
||||||
volume: ${{ steps.k8s-unity-build.outputs.volume }}
|
volume: ${{ steps.k8s-unity-build.outputs.volume }}
|
||||||
sourcePath: repo/build/
|
sourcePath: repo/build/
|
||||||
- uses: actions/upload-artifact@v1
|
- uses: actions/upload-artifact@v1
|
||||||
with:
|
with:
|
||||||
name: Kubernetes Build (${{ matrix.targetPlatform }})
|
name: Kubernetes Build (${{ matrix.targetPlatform }})
|
||||||
path: k8s-volume-download
|
path: k8s-volume-download
|
||||||
- run: ./ReleaseLockAndAttemptShutdown.sh ${{ env.GKE_PROJECT }} ${{ env.GKE_CLUSTER }} ${{ env.GKE_ZONE }}
|
- name: Dispose K8s Cluster
|
||||||
if: ${{ always() }}
|
if: ${{ always() }}
|
||||||
|
id: dispose
|
||||||
|
uses: frostebite/Provision-GKE-Cluster@1.0
|
||||||
|
with:
|
||||||
|
GOOGLE_SERVICE_ACCOUNT_EMAIL: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_EMAIL }}
|
||||||
|
GOOGLE_SERVICE_ACCOUNT_KEY: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_KEY }}
|
||||||
|
project: ${{ env.GKE_PROJECT }}
|
||||||
|
cluster: ${{ env.GKE_CLUSTER }}
|
||||||
|
zone: ${{ env.GKE_ZONE }}
|
||||||
|
lock: ${{ steps.provision.outputs.lock }}
|
||||||
|
dispose: true
|
||||||
|
|
|
||||||
|
|
@ -1,69 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# This creates a GKE Cluster
|
|
||||||
# - Will wait for any deletion to complete on a cluster with the same name before creating
|
|
||||||
# - Will wait for completion before continuing
|
|
||||||
# - If the script is run concurrently multiple times, only one cluster will be created, all instances will wait for availability
|
|
||||||
# Requires GCP Cloud SDK
|
|
||||||
# Installs retry https://github.com/kadwanev/retry
|
|
||||||
|
|
||||||
GKE_PROJECT=$1
|
|
||||||
GKE_CLUSTER=$2
|
|
||||||
GKE_ZONE=$3
|
|
||||||
|
|
||||||
# may update this to avoid repeated install, drop me a comment if needed
|
|
||||||
sudo sh -c "curl https://raw.githubusercontent.com/kadwanev/retry/master/retry -o /usr/local/bin/retry && chmod +x /usr/local/bin/retry"
|
|
||||||
|
|
||||||
attempts=0
|
|
||||||
while [ $attempts -le 1 ]
|
|
||||||
do
|
|
||||||
retry -s 15 -t 20 -v '
|
|
||||||
STATUS=$(gcloud container clusters list --format="json" --project $GKE_PROJECT |
|
|
||||||
jq "
|
|
||||||
.[] |
|
|
||||||
{name: .name, status: .status} |
|
|
||||||
select(.name == \"$GKE_CLUSTER\")
|
|
||||||
" |
|
|
||||||
jq ".status")
|
|
||||||
if [ "$STATUS" == "\"STOPPING\"" ]; then echo "Cluster stopping waiting for completion" && exit 1; fi
|
|
||||||
exit 0
|
|
||||||
'
|
|
||||||
cluster=$(gcloud container clusters list --project $GKE_PROJECT --format="json" | jq '.[] | select(.name == "${GKE_CLUSTER}")')
|
|
||||||
|
|
||||||
if [ -z "$cluster" ];
|
|
||||||
then
|
|
||||||
echo "No clusters found for \"$GKE_CLUSTER\" in project \"$GKE_CLUSTER\" in zone \"$GKE_ZONE\""
|
|
||||||
# you may not need this, it installs GCP beta for additional command line options
|
|
||||||
gcloud components install beta -q
|
|
||||||
# replace this line with whatever type of cluster you want to create
|
|
||||||
gcloud beta container --project $GKE_PROJECT clusters create $GKE_CLUSTER --zone $GKE_ZONE --no-enable-basic-auth --cluster-version "1.15.12-gke.2" --machine-type "custom-1-3072" --image-type "COS" --disk-type "pd-standard" --disk-size "15" --metadata disable-legacy-endpoints=true --scopes "https://www.googleapis.com/auth/devstorage.read_only","https://www.googleapis.com/auth/logging.write","https://www.googleapis.com/auth/monitoring","https://www.googleapis.com/auth/servicecontrol","https://www.googleapis.com/auth/service.management.readonly","https://www.googleapis.com/auth/trace.append" --num-nodes "1" --enable-stackdriver-kubernetes --enable-ip-alias --default-max-pods-per-node "110" --enable-autoscaling --min-nodes "0" --max-nodes "3" --no-enable-master-authorized-networks --addons HorizontalPodAutoscaling,HttpLoadBalancing --enable-autoupgrade --enable-autorepair --max-surge-upgrade 1 --max-unavailable-upgrade 0
|
|
||||||
fi;
|
|
||||||
retry -s 15 -t 20 -v '
|
|
||||||
STATUS=$(gcloud container clusters list --format="json" --project $GKE_PROJECT |
|
|
||||||
jq "
|
|
||||||
.[] |
|
|
||||||
{name: .name, status: .status} |
|
|
||||||
select(.name == \"$GKE_CLUSTER\")
|
|
||||||
" |
|
|
||||||
jq ".status")
|
|
||||||
if [ "$STATUS" == "\"PROVISIONING\"" ]; then echo "Cluster provisioning waiting for available" && exit 1; fi
|
|
||||||
exit 0
|
|
||||||
'
|
|
||||||
echo "Cluster is available"
|
|
||||||
gcloud container clusters get-credentials $GKE_CLUSTER --zone $GKE_ZONE --project $GKE_PROJECT
|
|
||||||
kubectl version
|
|
||||||
NSID=$(cat /proc/sys/kernel/random/uuid)
|
|
||||||
echo "::set-env name=NSID::"$NSID
|
|
||||||
{
|
|
||||||
cat <<EOF | kubectl apply -f -
|
|
||||||
apiVersion: v1
|
|
||||||
kind: Namespace
|
|
||||||
metadata:
|
|
||||||
name: ns-unity-builder-$NSID
|
|
||||||
labels:
|
|
||||||
app: unity-builder
|
|
||||||
EOF
|
|
||||||
} && exit 0
|
|
||||||
|
|
||||||
attempts=$(($attempts+1))
|
|
||||||
done
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
kubectl delete ns ns-unity-builder-$NSID
|
|
||||||
|
|
||||||
# do any unity-builder namespaces remain?
|
|
||||||
namespaceCount=$(kubectl get ns --output json | jq ".items | .[] | select(.metadata.labels.app == \"unity-builder\") | select(.status.phase != \"TERMINATING\")" | jq -s "length")
|
|
||||||
echo $namespaceCount
|
|
||||||
if [ "$namespaceCount" != "0" ]
|
|
||||||
then
|
|
||||||
echo "let next cluster delete"
|
|
||||||
exit 0
|
|
||||||
else
|
|
||||||
echo "delete cluster"
|
|
||||||
gcloud container clusters delete $GKE_CLUSTER --zone $GKE_ZONE --project $GKE_PROJECT --quiet
|
|
||||||
fi
|
|
||||||
Loading…
Reference in New Issue