From 97ef92706babf3473cc18764a7904bebcd76e18e Mon Sep 17 00:00:00 2001 From: Lionel ORRY Date: Thu, 17 Jul 2025 12:45:35 +0200 Subject: [PATCH 01/11] refactor workflows to enable multiple docker images --- .github/workflows/build-and-push.yml | 23 +++++++++++++---------- .github/workflows/trigger-manual.yml | 19 +++++++++++++++++++ .github/workflows/trigger-nightly.yml | 13 +++++++++++++ 3 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/trigger-manual.yml create mode 100644 .github/workflows/trigger-nightly.yml diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml index 475ec6518..7f24431e4 100644 --- a/.github/workflows/build-and-push.yml +++ b/.github/workflows/build-and-push.yml @@ -1,14 +1,16 @@ -name: "Build GARM images" +name: "Build and push GARM images" on: - workflow_dispatch: + workflow_call: inputs: push_to_project: description: "Project to build images for" required: true + type: string default: "ghcr.io/cloudbase" ref: description: "Ref to build" required: true + type: string default: "main" schedule: - cron: "0 2 * * *" @@ -24,8 +26,9 @@ jobs: runs-on: ubuntu-latest steps: - name: "Checkout" - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: + ref: ${{ inputs.ref }} path: src/github.com/cloudbase/garm fetch-depth: 0 @@ -40,15 +43,12 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push + env: + REGISTRY_INPUT: ${{ inputs.push_to_project }} + GH_REF: ${{ inputs.ref }} + working-directory: src/github.com/cloudbase/garm run: | set -x - REGISTRY_INPUT="${{ github.event.inputs.push_to_project }}" - REF_INPUT="${{ github.event.inputs.ref }}" - - PUSH_TO_PROJECT="${REGISTRY_INPUT:-ghcr.io/cloudbase}" - GH_REF="${REF_INPUT:-main}" - cd src/github.com/cloudbase/garm && git checkout "${GH_REF}" - VERSION=$(git describe --tags --match='v[0-9]*' --always) AZURE_REF=v0.1.0 OPENSTACK_REF=v0.1.0 @@ -69,6 +69,9 @@ jobs: K8S_REF="main" VERSION="nightly" fi + if [ "$GH_REF" == "release/v1" ]; then + VERSION="v0.1" + fi docker buildx build \ --provenance=false \ --platform linux/amd64,linux/arm64 \ diff --git a/.github/workflows/trigger-manual.yml b/.github/workflows/trigger-manual.yml new file mode 100644 index 000000000..faf166d46 --- /dev/null +++ b/.github/workflows/trigger-manual.yml @@ -0,0 +1,19 @@ +name: Manual build of GARM images +on: + workflow_dispatch: + inputs: + push_to_project: + description: "Project to build images for" + required: true + default: "ghcr.io/cloudbase" + ref: + description: "Ref to build" + required: true + default: "main" + +jobs: + call-build-and-push: + uses: ./.github/workflows/build-and-push.yml + with: + push_to_project: ${{ inputs.push_to_project }} + ref: ${{ inputs.ref }} \ No newline at end of file diff --git a/.github/workflows/trigger-nightly.yml b/.github/workflows/trigger-nightly.yml new file mode 100644 index 000000000..79c42228f --- /dev/null +++ b/.github/workflows/trigger-nightly.yml @@ -0,0 +1,13 @@ +name: Nightly build of GARM images +on: + schedule: + - cron: "0 2 * * *" + +jobs: + call-build-and-push: + uses: ./.github/workflows/build-and-push.yml + strategy: + matrix: + ref: ["main", "release/v1"] + with: + ref: ${{ matrix.ref }} From 1e8d0d79a6052de814716964802977b7ec38a249 Mon Sep 17 00:00:00 2001 From: Lionel ORRY Date: Tue, 29 Jul 2025 09:47:29 +0200 Subject: [PATCH 02/11] improvements after review comments --- .github/workflows/build-and-push.yml | 32 +++++++++++++++++++--------- Dockerfile | 2 +- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml index 7f24431e4..907dd8c1b 100644 --- a/.github/workflows/build-and-push.yml +++ b/.github/workflows/build-and-push.yml @@ -48,17 +48,15 @@ jobs: GH_REF: ${{ inputs.ref }} working-directory: src/github.com/cloudbase/garm run: | + get_gh_latest_release() { + curl -s -L -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "https://api.github.com/repos/$1/latest" \ + | jq -r '.tag_name' + } set -x - VERSION=$(git describe --tags --match='v[0-9]*' --always) - AZURE_REF=v0.1.0 - OPENSTACK_REF=v0.1.0 - LXD_REF=v0.1.0 - INCUS_REF=v0.1.0 - AWS_REF=v0.1.0 - GCP_REF=v0.1.0 - EQUINIX_REF=v0.1.0 - K8S_REF=v0.3.2 if [ "$GH_REF" == "main" ]; then + VERSION="nightly" AZURE_REF="main" OPENSTACK_REF="main" LXD_REF="main" @@ -66,12 +64,26 @@ jobs: AWS_REF="main" GCP_REF="main" EQUINIX_REF="main" + LINODE_REF="main" K8S_REF="main" - VERSION="nightly" + else + VERSION=$(git describe --tags --match='v[0-9]*' --always) + AZURE_REF=$(get_gh_latest_release cloudbase/garm-provider-azure) + OPENSTACK_REF=$(get_gh_latest_release cloudbase/garm-provider-openstack) + LXD_REF=$(get_gh_latest_release cloudbase/garm-provider-lxd) + INCUS_REF=$(get_gh_latest_release cloudbase/garm-provider-incus) + AWS_REF=$(get_gh_latest_release cloudbase/garm-provider-aws) + GCP_REF=$(get_gh_latest_release cloudbase/garm-provider-gcp) + EQUINIX_REF=$(get_gh_latest_release cloudbase/garm-provider-equinix) + LINODE_REF=$(get_gh_latest_release flatcar/garm-provider-linode) + K8S_REF=$(get_gh_latest_release mercedes-benz/garm-provider-k8s) fi if [ "$GH_REF" == "release/v1" ]; then VERSION="v0.1" fi + if [ "$GH_REF" == "release/v2" ]; then + VERSION="v0.2" + fi docker buildx build \ --provenance=false \ --platform linux/amd64,linux/arm64 \ diff --git a/Dockerfile b/Dockerfile index 47723a6bc..b7ff032b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ ARG K8S_REF=v0.3.2 LABEL stage=builder -RUN apk add musl-dev gcc libtool m4 autoconf g++ make libblkid util-linux-dev git linux-headers upx +RUN apk add --no-cache musl-dev gcc libtool m4 autoconf g++ make libblkid util-linux-dev git linux-headers upx RUN git config --global --add safe.directory /build ADD . /build/garm From 3687c7fea416c27e6b29fa932472f379338727d2 Mon Sep 17 00:00:00 2001 From: Lionel ORRY Date: Tue, 29 Jul 2025 09:48:53 +0200 Subject: [PATCH 03/11] activate release/v2 nightly build --- .github/workflows/trigger-nightly.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/trigger-nightly.yml b/.github/workflows/trigger-nightly.yml index 79c42228f..133d95ae8 100644 --- a/.github/workflows/trigger-nightly.yml +++ b/.github/workflows/trigger-nightly.yml @@ -8,6 +8,6 @@ jobs: uses: ./.github/workflows/build-and-push.yml strategy: matrix: - ref: ["main", "release/v1"] + ref: ["main", "release/v1", "release/v2"] with: ref: ${{ matrix.ref }} From 5152bab1b8840b13cbe6a87eeb6a3859b6430b2d Mon Sep 17 00:00:00 2001 From: Lionel ORRY Date: Tue, 29 Jul 2025 13:32:42 +0200 Subject: [PATCH 04/11] fix branch names --- .github/workflows/build-and-push.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml index 907dd8c1b..9a466c941 100644 --- a/.github/workflows/build-and-push.yml +++ b/.github/workflows/build-and-push.yml @@ -78,10 +78,10 @@ jobs: LINODE_REF=$(get_gh_latest_release flatcar/garm-provider-linode) K8S_REF=$(get_gh_latest_release mercedes-benz/garm-provider-k8s) fi - if [ "$GH_REF" == "release/v1" ]; then + if [ "$GH_REF" == "release/v0.1" ]; then VERSION="v0.1" fi - if [ "$GH_REF" == "release/v2" ]; then + if [ "$GH_REF" == "release/v0.2" ]; then VERSION="v0.2" fi docker buildx build \ From be3026e87ceee2266559d1aff2b0aca1f23f67c1 Mon Sep 17 00:00:00 2001 From: Lionel ORRY Date: Tue, 29 Jul 2025 13:33:22 +0200 Subject: [PATCH 05/11] fix branch names --- .github/workflows/trigger-nightly.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/trigger-nightly.yml b/.github/workflows/trigger-nightly.yml index 133d95ae8..b643129a5 100644 --- a/.github/workflows/trigger-nightly.yml +++ b/.github/workflows/trigger-nightly.yml @@ -8,6 +8,6 @@ jobs: uses: ./.github/workflows/build-and-push.yml strategy: matrix: - ref: ["main", "release/v1", "release/v2"] + ref: ["main", "release/v0.1", "release/v0.2"] with: ref: ${{ matrix.ref }} From af1c090db59f0444cba749239443a4434116fc35 Mon Sep 17 00:00:00 2001 From: Lionel ORRY Date: Wed, 30 Jul 2025 09:03:28 +0200 Subject: [PATCH 06/11] transfer providers branch computation inside Dockerfile --- .github/workflows/build-and-push.yml | 32 ---------- Dockerfile | 89 ++++++++++++++++------------ 2 files changed, 50 insertions(+), 71 deletions(-) diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml index 9a466c941..d6520e227 100644 --- a/.github/workflows/build-and-push.yml +++ b/.github/workflows/build-and-push.yml @@ -48,35 +48,11 @@ jobs: GH_REF: ${{ inputs.ref }} working-directory: src/github.com/cloudbase/garm run: | - get_gh_latest_release() { - curl -s -L -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - "https://api.github.com/repos/$1/latest" \ - | jq -r '.tag_name' - } set -x if [ "$GH_REF" == "main" ]; then VERSION="nightly" - AZURE_REF="main" - OPENSTACK_REF="main" - LXD_REF="main" - INCUS_REF="main" - AWS_REF="main" - GCP_REF="main" - EQUINIX_REF="main" - LINODE_REF="main" - K8S_REF="main" else VERSION=$(git describe --tags --match='v[0-9]*' --always) - AZURE_REF=$(get_gh_latest_release cloudbase/garm-provider-azure) - OPENSTACK_REF=$(get_gh_latest_release cloudbase/garm-provider-openstack) - LXD_REF=$(get_gh_latest_release cloudbase/garm-provider-lxd) - INCUS_REF=$(get_gh_latest_release cloudbase/garm-provider-incus) - AWS_REF=$(get_gh_latest_release cloudbase/garm-provider-aws) - GCP_REF=$(get_gh_latest_release cloudbase/garm-provider-gcp) - EQUINIX_REF=$(get_gh_latest_release cloudbase/garm-provider-equinix) - LINODE_REF=$(get_gh_latest_release flatcar/garm-provider-linode) - K8S_REF=$(get_gh_latest_release mercedes-benz/garm-provider-k8s) fi if [ "$GH_REF" == "release/v0.1" ]; then VERSION="v0.1" @@ -91,13 +67,5 @@ jobs: --label "org.opencontainers.image.description=GARM ${GH_REF}" \ --label "org.opencontainers.image.licenses=Apache 2.0" \ --build-arg="GARM_REF=${GH_REF}" \ - --build-arg="AZURE_REF=${AZURE_REF}" \ - --build-arg="OPENSTACK_REF=${OPENSTACK_REF}" \ - --build-arg="LXD_REF=${LXD_REF}" \ - --build-arg="INCUS_REF=${INCUS_REF}" \ - --build-arg="AWS_REF=${AWS_REF}" \ - --build-arg="GCP_REF=${GCP_REF}" \ - --build-arg="EQUINIX_REF=${EQUINIX_REF}" \ - --build-arg="K8S_REF=${K8S_REF}" \ -t ${PUSH_TO_PROJECT}/garm:"${VERSION}" \ --push . diff --git a/Dockerfile b/Dockerfile index b7ff032b7..f13eb35a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,49 +1,60 @@ FROM docker.io/golang:alpine AS builder ARG GARM_REF -ARG AZURE_REF=v0.1.0 -ARG OPENSTACK_REF=v0.1.0 -ARG LXD_REF=v0.1.0 -ARG INCUS_REF=v0.1.0 -ARG AWS_REF=v0.1.0 -ARG GCP_REF=v0.1.0 -ARG EQUINIX_REF=v0.1.0 -ARG K8S_REF=v0.3.2 LABEL stage=builder -RUN apk add --no-cache musl-dev gcc libtool m4 autoconf g++ make libblkid util-linux-dev git linux-headers upx -RUN git config --global --add safe.directory /build +RUN apk add --no-cache musl-dev gcc libtool m4 autoconf g++ make libblkid util-linux-dev git linux-headers upx curl jq +RUN git config --global --add safe.directory /build && git config --global --add advice.detachedHead false ADD . /build/garm -RUN cd /build/garm && git checkout ${GARM_REF} -RUN git clone --depth 1 --branch ${AZURE_REF} https://github.com/cloudbase/garm-provider-azure /build/garm-provider-azure -RUN git clone --depth 1 --branch ${OPENSTACK_REF} https://github.com/cloudbase/garm-provider-openstack /build/garm-provider-openstack -RUN git clone --depth 1 --branch ${LXD_REF} https://github.com/cloudbase/garm-provider-lxd /build/garm-provider-lxd -RUN git clone --depth 1 --branch ${INCUS_REF} https://github.com/cloudbase/garm-provider-incus /build/garm-provider-incus -RUN git clone --depth 1 --branch ${AWS_REF} https://github.com/cloudbase/garm-provider-aws /build/garm-provider-aws -RUN git clone --depth 1 --branch ${GCP_REF} https://github.com/cloudbase/garm-provider-gcp /build/garm-provider-gcp -RUN git clone --depth 1 --branch ${EQUINIX_REF} https://github.com/cloudbase/garm-provider-equinix /build/garm-provider-equinix - -RUN git clone --depth 1 --branch ${K8S_REF} https://github.com/mercedes-benz/garm-provider-k8s /build/garm-provider-k8s - -RUN cd /build/garm && go build -o /bin/garm \ - -tags osusergo,netgo,sqlite_omit_load_extension \ - -ldflags "-linkmode external -extldflags '-static' -s -w -X github.com/cloudbase/garm/util/appdefaults.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" \ - /build/garm/cmd/garm && upx /bin/garm -RUN cd /build/garm/cmd/garm-cli && go build -o /bin/garm-cli \ - -tags osusergo,netgo,sqlite_omit_load_extension \ - -ldflags "-linkmode external -extldflags '-static' -s -w -X github.com/cloudbase/garm/util/appdefaults.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" \ - . && upx /bin/garm-cli -RUN mkdir -p /opt/garm/providers.d -RUN cd /build/garm-provider-azure && go build -ldflags="-linkmode external -extldflags '-static' -s -w -X main.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" -o /opt/garm/providers.d/garm-provider-azure . && upx /opt/garm/providers.d/garm-provider-azure -RUN cd /build/garm-provider-openstack && go build -ldflags="-linkmode external -extldflags '-static' -s -w -X main.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" -o /opt/garm/providers.d/garm-provider-openstack . && upx /opt/garm/providers.d/garm-provider-openstack -RUN cd /build/garm-provider-lxd && go build -ldflags="-linkmode external -extldflags '-static' -s -w -X main.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" -o /opt/garm/providers.d/garm-provider-lxd . && upx /opt/garm/providers.d/garm-provider-lxd -RUN cd /build/garm-provider-incus && go build -ldflags="-linkmode external -extldflags '-static' -s -w -X main.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" -o /opt/garm/providers.d/garm-provider-incus . && upx /opt/garm/providers.d/garm-provider-incus -RUN cd /build/garm-provider-aws && go build -ldflags="-linkmode external -extldflags '-static' -s -w -X main.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" -o /opt/garm/providers.d/garm-provider-aws . && upx /opt/garm/providers.d/garm-provider-aws -RUN cd /build/garm-provider-gcp && go build -ldflags="-linkmode external -extldflags '-static' -s -w -X main.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" -o /opt/garm/providers.d/garm-provider-gcp . && upx /opt/garm/providers.d/garm-provider-gcp -RUN cd /build/garm-provider-equinix && go build -ldflags="-linkmode external -extldflags '-static' -s -w -X main.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" -o /opt/garm/providers.d/garm-provider-equinix . && upx /opt/garm/providers.d/garm-provider-equinix - -RUN cd /build/garm-provider-k8s/cmd/garm-provider-k8s && go build -ldflags="-linkmode external -extldflags '-static' -s -w" -o /opt/garm/providers.d/garm-provider-k8s . && upx /opt/garm/providers.d/garm-provider-k8s + +RUN cd /build/garm && git checkout ${GARM_REF} \ + && go build -o /bin/garm \ + -tags osusergo,netgo,sqlite_omit_load_extension \ + -ldflags "-linkmode external -extldflags '-static' -s -w -X github.com/cloudbase/garm/util/appdefaults.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" \ + /build/garm/cmd/garm && upx /bin/garm +RUN cd /build/garm/cmd/garm-cli \ + && go build -o /bin/garm-cli \ + -tags osusergo,netgo,sqlite_omit_load_extension \ + -ldflags "-linkmode external -extldflags '-static' -s -w -X github.com/cloudbase/garm/util/appdefaults.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" \ + . && upx /bin/garm-cli +RUN mkdir -p /opt/garm/providers.d; \ + for repo in \ + cloudbase/garm-provider-azure \ + cloudbase/garm-provider-openstack \ + cloudbase/garm-provider-lxd \ + cloudbase/garm-provider-incus \ + cloudbase/garm-provider-aws \ + cloudbase/garm-provider-gcp \ + cloudbase/garm-provider-equinix \ + flatcar/garm-provider-linode \ + mercedes-benz/garm-provider-k8s; \ + do \ + export PROVIDER_NAME="$(basename $repo)"; \ + export PROVIDER_SUBDIR=""; \ + if [ "$GARM_REF" == "main" ]; then \ + export PROVIDER_TAG="main"; \ + else \ + export PROVIDER_TAG="$(curl -s -L https://api.github.com/repos/$repo/releases/latest | jq -r '.tag_name')"; \ + fi; \ + case $PROVIDER_NAME in \ + "garm-provider-k8s") \ + export PROVIDER_TAG=v0.3.1; \ + export PROVIDER_SUBDIR="cmd/garm-provider-k8s"; \ + export PROVIDER_LDFLAGS="-linkmode external -extldflags \"-static\" -s -w"; \ + ;; \ + "garm-provider-linode") \ + export PROVIDER_LDFLAGS="-linkmode external -extldflags \"-static\" -s -w"; \ + ;; \ + *) \ + export PROVIDER_LDFLAGS="-linkmode external -extldflags \"-static\" -s -w -X main.Version=$PROVIDER_TAG"; \ + ;; \ + esac; \ + git clone --depth 1 --branch "$PROVIDER_TAG" "https://github.com/$repo" "/build/$PROVIDER_NAME" \ + && cd "/build/$PROVIDER_NAME/$PROVIDER_SUBDIR" \ + && go build -ldflags="$PROVIDER_LDFLAGS" -o /opt/garm/providers.d/$PROVIDER_NAME . \ + && upx /opt/garm/providers.d/$PROVIDER_NAME; \ + done FROM busybox From f6f22cb6864fcc395026e036337244f2fa066607 Mon Sep 17 00:00:00 2001 From: Lionel ORRY Date: Wed, 30 Jul 2025 09:23:55 +0200 Subject: [PATCH 07/11] small fixes --- .github/workflows/build-and-push.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml index d6520e227..3aa5bef65 100644 --- a/.github/workflows/build-and-push.yml +++ b/.github/workflows/build-and-push.yml @@ -48,7 +48,6 @@ jobs: GH_REF: ${{ inputs.ref }} working-directory: src/github.com/cloudbase/garm run: | - set -x if [ "$GH_REF" == "main" ]; then VERSION="nightly" else @@ -67,5 +66,5 @@ jobs: --label "org.opencontainers.image.description=GARM ${GH_REF}" \ --label "org.opencontainers.image.licenses=Apache 2.0" \ --build-arg="GARM_REF=${GH_REF}" \ - -t ${PUSH_TO_PROJECT}/garm:"${VERSION}" \ + -t ${REGISTRY_INPUT}/garm:"${VERSION}" \ --push . From 0f4f98dd03c2a7f3ceb96cfe81fb309cc6d28f29 Mon Sep 17 00:00:00 2001 From: Lionel ORRY Date: Wed, 30 Jul 2025 11:16:16 +0200 Subject: [PATCH 08/11] put a better git version in providers --- Dockerfile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index f13eb35a8..87d701e39 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,8 @@ RUN git config --global --add safe.directory /build && git config --global --add ADD . /build/garm -RUN cd /build/garm && git checkout ${GARM_REF} \ +RUN git -C /build/garm checkout ${GARM_REF} +RUN cd /build/garm \ && go build -o /bin/garm \ -tags osusergo,netgo,sqlite_omit_load_extension \ -ldflags "-linkmode external -extldflags '-static' -s -w -X github.com/cloudbase/garm/util/appdefaults.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" \ @@ -18,7 +19,8 @@ RUN cd /build/garm/cmd/garm-cli \ -tags osusergo,netgo,sqlite_omit_load_extension \ -ldflags "-linkmode external -extldflags '-static' -s -w -X github.com/cloudbase/garm/util/appdefaults.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" \ . && upx /bin/garm-cli -RUN mkdir -p /opt/garm/providers.d; \ +RUN set -e; \ + mkdir -p /opt/garm/providers.d; \ for repo in \ cloudbase/garm-provider-azure \ cloudbase/garm-provider-openstack \ @@ -37,20 +39,20 @@ RUN mkdir -p /opt/garm/providers.d; \ else \ export PROVIDER_TAG="$(curl -s -L https://api.github.com/repos/$repo/releases/latest | jq -r '.tag_name')"; \ fi; \ + git clone --branch "$PROVIDER_TAG" "https://github.com/$repo" "/build/$PROVIDER_NAME"; \ case $PROVIDER_NAME in \ "garm-provider-k8s") \ - export PROVIDER_TAG=v0.3.1; \ export PROVIDER_SUBDIR="cmd/garm-provider-k8s"; \ export PROVIDER_LDFLAGS="-linkmode external -extldflags \"-static\" -s -w"; \ + git -C /build/garm-provider-k8s checkout v0.3.1; \ ;; \ "garm-provider-linode") \ export PROVIDER_LDFLAGS="-linkmode external -extldflags \"-static\" -s -w"; \ ;; \ *) \ - export PROVIDER_LDFLAGS="-linkmode external -extldflags \"-static\" -s -w -X main.Version=$PROVIDER_TAG"; \ + export PROVIDER_LDFLAGS="-linkmode external -extldflags \"-static\" -s -w -X main.Version=$(git -C /build/$PROVIDER_NAME describe --tags --match='v[0-9]*' --dirty --always)"; \ ;; \ esac; \ - git clone --depth 1 --branch "$PROVIDER_TAG" "https://github.com/$repo" "/build/$PROVIDER_NAME" \ && cd "/build/$PROVIDER_NAME/$PROVIDER_SUBDIR" \ && go build -ldflags="$PROVIDER_LDFLAGS" -o /opt/garm/providers.d/$PROVIDER_NAME . \ && upx /opt/garm/providers.d/$PROVIDER_NAME; \ From eb07ed377437eb8b1d22f7b15f6949172829a1ad Mon Sep 17 00:00:00 2001 From: Lionel ORRY Date: Wed, 30 Jul 2025 11:29:00 +0200 Subject: [PATCH 09/11] remove obsolete tech debt --- Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 87d701e39..e0c672066 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,7 +44,6 @@ RUN set -e; \ "garm-provider-k8s") \ export PROVIDER_SUBDIR="cmd/garm-provider-k8s"; \ export PROVIDER_LDFLAGS="-linkmode external -extldflags \"-static\" -s -w"; \ - git -C /build/garm-provider-k8s checkout v0.3.1; \ ;; \ "garm-provider-linode") \ export PROVIDER_LDFLAGS="-linkmode external -extldflags \"-static\" -s -w"; \ @@ -53,7 +52,7 @@ RUN set -e; \ export PROVIDER_LDFLAGS="-linkmode external -extldflags \"-static\" -s -w -X main.Version=$(git -C /build/$PROVIDER_NAME describe --tags --match='v[0-9]*' --dirty --always)"; \ ;; \ esac; \ - && cd "/build/$PROVIDER_NAME/$PROVIDER_SUBDIR" \ + cd "/build/$PROVIDER_NAME/$PROVIDER_SUBDIR" \ && go build -ldflags="$PROVIDER_LDFLAGS" -o /opt/garm/providers.d/$PROVIDER_NAME . \ && upx /opt/garm/providers.d/$PROVIDER_NAME; \ done From 158b35db06c45b0880c48d1ec2bca87916cf9093 Mon Sep 17 00:00:00 2001 From: Lionel ORRY Date: Wed, 30 Jul 2025 14:35:01 +0200 Subject: [PATCH 10/11] simplify workflows --- .github/workflows/build-and-push.yml | 16 +++++----------- .github/workflows/trigger-nightly.yml | 5 +---- Dockerfile | 9 +++++---- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml index 3aa5bef65..4c520e4e0 100644 --- a/.github/workflows/build-and-push.yml +++ b/.github/workflows/build-and-push.yml @@ -42,22 +42,16 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push + - name: Build and push image env: - REGISTRY_INPUT: ${{ inputs.push_to_project }} + IMAGE_REGISTRY: ${{ inputs.push_to_project }} GH_REF: ${{ inputs.ref }} working-directory: src/github.com/cloudbase/garm run: | if [ "$GH_REF" == "main" ]; then - VERSION="nightly" + IMAGE_TAG="nightly" else - VERSION=$(git describe --tags --match='v[0-9]*' --always) - fi - if [ "$GH_REF" == "release/v0.1" ]; then - VERSION="v0.1" - fi - if [ "$GH_REF" == "release/v0.2" ]; then - VERSION="v0.2" + IMAGE_TAG=$(git describe --tags --match='v[0-9]*' --always) fi docker buildx build \ --provenance=false \ @@ -66,5 +60,5 @@ jobs: --label "org.opencontainers.image.description=GARM ${GH_REF}" \ --label "org.opencontainers.image.licenses=Apache 2.0" \ --build-arg="GARM_REF=${GH_REF}" \ - -t ${REGISTRY_INPUT}/garm:"${VERSION}" \ + -t ${IMAGE_REGISTRY}/garm:"${IMAGE_TAG}" \ --push . diff --git a/.github/workflows/trigger-nightly.yml b/.github/workflows/trigger-nightly.yml index b643129a5..e0b838560 100644 --- a/.github/workflows/trigger-nightly.yml +++ b/.github/workflows/trigger-nightly.yml @@ -6,8 +6,5 @@ on: jobs: call-build-and-push: uses: ./.github/workflows/build-and-push.yml - strategy: - matrix: - ref: ["main", "release/v0.1", "release/v0.2"] with: - ref: ${{ matrix.ref }} + ref: "main" diff --git a/Dockerfile b/Dockerfile index e0c672066..045581f6b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,11 +35,11 @@ RUN set -e; \ export PROVIDER_NAME="$(basename $repo)"; \ export PROVIDER_SUBDIR=""; \ if [ "$GARM_REF" == "main" ]; then \ - export PROVIDER_TAG="main"; \ + export PROVIDER_REF="main"; \ else \ - export PROVIDER_TAG="$(curl -s -L https://api.github.com/repos/$repo/releases/latest | jq -r '.tag_name')"; \ + export PROVIDER_REF="$(curl -s -L https://api.github.com/repos/$repo/releases/latest | jq -r '.tag_name')"; \ fi; \ - git clone --branch "$PROVIDER_TAG" "https://github.com/$repo" "/build/$PROVIDER_NAME"; \ + git clone --branch "$PROVIDER_REF" "https://github.com/$repo" "/build/$PROVIDER_NAME"; \ case $PROVIDER_NAME in \ "garm-provider-k8s") \ export PROVIDER_SUBDIR="cmd/garm-provider-k8s"; \ @@ -49,7 +49,8 @@ RUN set -e; \ export PROVIDER_LDFLAGS="-linkmode external -extldflags \"-static\" -s -w"; \ ;; \ *) \ - export PROVIDER_LDFLAGS="-linkmode external -extldflags \"-static\" -s -w -X main.Version=$(git -C /build/$PROVIDER_NAME describe --tags --match='v[0-9]*' --dirty --always)"; \ + export PROVIDER_VERSION=$(git -C /build/$PROVIDER_NAME describe --tags --match='v[0-9]*' --dirty --always); \ + export PROVIDER_LDFLAGS="-linkmode external -extldflags \"-static\" -s -w -X main.Version=$PROVIDER_VERSION"; \ ;; \ esac; \ cd "/build/$PROVIDER_NAME/$PROVIDER_SUBDIR" \ From 22f655f48db003e295ac64b502a0345235768139 Mon Sep 17 00:00:00 2001 From: Lionel ORRY Date: Thu, 31 Jul 2025 08:42:16 +0200 Subject: [PATCH 11/11] fixes after testing --- .github/workflows/build-and-push.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml index 4c520e4e0..93dd9a757 100644 --- a/.github/workflows/build-and-push.yml +++ b/.github/workflows/build-and-push.yml @@ -4,16 +4,14 @@ on: inputs: push_to_project: description: "Project to build images for" - required: true + required: false type: string default: "ghcr.io/cloudbase" ref: description: "Ref to build" - required: true + required: false type: string default: "main" - schedule: - - cron: "0 2 * * *" permissions: contents: read