Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workflow: added Integration Tests #26

Merged
merged 5 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions .github/workflows/integration.yml
giautm marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Copyright 2023 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.

name: Integration Tests

on:
push:
branches:
- 'main'
pull_request:

jobs:
collatz:
name: Build collatz binary
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
name: Checkout collatz example
with:
repository: ServiceWeaver/weaver
ref: 'v0.15.0'
- uses: actions/setup-go@v4
with:
go-version: '1.20'
cache: true
- name: Build collatz example
working-directory: ./examples/collatz
run: |
# Disable CGO to ensure the binary is statically linked
CGO_ENABLED=0 \
go build -o collatz
- uses: actions/upload-artifact@v3
with:
name: collatz-binary
path: ./examples/collatz/collatz
deploy:
name: Deploy and run tests
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: collatz
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
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
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install weaver-kube
run: |
go install ./cmd/weaver-kube
- uses: actions/download-artifact@v3
with:
name: collatz-binary
path: ./examples/collatz
- name: Run integration script
working-directory: ./examples/collatz
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
run: |
kubectl get all && \
kubectl describe pod -l app_name=collatz && \
kubectl logs -l app_name=collatz
- uses: actions/upload-artifact@v3
if: always()
with:
name: collatz-kube-manifests
path: ./examples/collatz/kube_*.yaml
52 changes: 52 additions & 0 deletions dev/integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/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.

# Exit on command error
set -e

# Ensure image name is lowercase
IMAGE_NAME=$(echo $IMAGE_NAME | tr '[:upper:]' '[:lower:]')

echo "Generate weaver.toml"
cat <<EOT > ./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
Loading