Skip to content

Commit

Permalink
build: publish container & chart to oci registry with version from fr…
Browse files Browse the repository at this point in the history
…om git
  • Loading branch information
davidB committed Dec 11, 2024
1 parent 6738ab7 commit 2c4809a
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 29 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ jobs:
if: steps.changed-files.outputs.any_changed == 'true'
- uses: jdx/mise-action@v2
if: steps.changed-files.outputs.any_changed == 'true'
with:
experimental: true
- run: mise install
if: steps.changed-files.outputs.any_changed == 'true'
shell: bash
Expand Down
21 changes: 9 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,12 @@ jobs:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}

# - name: "Build Inventory Image"
# run: |
# docker build . --tag ghcr.io/<your-GitHub-username>/store:latest
# docker push ghcr.io/${{ github.repository }}/store:latest

- name: Run Skaffold pipeline as action
uses: hiberbee/github-action-skaffold@1.27.0
with:
skaffold-version: "2.10.0"
command: build
# repository: ghcr.io/${{ github.repository }}
- name: Set up Docker Buildx # to support buildx, multi-arch builds
uses: docker/setup-buildx-action@v3
- uses: jdx/mise-action@v2
- run: mise install
shell: bash
working-directory: charts
- run: mise run publish
shell: bash
working-directory: charts
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,4 @@ megalinter-reports/
#misc
.aider*
proptest-regressions/
build/
1 change: 1 addition & 0 deletions cdviz-collector/.mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = "http://127.0.0.1:4317"
OTEL_TRACES_SAMPLER = "always_off"

[tools]
# "aqua:hadolint/hadolint" = "2" # hadolint is a Dockerfile linter
rust = "1.83.0" # the rust tool stack (with cargo, fmt, clippy) to build source
"aqua:cargo-bins/cargo-binstall" = "1" # do not use cargo-binstall (it's a special name used by mise)
"cargo:cargo-hack" = "latest"
Expand Down
2 changes: 1 addition & 1 deletion cdviz-collector/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ RUN <<EOT
cp "target/aarch64-unknown-linux-musl/${PROFILE}/cdviz-collector" /app/linux/arm64
cp "target/x86_64-unknown-linux-musl/${PROFILE}/cdviz-collector" /app/linux/amd64
EOT
# TODO RUN upx /work/target/${TARGET}/${PROFILE}/cdviz-collector
# TODO `upx /work/target/${TARGET}/${PROFILE}/cdviz-collector`

HEALTHCHECK NONE

Expand Down
99 changes: 86 additions & 13 deletions charts/.mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,92 @@ CLUSTER_NAME = "kind-local"
# local kubernetes (k8s)
# docker = "latest" # to build, to run containers, should be available for some of thoses tools
# dive = "latest" # to explore content of image container
helm = "3" # to deploy, check helm chart
kubectl = "1.31" # to interact with k8s cluster
ctlptl = "0.8" # to setup / manage local k8s (kind) cluster
kind = "0.25.0" # to have a local k8s cluster (on top of docker)
java = "21" # required by skaffold
skaffold = "2" # to have simple watch flow to build container, to publish container on local k8s registry, to deploy helm chart with new container

[tasks.lint]
run = [
"helm lint cdviz-collector",
"helm lint cdviz-db",
"helm lint cdviz-grafana",
"helm lint cdviz",
helm = "3" # to deploy, check helm chart
kubectl = "1.31" # to interact with k8s cluster
ctlptl = "0.8" # to setup / manage local k8s (kind) cluster
kind = "0.25.0" # to have a local k8s cluster (on top of docker)
java = "21" # required by skaffold
skaffold = "2" # to have simple watch flow to build container, to publish container on local k8s registry, to deploy helm chart with new container
"aqua:mikefarah/yq" = "4"

# TODO upgrade version only if change in the context of the Dockerfile
# TODO sign container (see <https://www.sigstore.dev/how-it-works>)
# TODO sign chart (see <https://www.sigstore.dev/how-it-works>)

[tasks."lint:cdviz-collector"]
run = ["helm lint cdviz-collector"]

[tasks."lint:cdviz-db"]
run = ["helm lint cdviz-db"]

[tasks."lint:cdviz-grafana"]
run = ["helm lint cdviz-grafana"]

[tasks."lint:cdviz"]
run = ["helm lint cdviz"]

[tasks."publish-module"]
hide = true
shell = 'bash -c'
run = """
set -euxo pipefail
MODULE={{option(name="module")}}
mkdir -p build || true
# get version from git descibe
git describe --always "$(git log -n 1 --pretty=format:%h -- ../${MODULE})" > build/version-${MODULE}.txt
VERSION=$(cat build/version-${MODULE}.txt)
# build container (for x86_64 and arm64) with version as tag & publish on ghcr.io
if [[ -f "../${MODULE}/Dockerfile" ]]; then
docker buildx build \
--output type=image,compression=zstd,oci-mediatypes=true \
--platform linux/amd64,linux/arm64 \
-t "ghcr.io/cdviz-dev/${MODULE}:${VERSION}" \
--push \
-f "../${MODULE}/Dockerfile" \
"../${MODULE}"
fi
# build & publish chart as oci
# set version in Chart.yaml & values.yaml (using go-yq) not needed because the version of the image is set to appVersion, and the version (& appVersion) are set via cli during the package
helm package -d build "${MODULE}" --app-version "$VERSION" --version "$VERSION"
helm push "build/${MODULE}-${VERSION}.tgz" oci://ghcr.io/cdviz-dev
"""

[tasks."publish:cdviz-collector"]
run = ["mise run publish-module --module cdviz-collector"]

[tasks."publish:cdviz-db"]
run = ["mise run publish-module --module cdviz-db"]

[tasks."publish:cdviz-grafana"]
run = ["mise run publish-module --module cdviz-grafana"]

[tasks."publish:cdviz"]
shell = 'bash -c'
depends = [
"publish:cdviz-collector",
"publish:cdviz-db",
"publish:cdviz-grafana",
]
run = """
set -euxo pipefail
for MODULE in cdviz-collector cdviz-db cdviz-grafana; do
VERSION=$(cat build/version-${MODULE}.txt)
yq eval -i "with(.dependencies[] ; select(.name == \"${MODULE}\").version = \"${VERSION}\")" cdviz/Chart.yaml
done
VERSION=$(git describe --always)
helm package -d build "${MODULE}" --app-version "$VERSION" --version "$VERSION"
helm push "build/${MODULE}-${VERSION}.tgz" oci://ghcr.io/cdviz-dev
"""

[tasks."publish"]
depends = ["publish:cdviz"]

[tasks."k8s:create"]
run = [
Expand All @@ -44,6 +116,7 @@ run = [

[tasks.ci]
description = "set of tasks run by CI"
depends = ["lint:*"]
run = [
# sudo systemctl start docker
# k3d cluster create "$CLUSTER_NAME" --agents 2
Expand Down
2 changes: 1 addition & 1 deletion charts/cdviz-collector/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ image:
repository: ghcr.io/cdviz-dev/cdviz-collector
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "latest" # TODO Change this to a version number on release
# tag: "latest"

imagePullSecrets: []
nameOverride: ""
Expand Down

0 comments on commit 2c4809a

Please sign in to comment.