Skip to content

Commit

Permalink
Added multi-platform build
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamingRaven committed Sep 18, 2024
1 parent 5698801 commit ef2cc6f
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @DreamingRaven
48 changes: 48 additions & 0 deletions .github/workflows/0-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Lint Helm Charts
on:
workflow_call:

env:
CHARTS_DIR: "charts"
K8S_VERSION: "1.31.0"

jobs:
lint:
runs-on: ubuntu-latest
container:
image: alpine/helm:latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set Environment Variables and Paths the GitHub Way
run: |
export GOPATH=$HOME/.go
echo "GOPATH=$HOME/.go" >> $GITHUB_ENV
echo "$GOPATH/bin" >> $GITHUB_PATH
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install Dependencies
run: |
apk add --no-cache git make musl-dev go
go install github.com/yannh/kubeconform/cmd/kubeconform@v0.6.7
- name: Iteratively Lint Charts
run: |
for dir in ${{ env.CHARTS_DIR }}/*/
do
echo "*************************************"
dir=${dir%*/} # removes trailing "/"
echo "linting ${dir} chart"
helm dependency update "${dir}"
helm lint "${dir}"/
# on run if not 'corvid' chart
if [ "${dir}" != "${{ env.CHARTS_DIR }}/auth" ] && [ "${dir}" != "${{ env.CHARTS_DIR }}/kyverno" ]; then
helm template --namespace tst "${dir}"/ | kubeconform -strict -kubernetes-version ${{ env.K8S_VERSION }} \
-schema-location './schemas/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json' \
-schema-location default \
-schema-location 'https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/{{ .NormalizedKubernetesVersion }}/{{ .ResourceKind }}{{ .KindSuffix }}.json' \
-schema-location 'https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json'
fi
echo "*************************************"
done
53 changes: 53 additions & 0 deletions .github/workflows/1-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build Helm Charts
on:
workflow_call:

env:
CHARTS_DIR: "charts"

jobs:
build:
runs-on: ubuntu-latest
container:
image: alpine/helm:latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set Environment Variables and Paths the GitHub Way
run: |
export GOPATH=$HOME/.go
echo "GOPATH=$HOME/.go" >> $GITHUB_ENV
echo "$GOPATH/bin" >> $GITHUB_PATH
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install Dependencies
run: |
apk add --no-cache git make musl-dev go
- name: Iteratively Build Charts
run: |
for dir in ${{ env.CHARTS_DIR }}/*/
do
echo "*************************************"
DIR=${dir%*/} # removes trailing "/"
APP_VER=$(yq ".image.tag" ${DIR}/values.yaml | tr -d '"')
if [ "${APP_VER}" == "null" ]; then
echo "appVersion falling back to ${DIR}/Chart.yaml"
APP_VER=$(yq ".appVersion" ${DIR}/Chart.yaml | tr -d '"')
fi
HELM_VER=$(yq ".version" ${DIR}/Chart.yaml | tr -d '"')
echo "building ${DIR} chart (app: ${APP_VER}, chart: ${HELM_VER})"
echo "helm dependency build ${DIR}"
helm dependency build "${DIR}"/
echo "helm package '${DIR}/' --destination ./package --app-version ${APP_VER} --version=${HELM_VER}"
helm package "${DIR}/" --destination ./package --app-version ${APP_VER} --version=${HELM_VER}
echo "*************************************"
done
- name: Upload Charts
uses: actions/upload-artifact@v4
with:
name: charts
path: ./package
retention-days: 1
64 changes: 64 additions & 0 deletions .github/workflows/2-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Deploy Helm Charts
on:
workflow_call:

env:
CHARTS_DIR: "charts"

jobs:
deploy:
runs-on: ubuntu-latest
container:
image: alpine/helm:latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set Environment Variables and Paths the GitHub Way
run: |
export GOPATH=$HOME/.go
echo "GOPATH=$HOME/.go" >> $GITHUB_ENV
echo "$GOPATH/bin" >> $GITHUB_PATH
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install Dependencies
run: |
apk add --no-cache git tree make musl-dev go
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: charts
path: package

- name: Debug Artifacts
run: |
tree .
- name: Login to GHCR OCI Registry
run: |
helm registry login ghcr.io -u DreamingRaven -p ${{ secrets.GITHUB_TOKEN }}
env:
HELM_EXPERIMENTAL_OCI: '1'

- name: Helm Push Artifacts if Version Doesn't Exist
run: |
cd package
for filename in *.tgz; do
echo "*************************************"
regex='([a-zA-Z0-9_-]+)-([v0-9\.-]+)\.tgz'
chart_name=$(echo "$filename" | sed -E "s/$regex/\1/")
chart_version=$(echo "$filename" | sed -E "s/$regex/\2/")
echo "${chart_name} ${chart_version}"
if helm pull oci://ghcr.io/DreamingRaven/"${chart_name}" --version "${chart_version}"; then
echo "${chart_name} ${chart_version} exists, skipping ..."
else
echo "Pushing ${chart_name} ${chart_version} to ghcr.io/DreamingRaven"
helm push "${filename}" oci://ghcr.io/DreamingRaven/
fi
echo "*************************************"
done
env:
HELM_EXPERIMENTAL_OCI: '1'
shell: bash

18 changes: 18 additions & 0 deletions .github/workflows/check-pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Check Pipeline
on:
push:
branches:
- '**' # on push to any branch this pipeline should lint
- '!main' # that is not master

env:
CHARTS_DIR: "charts"
K8S_VERSION: "1.31.0"

jobs:
lint:
uses: ./.github/workflows/0-lint.yaml
build:
uses: ./.github/workflows/1-build.yaml
needs:
- lint
21 changes: 21 additions & 0 deletions .github/workflows/publish-pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Publish Pipeline
on:
push:
branches:
- 'main' # on push to any branch this pipeline should lint

env:
CHARTS_DIR: "charts"
K8S_VERSION: "1.31.0"

jobs:
lint:
uses: ./.github/workflows/0-lint.yaml
build:
uses: ./.github/workflows/1-build.yaml
needs:
- lint
deploy:
uses: ./.github/workflows/2-deploy.yaml
needs:
- build

0 comments on commit ef2cc6f

Please sign in to comment.