Skip to content

Commit

Permalink
Merge pull request #110 from mallardduck/repo-reorg/publish-workflows
Browse files Browse the repository at this point in the history
Repo reorg follow up for Releases
  • Loading branch information
mallardduck authored Oct 17, 2024
2 parents b08a854 + 007b75e commit 50d7c1a
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 15 deletions.
116 changes: 114 additions & 2 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,125 @@
name : Publish images
name : Publish images, charts and binaries

on:
push:
tags:
- "*"
- "v*"

env:
GHCR_REGISTRY: ghcr.io
REGISTRY: docker.io
IMAGE_NAME: ${{ github.repository }}
YQ_VERSION: v4.44.3

jobs:
helm-locker-ci:
uses: ./.github/workflows/hl-ci.yaml
helm-project-operator-ci:
uses: ./.github/workflows/hpo-ci.yaml
with:
skip_build: 'true'
goreleaser:
name: Build go binaries and helm chart
runs-on : runs-on,image=ubuntu22-full-x64,runner=4cpu-linux-x64,run-id=${{ github.run_id }}
needs: [
helm-locker-ci,
helm-project-operator-ci,
]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_CURRENT_TAG: ${{ github.ref_name }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git fetch --force --tags
- name : setup Go
uses : actions/setup-go@v5
with:
go-version: 1.22
- name: Install mikefarah/yq
run: |
sudo wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64 -O /usr/bin/yq && sudo chmod +x /usr/bin/yq;
- uses: azure/setup-kubectl@v3
- name : Install helm
uses: azure/setup-helm@v3
- name: Prepare helm charts for debug artifacts
run: |
BUILD_TARGET=helm-locker make package-helm && echo "hl: chart success"
BUILD_TARGET=helm-project-operator make package-helm && echo "hpo: embeded chart success"
BUILD_TARGET=prometheus-federator make package-helm && echo "pf: embeded chart success"
- name: Prepare embedded helm chart (needed for build)
run: |
BUILD_TARGET=helm-project-operator make build-chart
BUILD_TARGET=prometheus-federator make build-chart
- uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_CURRENT_TAG: ${{ github.ref_name }}
push-dev-images:
name : Build and push helm-locker & Helm-Project-Operator images
runs-on : runs-on,image=ubuntu22-full-x64,runner=4cpu-linux-x64,run-id=${{ github.run_id }}
needs: [
helm-locker-ci,
helm-project-operator-ci,
]
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name : Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.GHCR_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for helm-locker image
id: meta-locker
uses: docker/metadata-action@v5
with:
images: ${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }}/helm-locker
- name: Build and push helm-locker image
id: push
uses: docker/build-push-action@v5
with:
context: .
file: ./package/Dockerfile-helm-locker
push: true
tags: ${{ steps.meta-locker.outputs.tags }}
labels: ${{ steps.meta-locker.outputs.labels }}
platforms : linux/amd64,linux/arm64
- name: Extract metadata (tags, labels) for Helm-Project-Operator image
id: meta-hpo
uses: docker/metadata-action@v5
with:
images: ${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }}/helm-project-operator
- name: Build Helm-Project-Operator image
uses: docker/build-push-action@v5
with:
context: .
file: ./package/Dockerfile-helm-project-operator
push: true
tags: ${{ steps.meta-hpo.outputs.tags }}
labels: ${{ steps.meta-hpo.outputs.labels }}
platforms: linux/amd64,linux/arm64

publish-images:
name: Publish prometheus-federator image
runs-on: ubuntu-latest
needs: [
helm-locker-ci,
helm-project-operator-ci,
]
permissions:
contents : read
id-token: write
Expand Down
84 changes: 84 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Make sure to check the documentation at https://goreleaser.com
version: 2 # the goreleaser config version
before:
hooks:
- go mod tidy
builds:
- id: helm-locker
main: ./cmd/helm-locker/main.go
goos:
- linux
goarch:
- amd64
- arm64
binary: helm-locker
ldflags:
- -extldflags
- -static
- -s
- -X main.Version={{.Version}} -X main.GitCommit={{.Commit}}
flags:
- -trimpath
env:
- CGO_ENABLED=0
- id: helm-project-operator
main: ./cmd/helm-project-operator/main.go
goos:
- linux
goarch:
- amd64
- arm64
binary: helm-project-operator
ldflags:
- -extldflags
- -static
- -s
- -X main.Version={{.Version}} -X main.GitCommit={{.Commit}}
flags:
- -trimpath
env:
- CGO_ENABLED=0
- id: prometheus-federator
main: ./cmd/prometheus-federator/main.go
goos:
- linux
goarch:
- amd64
- arm64
binary: prometheus-federator
ldflags:
- -extldflags
- -static
- -s
- -X main.Version={{.Version}} -X main.GitCommit={{.Commit}}
flags:
- -trimpath
env:
- CGO_ENABLED=0
archives:
- id: prometheus-federator
builds:
- prometheus-federator
name_template: '{{ .Binary }}-{{ .Arch }}'
- id: helm-project-operator
builds:
- helm-project-operator
name_template: '{{ .Binary }}-{{ .Arch }}'
- id: helm-locker
builds:
- helm-locker
name_template: '{{ .Binary }}-{{ .Arch }}'
release:
prerelease: auto
extra_files:
- glob : ./build/charts/*.tgz
checksum:
name_template: 'checksums.txt'
snapshot:
version_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
1 change: 0 additions & 1 deletion package/Dockerfile-helm-project-operator
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ COPY --from=helm /helm/bin/helm /usr/local/bin/
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN make build-chart
RUN make build

FROM registry.suse.com/bci/bci-micro:latest
Expand Down
17 changes: 6 additions & 11 deletions scripts/build-chart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ source $(dirname $0)/util-chart

# We don't do this for helm-locker
if [[ "${BUILD_TARGET}" == "helm-locker" ]]; then
echo "No build-chart for helm-locker; maybe you meant package-helm"
exit
fi

Expand All @@ -20,20 +21,14 @@ fi
CHART=${CHART:-${DEFAULT_CHART_TARGET}}

if [ "$BUILD_TARGET" == "prometheus-federator" ]; then
CHART_VERSION=${EMBEDDED_CHART_VERSION:-$(find ./charts/${CHART} -maxdepth 1 -mindepth 1 -type d | tr - \~ | sort -rV | tr \~ - | head -n1 | cut -d'/' -f4)}

# Prepare and package charts
package-charts "charts/${CHART}/${CHART_VERSION}" ./build/charts
CHART_VERSION=${EMBEDDED_CHART_VERSION:-$(find "./charts/${CHART}" -maxdepth 1 -mindepth 1 -type d | tr - \~ | sort -rV | tr \~ - | head -n1 | cut -d'/' -f4)}

# Prepare chart for embedding location
base64 -i "build/charts/${CHART}-${CHART_VERSION}.tgz" > "cmd/${BUILD_TARGET}/fs/${CHART}.tgz.base64"
rm "build/charts/${CHART}-${CHART_VERSION}.tgz"
base64 -i "assets/${CHART}/${CHART}-${CHART_VERSION}.tgz" > "cmd/${BUILD_TARGET}/fs/${CHART}.tgz.base64"
elif [ "$BUILD_TARGET" == "helm-project-operator" ]; then
# Prepare base chart for build
rm -rf build/charts
mkdir -p build/charts
cp -rf "examples/helm-project-operator/${CHART}" build/charts/

clean-old-chart "$CHART"
cp -rf "examples/${BUILD_TARGET}/${CHART}" build/charts/

# Update the chart placeholders
edit-charts "build/charts/${CHART}/Chart.yaml" "${HELM_CHART_VERSION}" "${HELM_IMAGE_TAG}"
Expand All @@ -43,4 +38,4 @@ elif [ "$BUILD_TARGET" == "helm-project-operator" ]; then
base64 -i "./build/charts/${CHART}-${HELM_CHART_VERSION}.tgz" > "cmd/${BUILD_TARGET}/fs/${CHART}.tgz.base64"
fi

echo "Completed ${CHART} (${CHART_VERSION}) build process."
echo "Completed ${CHART} (ver: ${HELM_CHART_VERSION:-"n/a"}) build process."
33 changes: 33 additions & 0 deletions scripts/package-helm
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
set -e
set -x

if ! hash helm 2>/dev/null; then
echo "Helm is not installed"
exit 1
fi

source "$(dirname "$0")/version"
source "$(dirname "$0")/util-chart"

# We don't do the full process for prometheus-federator
if [[ "${BUILD_TARGET}" == "prometheus-federator" ]]; then
mkdir -p ./dist/artifacts/
CHART_VERSION=${EMBEDDED_CHART_VERSION:-$(find "./charts/${BUILD_TARGET}" -maxdepth 1 -mindepth 1 -type d | tr - \~ | sort -rV | tr \~ - | head -n1 | cut -d'/' -f4)}
cp -a "./assets/${BUILD_TARGET}/${BUILD_TARGET}-${CHART_VERSION}.tgz" ./build/charts/
exit
fi

cd "$(dirname "$0")/.."

if [ "$BUILD_TARGET" == "helm-project-operator" ]; then
DEFAULT_CHART_SOURCE="./packages/$BUILD_TARGET/charts"
elif [ "$BUILD_TARGET" == "helm-locker" ]; then
DEFAULT_CHART_SOURCE="./examples/$BUILD_TARGET/helm-locker-chart-example"
fi

clean-old-chart "$BUILD_TARGET"
cp -rf "${DEFAULT_CHART_SOURCE}" "./build/charts/${BUILD_TARGET}"

edit-charts "./build/charts/${BUILD_TARGET}/Chart.yaml" "${HELM_CHART_VERSION}" "${HELM_IMAGE_TAG}"
package-charts "./build/charts/${BUILD_TARGET}"
11 changes: 10 additions & 1 deletion scripts/util-chart
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,14 @@ function edit-charts() {
}

function package-charts() {
helm package --debug "${1:-"./build/charts/helm-project-operator"}" -d "${2:-"./dist/artifacts"}"
helm package --debug "${1:-"./build/charts/helm-project-operator"}" -d "${2:-"./build/charts"}"
}

function clean-old-chart() {
if [[ -d "./build/charts/${1}" ]]; then
rm -rf "./build/charts/${1}"
fi
if [[ ! -d "./build/charts" ]]; then
mkdir -p "./build/charts"
fi
}

0 comments on commit 50d7c1a

Please sign in to comment.