From ccff406cdcd3e043b432fe99b4038d1b4699c702 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Fri, 21 Feb 2020 15:26:03 -0800 Subject: [PATCH] GitHub Actions smoke tests (#288) - added ci smoke tests to repo --- .github/workflows/README.md | 62 +++++++++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 53 +++++++++++++++++++++++++++++++ .travis.yml | 12 ------- skaffold.yaml | 6 ---- 4 files changed, 115 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/README.md create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/README.md b/.github/workflows/README.md new file mode 100644 index 0000000..43af343 --- /dev/null +++ b/.github/workflows/README.md @@ -0,0 +1,62 @@ +# GitHub Actions Workflows + +## Setup +- workloads run using [GitHub self-hosted runners](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/about-self-hosted-runners) +- project admins maintain a private Google Compute Engine VM for running tests + - VM should be at least n1-standard-4 with 50GB persistent disk + - instructions for setting up the VM can be found in repo settings under "Actions" + - ⚠️ WARNING: VM should be set up with no GCP service account + - external contributors could contribute malicious PRs to run code on our test VM. Ensure no service accounts or other secrets exist on the VM + - An empty GCP project should be used for extra security + - to set up dependencies, run the following commands: + ``` + # install kubectl + sudo apt-get install kubectl + + # install kind + curl -Lo ./kind "https://github.com/kubernetes-sigs/kind/releases/download/v0.7.0/kind-$(uname)-amd64" && \ + chmod +x ./kind && \ + sudo mv ./kind /usr/local/bin + + # install skaffold + curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64 && \ + chmod +x skaffold && \ + sudo mv skaffold /usr/local/bin + + # install docker + sudo apt install apt-transport-https ca-certificates curl gnupg2 software-properties-common && \ + curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - && \ + sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" && \ + sudo apt update && \ + sudo apt install docker-ce && \ + sudo usermod -aG docker ${USER} + + # logout and back on + exit + ``` + - ensure GitHub Actions runs as background service: + ``` + sudo ∼/actions-runner/svc.sh install + sudo ∼/actions-runner/svc.sh start + ``` + + +--- +## Workflows + +### ci.yaml + +#### Triggers +- commits pushed to master +- PRs to master +- PRs to release/ branches + +#### Actions +- ensures kind cluster is running +- builds all containers in src/ +- deploys local containers to kind + - ensures all pods reach ready state + - ensures HTTP request to frontend returns HTTP status 200 +- deploys manifests from /releases + - ensures all pods reach ready state + - ensures HTTP request to frontend returns HTTP status 200 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2661a8f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,53 @@ +name: "Continuous Integration" +on: + push: + # run on pushes to master or release/* + branches: + - master + - release/* + pull_request: + # run on pull requests targeting master + branches: + - master +jobs: + run-tests: + runs-on: self-hosted + steps: + - uses: actions/checkout@v2 + - name: Setup Cluster + run: | + set -x + kind delete cluster || true + kind create cluster + kubectl get nodes + - name: Deploy From Source + run: | + skaffold run + - name: Wait For Pods + timeout-minutes: 20 + run: | + set -x + kubectl wait --for=condition=available --timeout=500s deployment/adservice + kubectl wait --for=condition=available --timeout=500s deployment/cartservice + kubectl wait --for=condition=available --timeout=500s deployment/checkoutservice + kubectl wait --for=condition=available --timeout=500s deployment/currencyservice + kubectl wait --for=condition=available --timeout=500s deployment/emailservice + kubectl wait --for=condition=available --timeout=500s deployment/frontend + kubectl wait --for=condition=available --timeout=500s deployment/loadgenerator + kubectl wait --for=condition=available --timeout=500s deployment/paymentservice + kubectl wait --for=condition=available --timeout=500s deployment/productcatalogservice + kubectl wait --for=condition=available --timeout=500s deployment/recommendationservice + kubectl wait --for=condition=available --timeout=500s deployment/shippingservice + - name: Smoke Test + timeout-minutes: 5 + run: | + set -x + RESULT=" " + while [[ "$RESULT" != " HTTP/1.1 200 OK" ]]; do + sleep 1 + RESULT=$(kubectl exec deployments/frontend -- sh -c "wget --spider -S "http://frontend" 2>&1 | grep 'HTTP/'") + echo "front end response: $RESULT" + done + if [[ "$RESULT" != " HTTP/1.1 200 OK" ]]; then + exit 1 + fi diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 124f5dd..0000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -sudo: required - -services: -- docker - -install: -- curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/v0.20.0/skaffold-linux-amd64 -- chmod +x skaffold -- sudo mv skaffold /usr/local/bin - -script: -- skaffold build --profile travis-ci diff --git a/skaffold.yaml b/skaffold.yaml index 665f80a..dfd6aeb 100644 --- a/skaffold.yaml +++ b/skaffold.yaml @@ -49,12 +49,6 @@ deploy: manifests: - ./kubernetes-manifests/**.yaml profiles: -# "travis-ci" profile is used to build the images without -# pushing them. -- name: travis-ci - build: - local: - push: false # "gcb" profile allows building and pushing the images # on Google Container Builder without requiring docker # installed on the developer machine. However, note that