From a960ee0597cdb9c5ced5df0745b91bd33c42d297 Mon Sep 17 00:00:00 2001 From: "Giau. Tran Minh" Date: Sat, 8 Jul 2023 11:00:39 +0700 Subject: [PATCH] chore: move shell scripts to single file --- .github/workflows/integration.yml | 47 ++++------------------------- dev/integration.sh | 49 +++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 41 deletions(-) create mode 100755 dev/integration.sh diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 53c0ab0..e635841 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -58,6 +58,7 @@ jobs: go-version: '1.20' cache: true - uses: azure/setup-kubectl@v3 + - uses: medyagh/setup-minikube@master - uses: docker/login-action@v2 with: registry: ghcr.io @@ -70,48 +71,12 @@ jobs: with: name: collatz-binary path: ./examples/collatz - - uses: ASzc/change-string-case-action@v5 - id: repository - with: - string: ${{ github.repository }} - - name: Generate weaver.toml - uses: DamianReeves/write-file-action@master - with: - path: ./examples/collatz/weaver.toml - write-mode: overwrite - contents: | - [serviceweaver] - binary = "./collatz" - [kube] - image = "ghcr.io/${{ steps.repository.outputs.lowercase }}/example-collatz" - listeners.collatz = {public = true} - - name: Build and generate kube manifests - working-directory: ./examples/collatz - run: | - # Ensure the binary is executable - chmod +x ./collatz - # Build the docker image and push - weaver-kube deploy weaver.toml - - uses: medyagh/setup-minikube@master - id: minikube - - name: Deploy the application - working-directory: ./examples/collatz - run: | - kubectl apply -f ./kube_*.yaml - - name: Wait for deployment to be ready + - name: Run integration script working-directory: ./examples/collatz - run: | - kubectl wait --for=condition=Available=True --timeout=90s Deployment -l serviceweaver/app_name=collatz - - name: Call the collatz API - run: | - # Get the load balancer name - LOAD_BALANCER_NAME=$(kubectl get service \ - -l serviceweaver/app_name=collatz \ - -o=go-template \ - --template='{{- range .items -}}{{- if eq .spec.type "LoadBalancer" -}}{{ .metadata.name }}{{- end -}}{{- end -}}') - # Call the API and check the response - kubectl run -i --rm --restart=Never --image=busybox:latest test-api \ - --command wget -- -q -O - http://$LOAD_BALANCER_NAME/\?x\=10 + run: ../../dev/integration.sh + shell: bash + env: + IMAGE_NAME: ghcr.io/${{ github.repository }}/example-collatz - name: Display deployment logs if: failure() working-directory: ./examples/collatz diff --git a/dev/integration.sh b/dev/integration.sh new file mode 100755 index 0000000..a3c357c --- /dev/null +++ b/dev/integration.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# Copyright 2022 Google LLC +# +# Licensed 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. + +# Ensure image name is lowercase +IMAGE_NAME=$(echo $IMAGE_NAME | tr '[:upper:]' '[:lower:]') + +echo "Generate weaver.toml" +cat < ./weaver.toml +[serviceweaver] +binary = "./collatz" +[kube] +image = "$IMAGE_NAME" +listeners.collatz = {public = true} +EOT + +# Ensure the binary is executable +chmod +x ./collatz + +echo "Build the docker image and push" +weaver-kube deploy weaver.toml + +echo "Deploy the application" +kubectl apply -f ./kube_*.yaml + +echo "Wait for deployment to be ready" +kubectl wait --for=condition=Available=True --timeout=90s Deployment \ + -l serviceweaver/app_name=collatz + +# Get the load balancer name +LOAD_BALANCER_NAME=$(kubectl get service \ + -l serviceweaver/app_name=collatz \ + -o=go-template \ + --template='{{- range .items -}}{{- if eq .spec.type "LoadBalancer" -}}{{ .metadata.name }}{{- end -}}{{- end -}}') + +echo "Call the API and check the response" +kubectl run -i --rm --restart=Never --image=busybox:latest test-api \ + --command wget -- -q -O - http://$LOAD_BALANCER_NAME/\?x\=10