Skip to content
Open
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
67 changes: 67 additions & 0 deletions .github/workflows/go-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
on:
push:
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'
workflow_dispatch:

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

- 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 }}

- name: Test
run: |
./run-test.sh "ghcr.io/opsboost/iss-operator:latest"
117 changes: 117 additions & 0 deletions run-test.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"