CI #65
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SPDX-FileCopyrightText: The RamenDR authors | |
# SPDX-License-Identifier: Apache-2.0 | |
--- | |
# yamllint disable rule:line-length | |
name: CI | |
# This workflow will run when developer push a topic branch to their | |
# fork in github, minimizing noise for maintainers. This | |
# workflow also runs on nightly basis at 12:00 AM (00:00 UTC) | |
on: # yamllint disable-line rule:truthy | |
push: | |
pull_request: | |
schedule: | |
- cron: '0 0 * * *' | |
env: | |
# Values can be overriden by repository variables. | |
IMAGE_TAG_BASE: ${{ vars.IMAGE_TAG_BASE || 'quay.io/ramendr/ramen' }} | |
IMAGE_REPOSITORY: ${{ vars.IMAGE_REPOSITORY || 'ramendr' }} | |
IMAGE_NAME: ${{ vars.IMAGE_NAME || 'ramen' }} | |
OPERATOR_SUGGESTED_NAMESPACE: ${{ vars.OPERATOR_SUGGESTED_NAMESPACE || 'ramen-system' }} | |
# Constants | |
GO_VERSION: "1.19" | |
IMAGE_REGISTRY: "quay.io" | |
IMAGE_TAG: "ci" | |
DOCKERCMD: "podman" | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
lint: | |
name: Linters | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v2 | |
- name: Install prereqs | |
run: | | |
echo 'APT::Acquire::Retries "5";' | sudo tee /etc/apt/apt.conf.d/80-retries | |
sudo apt-get update | |
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y python3-pip ruby | |
sudo gem install mdl | |
sudo pip3 install yamllint | |
- name: Run linters | |
run: ./hack/pre-commit.sh | |
- name: Check that generated files were not modified | |
run: | | |
make generate | |
make manifests | |
go mod tidy | |
git --no-pager diff | |
git diff-index --quiet HEAD | |
golangci: | |
name: Golangci Lint | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v2 | |
- name: Setup go | |
uses: actions/setup-go@v2 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: GolangCI Lint | |
uses: golangci/golangci-lint-action@v3 | |
with: | |
version: v1.49.0 | |
unit-test: | |
name: Unit tests | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v2 | |
- name: Setup go | |
uses: actions/setup-go@v2 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: Run unit tests | |
run: GO_TEST_GINKGO_ARGS="" make test | |
drenv-test: | |
name: drenv tests | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v3 | |
- name: Setup python | |
uses: actions/setup-python@v4 | |
- name: Install minikube | |
run: | | |
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 | |
sudo install minikube-linux-amd64 /usr/local/bin/minikube | |
minikube version | |
mkdir "$HOME/.minikube/profiles" | |
- name: Install kubectl | |
run: | | |
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" | |
sudo install ./kubectl /usr/local/bin/ | |
kubectl version --client --output=yaml | |
- name: Install tools | |
run: pip install -r requirements.txt | |
- name: Enable coverage for child processes | |
run: cp coverage.pth $(python -m site --user-site) | |
- name: Install drenv | |
run: pip install -e test | |
- name: Run flake8 | |
run: make flake8 | |
working-directory: test | |
- name: Run pylint | |
run: make pylint | |
working-directory: test | |
- name: Run black | |
run: make black | |
working-directory: test | |
- name: Run tests | |
run: make test | |
working-directory: test | |
- name: Report test coverage | |
run: make coverage | |
working-directory: test | |
ramenctl-test: | |
name: ramenctl tests | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v3 | |
- name: Setup python | |
uses: actions/setup-python@v4 | |
- name: Install tools | |
run: pip install -r requirements.txt | |
- name: Install drenv | |
run: pip install -e test | |
- name: Run flake8 | |
run: make flake8 | |
working-directory: ramenctl | |
- name: Run pylint | |
run: make pylint | |
working-directory: ramenctl | |
- name: Run black | |
run: make black | |
working-directory: ramenctl | |
build-image-and-ensure-clean-branch: | |
name: Build image and ensure clean branch | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v2 | |
- name: Setup go | |
uses: actions/setup-go@v2 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: Build image | |
run: make docker-build | |
- name: Export image | |
run: ${{env.DOCKERCMD}} save -o /tmp/ramen-operator.tar ${IMAGE_TAG_BASE}-operator:${IMAGE_TAG} | |
- name: Save image artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: ramen-operator | |
path: /tmp/ramen-operator.tar | |
retention-days: 1 | |
- name: Go tidy | |
run: go mod tidy | |
deploy-check: | |
name: Check artifacts and operator deployment | |
needs: [build-image-and-ensure-clean-branch] | |
runs-on: ubuntu-20.04 | |
strategy: | |
fail-fast: false | |
matrix: | |
kubernetes_version: ["1.20.7"] | |
include: | |
- kubernetes_version: "1.20.7" | |
kind_image: "1.20.7@sha256:cbeaf907fc78ac97ce7b625e4bf0de16e3ea725daf6b04f930bd14c67c671ff9" | |
kind_version: "v0.11.1" | |
env: | |
KUBERNETES_VERSION: ${{ matrix.kubernetes_version }} | |
KIND_VERSION: ${{ matrix.kind_version }} | |
KIND_IMAGE: ${{ matrix.kind_image }} | |
KIND_CLUSTER_NAME: "ci" | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v2 | |
- name: Setup go | |
uses: actions/setup-go@v2 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: Install kubectl | |
run: | | |
curl -LO "https://storage.googleapis.com/kubernetes-release/release/v${KUBERNETES_VERSION}/bin/linux/amd64/kubectl" | |
sudo install ./kubectl /usr/local/bin/ | |
- name: Create Kind kubernetes cluster | |
run: ./hack/setup-kind-cluster.sh | |
- name: Download image artifact | |
uses: actions/download-artifact@v1 | |
with: | |
name: ramen-operator | |
path: /tmp | |
- name: Load image artifact | |
run: | | |
kind load image-archive /tmp/ramen-operator.tar --name ${KIND_CLUSTER_NAME} | |
- name: Install cert-manager | |
run: | | |
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.10.0/cert-manager.yaml | |
kubectl -n cert-manager wait --for=condition=Available --timeout=60s deploy/cert-manager | |
kubectl -n cert-manager wait --for=condition=Available --timeout=60s deploy/cert-manager-cainjector | |
kubectl -n cert-manager wait --for=condition=Available --timeout=60s deploy/cert-manager-webhook | |
- name: Deploy dependent CRDs | |
run: | | |
kubectl apply -f hack/test/ | |
- name: Deploy operator | |
run: | | |
make deploy | |
kubectl get deployment -n ramen-system | |
kubectl -n ramen-system wait --for=condition=Available --timeout=60s deploy/ramen-hub-operator | |
kubectl -n ramen-system wait --for=condition=Available --timeout=60s deploy/ramen-dr-cluster-operator | |
- name: Display failure logs | |
if: ${{ failure() }} | |
run: | | |
echo "===> BEGIN failure details <===" | |
echo "===> NODE details <===" | |
kubectl get node -o yaml | |
echo "===> Ramen POD details <===" | |
kubectl get pods -n ramen-system -o yaml | |
echo "===> Ramen POD describe <===" | |
kubectl describe pods -n ramen-system | |
echo "===> Ramen DR Orchestrator POD logs <===" | |
kubectl logs -n ramen-system deployment/ramen-hub-operator -c manager | |
echo "===> Ramen DR Manager POD logs <===" | |
kubectl logs -n ramen-system deployment/ramen-dr-cluster-operator -c manager | |
echo "===> END failure details <===" | |
publish-image: | |
name: Publish built image | |
needs: [deploy-check, lint, golangci, unit-test, build-image-and-ensure-clean-branch] | |
if: > | |
(vars.PUBLISH_IMAGES == 'true') && | |
(github.event_name == 'push') && | |
(github.ref == 'refs/heads/main' || | |
startsWith(github.ref, 'refs/heads/release-') || | |
startsWith(github.ref, 'refs/tags/v')) | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Download image artifact | |
uses: actions/download-artifact@v1 | |
with: | |
name: ramen-operator | |
path: /tmp | |
- name: Load image artifact | |
run: | | |
${{env.DOCKERCMD}} load -i /tmp/ramen-operator.tar | |
- name: Login to Quay | |
uses: docker/login-action@v1 | |
with: | |
registry: quay.io | |
username: ${{ secrets.QUAY_USERNAME }} | |
password: ${{ secrets.QUAY_ROBOT_TOKEN }} | |
- name: Determine image tag | |
run: | | |
[[ "${{ github.ref }}" =~ ^refs\/(heads|tags)\/(release-)?(.*) ]] | |
echo "heads or tags? ${BASH_REMATCH[1]}" | |
echo "release? ${BASH_REMATCH[2]}" | |
echo "version? ${BASH_REMATCH[3]}" | |
TAG="" | |
if test "${BASH_REMATCH[1]}" = "heads"; then | |
if test "${BASH_REMATCH[2]}" = "" && test "${BASH_REMATCH[3]}" = "main"; then | |
TAG="canary" | |
elif test "${BASH_REMATCH[2]}" = "release-"; then | |
TAG="${BASH_REMATCH[3]}-canary" | |
fi | |
elif test "${BASH_REMATCH[1]}" == "tags" && test "${BASH_REMATCH[2]}" = ""; then | |
TAG="${BASH_REMATCH[3]}" | |
fi | |
test "${TAG}" = "" && exit 1 | |
echo "Publish image tag ${TAG}" | |
echo "publish_image_tag=${TAG}" >> $GITHUB_ENV | |
- name: Push operator image to Quay | |
run: | | |
${{env.DOCKERCMD}} tag "${IMAGE_TAG_BASE}-operator:${IMAGE_TAG}" "${IMAGE_TAG_BASE}-operator:${{ env.publish_image_tag }}" | |
${{env.DOCKERCMD}} push "${IMAGE_TAG_BASE}-operator:${{ env.publish_image_tag }}" | |
# TODO: We do not need to build bundles and catalogs each time, fix once we reach alpha | |
- name: Checkout source | |
uses: actions/checkout@v2 | |
- name: Setup go | |
uses: actions/setup-go@v2 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: Build and push bundle images to Quay | |
run: | | |
IMAGE_TAG="${{ env.publish_image_tag }}" make bundle-build bundle-push | |
- name: Build and push catalog image to Quay | |
run: | | |
IMAGE_TAG="${{ env.publish_image_tag }}" make catalog-build catalog-push | |
# TODO: Test built bundles and catalog based install |