Merge pull request #456 from chickenkiller/feat/refactor-builds

Refactor CI/CD builds
This commit is contained in:
Gabriel 2025-07-31 10:58:16 +03:00 committed by GitHub
commit 8082e1a30e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 97 additions and 81 deletions

View file

@ -1,17 +1,17 @@
name: "Build GARM images" name: "Build and push GARM images"
on: on:
workflow_dispatch: workflow_call:
inputs: inputs:
push_to_project: push_to_project:
description: "Project to build images for" description: "Project to build images for"
required: true required: false
type: string
default: "ghcr.io/cloudbase" default: "ghcr.io/cloudbase"
ref: ref:
description: "Ref to build" description: "Ref to build"
required: true required: false
type: string
default: "main" default: "main"
schedule:
- cron: "0 2 * * *"
permissions: permissions:
contents: read contents: read
@ -24,8 +24,9 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: "Checkout" - name: "Checkout"
uses: actions/checkout@v3 uses: actions/checkout@v4
with: with:
ref: ${{ inputs.ref }}
path: src/github.com/cloudbase/garm path: src/github.com/cloudbase/garm
fetch-depth: 0 fetch-depth: 0
@ -39,35 +40,16 @@ jobs:
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push - name: Build and push image
env:
IMAGE_REGISTRY: ${{ inputs.push_to_project }}
GH_REF: ${{ inputs.ref }}
working-directory: src/github.com/cloudbase/garm
run: | 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
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 if [ "$GH_REF" == "main" ]; then
AZURE_REF="main" IMAGE_TAG="nightly"
OPENSTACK_REF="main" else
LXD_REF="main" IMAGE_TAG=$(git describe --tags --match='v[0-9]*' --always)
INCUS_REF="main"
AWS_REF="main"
GCP_REF="main"
EQUINIX_REF="main"
K8S_REF="main"
VERSION="nightly"
fi fi
docker buildx build \ docker buildx build \
--provenance=false \ --provenance=false \
@ -76,13 +58,5 @@ jobs:
--label "org.opencontainers.image.description=GARM ${GH_REF}" \ --label "org.opencontainers.image.description=GARM ${GH_REF}" \
--label "org.opencontainers.image.licenses=Apache 2.0" \ --label "org.opencontainers.image.licenses=Apache 2.0" \
--build-arg="GARM_REF=${GH_REF}" \ --build-arg="GARM_REF=${GH_REF}" \
--build-arg="AZURE_REF=${AZURE_REF}" \ -t ${IMAGE_REGISTRY}/garm:"${IMAGE_TAG}" \
--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 . --push .

19
.github/workflows/trigger-manual.yml vendored Normal file
View file

@ -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 }}

10
.github/workflows/trigger-nightly.yml vendored Normal file
View file

@ -0,0 +1,10 @@
name: Nightly build of GARM images
on:
schedule:
- cron: "0 2 * * *"
jobs:
call-build-and-push:
uses: ./.github/workflows/build-and-push.yml
with:
ref: "main"

View file

@ -1,49 +1,62 @@
FROM docker.io/golang:alpine AS builder FROM docker.io/golang:alpine AS builder
ARG GARM_REF 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 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 curl jq
RUN git config --global --add safe.directory /build RUN git config --global --add safe.directory /build && git config --global --add advice.detachedHead false
ADD . /build/garm 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 git -C /build/garm checkout ${GARM_REF}
RUN cd /build/garm \
RUN cd /build/garm && go build -o /bin/garm \ && go build -o /bin/garm \
-tags osusergo,netgo,sqlite_omit_load_extension \ -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)" \ -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 /build/garm/cmd/garm && upx /bin/garm
RUN cd /build/garm/cmd/garm-cli && go build -o /bin/garm-cli \ RUN cd /build/garm/cmd/garm-cli \
-tags osusergo,netgo,sqlite_omit_load_extension \ && go build -o /bin/garm-cli \
-ldflags "-linkmode external -extldflags '-static' -s -w -X github.com/cloudbase/garm/util/appdefaults.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" \ -tags osusergo,netgo,sqlite_omit_load_extension \
. && upx /bin/garm-cli -ldflags "-linkmode external -extldflags '-static' -s -w -X github.com/cloudbase/garm/util/appdefaults.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" \
RUN mkdir -p /opt/garm/providers.d . && upx /bin/garm-cli
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 set -e; \
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 mkdir -p /opt/garm/providers.d; \
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 for repo in \
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 cloudbase/garm-provider-azure \
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 cloudbase/garm-provider-openstack \
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 cloudbase/garm-provider-lxd \
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 cloudbase/garm-provider-incus \
cloudbase/garm-provider-aws \
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 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_REF="main"; \
else \
export PROVIDER_REF="$(curl -s -L https://api.github.com/repos/$repo/releases/latest | jq -r '.tag_name')"; \
fi; \
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"; \
export PROVIDER_LDFLAGS="-linkmode external -extldflags \"-static\" -s -w"; \
;; \
"garm-provider-linode") \
export PROVIDER_LDFLAGS="-linkmode external -extldflags \"-static\" -s -w"; \
;; \
*) \
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" \
&& go build -ldflags="$PROVIDER_LDFLAGS" -o /opt/garm/providers.d/$PROVIDER_NAME . \
&& upx /opt/garm/providers.d/$PROVIDER_NAME; \
done
FROM busybox FROM busybox