From dfbf301c3bb2d993340bcc8adc316091b7a69528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Busse?= Date: Wed, 23 Nov 2022 10:00:45 +0100 Subject: [PATCH 1/3] gh-actions: Build and release --- .github/workflows/go-build.yaml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/go-build.yaml diff --git a/.github/workflows/go-build.yaml b/.github/workflows/go-build.yaml new file mode 100644 index 0000000..f9e6b3f --- /dev/null +++ b/.github/workflows/go-build.yaml @@ -0,0 +1,32 @@ +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Build + uses: actions/setup-go@v3 + with: + go-version: '1.19' + check-latest: true + - run: | + go build + ./infoscreen-operator --help + mv infoscreen-operator iss-operator-amd64 + + - name: Create archive + run: | + xz iss-operator-amd64 + + - name: Release + uses: "marvinpinto/action-automatic-releases@latest" + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + prerelease: false + automatic_release_tag: "latest" + files: | + iss-operator-amd64.xz From 819cf615f98eac3e726bd631901b00716596820a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Busse?= Date: Wed, 23 Nov 2022 10:53:11 +0100 Subject: [PATCH 2/3] gh-actions: Add container build --- .github/workflows/go-build.yaml | 74 ++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 25 deletions(-) diff --git a/.github/workflows/go-build.yaml b/.github/workflows/go-build.yaml index f9e6b3f..9430e6e 100644 --- a/.github/workflows/go-build.yaml +++ b/.github/workflows/go-build.yaml @@ -5,28 +5,52 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Build - uses: actions/setup-go@v3 - with: - go-version: '1.19' - check-latest: true - - run: | - go build - ./infoscreen-operator --help - mv infoscreen-operator iss-operator-amd64 - - - name: Create archive - run: | - xz iss-operator-amd64 - - - name: Release - uses: "marvinpinto/action-automatic-releases@latest" - with: - repo_token: "${{ secrets.GITHUB_TOKEN }}" - prerelease: false - automatic_release_tag: "latest" - files: | - iss-operator-amd64.xz + - name: Checkout + uses: actions/checkout@v3 + + - name: Build + uses: actions/setup-go@v3 + with: + go-version: '1.19' + check-latest: true + - run: | + go build + ./infoscreen-operator --help + mv infoscreen-operator iss-operator-amd64 + + - name: Create archive + run: | + xz iss-operator-amd64 + + - name: Release + uses: "marvinpinto/action-automatic-releases@latest" + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + prerelease: false + automatic_release_tag: "latest" + files: | + iss-operator-amd64.xz + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and push to ghcr + id: docker_build + uses: docker/build-push-action@v2 + with: + platforms: linux/amd64 + push: true + tags: ghcr.io/opsboost/iss-operator:latest + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} From 3e78df28ce4b353309ff6149531026a9389b0e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Busse?= Date: Wed, 23 Nov 2022 20:16:01 +0100 Subject: [PATCH 3/3] gh-actions: Add test with minikube deployment --- .github/workflows/go-build.yaml | 13 +++- run-test.sh | 117 ++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+), 1 deletion(-) create mode 100755 run-test.sh diff --git a/.github/workflows/go-build.yaml b/.github/workflows/go-build.yaml index 9430e6e..855ac90 100644 --- a/.github/workflows/go-build.yaml +++ b/.github/workflows/go-build.yaml @@ -1,4 +1,11 @@ -on: [push, pull_request] +on: + push: + paths-ignore: + - '**.md' + pull_request: + paths-ignore: + - '**.md' + workflow_dispatch: jobs: build: @@ -54,3 +61,7 @@ jobs: - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }} + + - name: Test + run: | + ./run-test.sh "ghcr.io/opsboost/iss-operator:latest" diff --git a/run-test.sh b/run-test.sh new file mode 100755 index 0000000..9260cf2 --- /dev/null +++ b/run-test.sh @@ -0,0 +1,117 @@ +#!/usr/bin/env bash + +[[ "$TRACE" ]] && set -x +set -eo pipefail + +INSTALL_MINIKUBE="1" +ARCH=amd64 + +pod_running() { + if [ "$(kubectl get pods -A | grep "${1}" | awk '{print $4}')" != "Running" ]; then + echo "1" + else + echo "0" + fi +} + +pod_name() { + local name + name=$(kubectl get pods -A | grep "${1}" | awk '{print $2}') + echo "$name" +} + +container_name() { + local arr + local name + arr=(${1//:/ }) + name=${arr[0]} + arr=(${name//\// }) + name=${arr[2]} + echo "$name" +} + +minikube_install() { + sudo apt install -y podman curl + curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-${ARCH} + curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/${ARCH}/kubectl.sha256" + curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/${ARCH}/kubectl" + echo "$(cat kubectl.sha256) kubectl" | sha256sum --check + sudo install minikube-linux-${ARCH} /usr/local/bin/minikube + sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl + kubectl version --client +} + +minikube_deinstall() { + minikube stop + minikube delete --all +} + +check_dependencies() { + for i in "${DEPS[@]}" + do + if [[ -z $(which "${i}") ]]; then + error "Could not find ${i}" + exit 1 + fi + done +} + +main() { + local image="${1}" + + # Get container name + local container + container=$(container_name "${image}") + + # Check for minikube + # Install if absent and installation enabled + if [[ -z $(which "minikube") ]]; then + printf "Could not find minikube" + if [ "$INSTALL_MINIKUBE" -eq "1" ]; then + minikube_install + fi + fi + + # Check for a running minikube + if minikube status | grep 'Running'; then + printf "minikube is already running.\n" + printf "To continue, stop minikube and restart script\n" + exit 1 + fi + + # Run minikube + minikube start --driver=podman --container-runtime=cri-o + + # Deploy + kubectl create deployment "${container}" --image="${image}" + + # Wait for container to come up + sleep 30 + kubectl get pods -A -o wide + + # Get pod name + local pod + pod=$(pod_name "${container}") + + # Show logs + kubectl logs "${pod}" + + local r + r=$(pod_running "${pod}") + + if [ "$r" -eq 0 ]; then + printf "Deployment successful\n" + else + printf "Deployment failed\n" + local fail=1 + fi + + # Cleanup + minikube_deinstall + + if [ "$fail" -eq "1" ]; then + exit 1 + fi +} + +main "$@"