Skip to content

Commit

Permalink
Build and publish charts for OBS/IBS artifacts in gh-pages
Browse files Browse the repository at this point in the history
Signed-off-by: David Cassany <dcassany@suse.com>
  • Loading branch information
davidcassany committed Aug 28, 2023
1 parent c90c1c8 commit d300159
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 211 deletions.
66 changes: 66 additions & 0 deletions .github/actions/chart/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Build and publish charts

inputs:
build_env:
required: true
keep_previous:
required: false
default: no
ibs_release:
required: false
default: no

runs:
using: composite
steps:
- name: Install yq
uses: mikefarah/yq@v4.28.2
- name: Set image repositories
id: set_repo
shell: bash
env:
B_ENV: ${{ inputs.build_env }}
IBS_RELEASE: ${{ inputs.ibs_release }}
run: |
if [ "${IBS_RELEASE}" == "yes" ]; then
echo "B_REPO=registry.suse.com" >> $GITHUB_OUTPUT
else
echo "B_REPO=registry.opensuse.org/isv/rancher/elemental/${B_ENV}/containers" >> $GITHUB_OUTPUT
fi
- name: Build chart for release
env:
B_REPO: ${{ steps.set_repo.outputs.B_REPO }}
OPERATOR_REPO: rancher/elemental-operator
SEEDIMAGE_REPO: rancher/seedimage-builder
CHANNEL_REPO: rancher/elemental-teal-channel
shell: bash
run: |
REGISTRY_URL=${B_REPO} \
REPO=${OPERATOR_REPO} \
REPO_SEEDIMAGE=${SEEDIMAGE_REPO} \
REPO_CHANNEL=${CHANNEL_REPO} \
make chart
- name: Build and push index
env:
B_ENV: ${{ inputs.build_env }}
KEEP_PREV: ${{ inputs.keep_previous }}
IBS_RELEASE: ${{ inputs.ibs_release }}
shell: bash
run: |
COMMIT=$(git rev-parse HEAD)
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git config --global user.name "${{ github.actor }}"
git checkout gh-pages
if [ "${IBS_RELEASE}" == "yes" ]; then
B_ENV="release"
fi
if [ "${KEEP_PREV}" == "no" ]; then
rm -rf ${B_ENV}
fi
mkdir -p ${B_ENV}/build
cp -v build/* ${B_ENV}/build
helm repo index --url https://rancher.github.io/elemental-operator ./${B_ENV}
git add ${B_ENV}/index.yaml ${B_ENV}/build/ -f
git commit -m "Updating helm dev repo to main commit ${{ github.sha }}"
git push --set-upstream origin gh-pages
git checkout ${COMMIT}
84 changes: 7 additions & 77 deletions .github/workflows/chart.yaml
Original file line number Diff line number Diff line change
@@ -1,90 +1,20 @@
name: Build and publish chart
name: Build and publish development charts
on:
pull_request:
push:
branches:
- main
tags:
- 'v*'
- "v*"

jobs:
chart:
dev-charts:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install yq
uses: mikefarah/yq@v4.28.2
- name: Build chart for CI
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: |
make chart
- name: Build chart for release
if: startsWith(github.ref, 'refs/tags/')
run: |
REGISTRY_URL=quay.io/costoolkit REPO=elemental-operator REPO_SEEDIMAGE=elemental-seedimage TAG=${GITHUB_REF##*/} make chart
- name: Publish chart to release
uses: fnkr/github-action-ghr@v1
if: startsWith(github.ref, 'refs/tags/')
env:
GHR_COMPRESS: tgz
GHR_PATH: build/
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GHR_REPLACE: true
- name: Install Helm
if: startsWith(github.ref, 'refs/tags/')
uses: azure/setup-helm@v1
- name: Build and publish OBS dev charts
uses: "./.github/actions/chart"
with:
version: v3.7.1
- name: Set chart output
id: chart
run: |
CHART=$(find . -type f -name "elemental-operator-[1-9]*.tgz" -print)
echo "chart_name=$CHART" >> $GITHUB_OUTPUT
- name: Test chart values
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: |
REGISTRY_URL=$(helm show values ${{ steps.chart.outputs.chart_name }}|yq .registry_url)
REPO=$(helm show values ${{ steps.chart.outputs.chart_name }}|yq .image.repository)
if [ "$REGISTRY_URL" != "quay.io/coostoolkit" ]; then
echo "registry_url on the built chart is not the expected value"
echo "Expected quay.io/coostoolkit but got $REGISTRY_URL"
fi
if [ "$REPO" != "elemental-operator-ci" ];then
echo "REPO on the built chart is not the expected value"
echo "Expected elemental-operator-ci but got $REPO"
exit 1
fi
- name: Test release chart values
if: startsWith(github.ref, 'refs/tags/')
run: |
REGISTRY_URL=$(helm show values ${{ steps.chart.outputs.chart_name }}|yq .registry_url))
REPO=$(helm show values ${{ steps.chart.outputs.chart_name }}|yq .image.repository)
TAG=$(helm show values ${{ steps.chart.outputs.chart_name }}|yq .image.tag)
if [ "$REGISTRY_URL" != "quay.io/coostoolkit" ]; then
echo "registry_url on the built chart is not the expected value"
echo "Expected quay.io/coostoolkit but got $REGISTRY_URL"
fi
if [ "$REPO" != "elemental-operator" ];then
echo "REPO on the built chart is not the expected value"
echo "Expected elemental-operator but got $REPO"
exit 1
fi
if [ "$TAG" != "${GITHUB_REF##*/}" ];then
echo "TAG on the built chart is not the expected value"
echo "Expected ${GITHUB_REF##*/} but got $TAG"
exit 1
fi
- name: Build and push index
if: startsWith(github.ref, 'refs/tags/')
run: |
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git config --global user.name "${{ github.actor }}"
git checkout gh-pages
rm index.yaml
helm repo index --url https://rancher.github.io/elemental-operator .
git add index.yaml build/ -f
git commit -m "Updating helm repo to main commit ${{ github.sha }}"
git push --set-upstream origin gh-pages
build_env: dev
42 changes: 0 additions & 42 deletions .github/workflows/gorelease.yaml

This file was deleted.

61 changes: 61 additions & 0 deletions .github/workflows/release-chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Build and publish staging or stable charts
on:
workflow_dispatch:
inputs:
tag:
description: "Tag to build"
required: true
type: string
release:
description: "Release stable versions, staging otherwise"
type: boolean
default: false

jobs:
stable-charts:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Log inputs
run: echo "${{ toJSON(github.event.inputs) }}"
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ inputs.tag }}
- name: Build and publish OBS staging charts
if: inputs.release == false
uses: "./.github/actions/chart"
with:
build_env: staging
- name: Build and publish OBS stable charts
if: inputs.release == true
uses: "./.github/actions/chart"
with:
build_env: stable
keep_previous: yes
- name: Clear built artifacts
if: inputs.release == true
shell: bash
run: |
rm -rf build/*
- name: Build and publish IBS charts
if: inputs.release == true
uses: "./.github/actions/chart"
with:
build_env: stable
keep_previous: yes
ibs_release: yes
- name: create release
if: inputs.release == true
uses: ncipollo/release-action@v1
id: create_release
with:
tag: ${{ inputs.tag }}
draft: false
prerelease: true
generateReleaseNotes: true
artifacts: "build/*"
updateOnlyUnreleased: true
allowUpdates: true
44 changes: 24 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
GIT_COMMIT?=$(shell git rev-parse HEAD)
GIT_COMMIT_SHORT?=$(shell git rev-parse --short HEAD)
GIT_TAG?=$(shell git describe --abbrev=0 --tags 2>/dev/null || echo "v0.0.0" )
TAG?=${GIT_TAG}-${GIT_COMMIT_SHORT}
REPO?=elemental-operator-ci
REPO_REGISTER?=elemental-register-ci
REPO_SEEDIMAGE?=seedimage-builder-ci
REGISTRY_URL?=quay.io/coostoolkit
#REGISTRY_URL?=registry.opensuse.org/isv/rancher/elemental/dev/containers
CHART_VERSION?=$(subst v,,$(GIT_TAG))
TAG?=${GIT_TAG}
REPO?=rancher/elemental-operator
REPO_REGISTER?=rancher/elemental-register
TAG_SEEDIMAGE?=${CHART_VERSION}
REPO_SEEDIMAGE?=rancher/seedimage-builder
TAG_CHANNEL?=${CHART_VERSION}
REPO_CHANNEL?=rancher/elemental-teal-channel
REGISTRY_URL?=registry.opensuse.org/isv/rancher/elemental/dev/containers
ifneq ($(REGISTRY_URL),)
REGISTRY_HEADER := $(REGISTRY_URL)/
else
REGISTRY_HEADER := ""
endif

export ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
CHART_VERSION?=$(subst v,,$(GIT_TAG))
CHART?=$(shell find $(ROOT_DIR) -type f -name "elemental-operator-$(CHART_VERSION).tgz" -print)
KUBE_VERSION?="v1.24.6"
CLUSTER_NAME?="operator-e2e"
Expand Down Expand Up @@ -98,7 +100,7 @@ build-docker-operator:
--build-arg "TAG=${GIT_TAG}" \
--build-arg "COMMIT=${GIT_COMMIT}" \
--build-arg "COMMITDATE=${COMMITDATE}" \
-t ${REGISTRY_HEADER}${REPO}:${TAG} .
-t ${REGISTRY_HEADER}${REPO}:${CHART_VERSION} .

.PHONY: build-docker-register
build-docker-register:
Expand All @@ -108,25 +110,25 @@ build-docker-register:
--build-arg "TAG=${GIT_TAG}" \
--build-arg "COMMIT=${GIT_COMMIT}" \
--build-arg "COMMITDATE=${COMMITDATE}" \
-t ${REGISTRY_HEADER}${REPO_REGISTER}:${TAG} .
-t ${REGISTRY_HEADER}${REPO_REGISTER}:${CHART_VERSION} .

.PHONY: build-docker-seedimage-builder
build-docker-seedimage-builder:
DOCKER_BUILDKIT=1 docker build \
-f Dockerfile.seedimage \
-t ${REGISTRY_HEADER}${REPO_SEEDIMAGE}:${TAG} .
-t ${REGISTRY_HEADER}${REPO_SEEDIMAGE}:${TAG_SEEDIMAGE} .

.PHONY: build-docker-push-operator
build-docker-push-operator: build-docker-operator
docker push ${REGISTRY_HEADER}${REPO}:${TAG}
docker push ${REGISTRY_HEADER}${REPO}:${CHART_VERSION}

.PHONY: build-docker-push-register
build-docker-push-register: build-docker-register
docker push ${REGISTRY_HEADER}${REPO_REGISTER}:${TAG}
docker push ${REGISTRY_HEADER}${REPO_REGISTER}:${CHART_VERSION}

.PHONY: build-docker-push-seedimage-builder
build-docker-push-seedimage-builder: build-docker-seedimage-builder
docker push ${REGISTRY_HEADER}${REPO_SEEDIMAGE}:${TAG}
docker push ${REGISTRY_HEADER}${REPO_SEEDIMAGE}:${TAG_SEEDIMAGE}

.PHONY: chart
chart:
Expand All @@ -135,12 +137,14 @@ chart:
helm package --version ${CHART_VERSION} --app-version ${GIT_TAG} -d $(ROOT_DIR)/build/ $(ROOT_DIR)/build/crds
rm -Rf $(ROOT_DIR)/build/crds
cp -rf $(ROOT_DIR)/charts/operator $(ROOT_DIR)/build/operator
yq -i '.image.tag = "${TAG}"' $(ROOT_DIR)/build/operator/values.yaml
yq -i '.image.tag = "${CHART_VERSION}"' $(ROOT_DIR)/build/operator/values.yaml
yq -i '.image.repository = "${REPO}"' $(ROOT_DIR)/build/operator/values.yaml
yq -i '.seedImage.tag = "${TAG}"' $(ROOT_DIR)/build/operator/values.yaml
yq -i '.seedImage.tag = "${TAG_SEEDIMAGE}"' $(ROOT_DIR)/build/operator/values.yaml
yq -i '.seedImage.repository = "${REPO_SEEDIMAGE}"' $(ROOT_DIR)/build/operator/values.yaml
yq -i '.channel.tag = "${TAG_CHANNEL}"' $(ROOT_DIR)/build/operator/values.yaml
yq -i '.channel.repository = "${REPO_CHANNEL}"' $(ROOT_DIR)/build/operator/values.yaml
yq -i '.registry_url = "${REGISTRY_URL}"' $(ROOT_DIR)/build/operator/values.yaml
helm package --version ${CHART_VERSION} --app-version ${GIT_TAG} -d $(ROOT_DIR)/build/ $(ROOT_DIR)/build/operator
helm package --version ${CHART_VERSION} --app-version ${CHART_VERSION} -d $(ROOT_DIR)/build/ $(ROOT_DIR)/build/operator
rm -Rf $(ROOT_DIR)/build/operator

.PHONY: migration-chart
Expand Down Expand Up @@ -178,20 +182,20 @@ setup-full-cluster: build-docker-operator build-docker-seedimage-builder chart s
export BRIDGE_IP="172.18.0.1" && \
export CHART=$(CHART) && \
export CONFIG_PATH=$(E2E_CONF_FILE) && \
kind load docker-image --name $(CLUSTER_NAME) ${REGISTRY_HEADER}${REPO}:${TAG} && \
kind load docker-image --name $(CLUSTER_NAME) ${REGISTRY_HEADER}${REPO_SEEDIMAGE}:${TAG} && \
kind load docker-image --name $(CLUSTER_NAME) ${REGISTRY_HEADER}${REPO}:${CHART_VERSION} && \
kind load docker-image --name $(CLUSTER_NAME) ${REGISTRY_HEADER}${REPO_SEEDIMAGE}:${TAG_SEEDIMAGE} && \
cd $(ROOT_DIR)/tests && $(GINKGO) -r -v --label-filter="do-nothing" ./e2e

kind-e2e-tests: build-docker-operator chart setup-kind
export CONFIG_PATH=$(E2E_CONF_FILE) && \
kind load docker-image --name $(CLUSTER_NAME) ${REGISTRY_HEADER}${REPO}:${TAG}
kind load docker-image --name $(CLUSTER_NAME) ${REGISTRY_HEADER}${REPO}:${CHART_VERSION}
$(MAKE) e2e-tests

# This builds the docker image, generates the chart, loads the image into the kind cluster and upgrades the chart to latest
# useful to test changes into the operator with a running system, without clearing the operator namespace
# thus losing any registration/inventories/os CRDs already created
reload-operator: build-docker-operator chart
kind load docker-image --name $(CLUSTER_NAME) ${REGISTRY_HEADER}${REPO}:${TAG}
kind load docker-image --name $(CLUSTER_NAME) ${REGISTRY_HEADER}${REPO}:${CHART_VERSION}
helm upgrade -n cattle-elemental-system elemental-operator $(CHART)

.PHONY: vendor
Expand Down
4 changes: 0 additions & 4 deletions charts/crds-migration/Chart.yaml

This file was deleted.

Loading

0 comments on commit d300159

Please sign in to comment.