From c21f67253cfe84071666989db5b484b7879a41fd Mon Sep 17 00:00:00 2001 From: Enno Gotthold Date: Sun, 6 Apr 2025 20:15:04 +0200 Subject: [PATCH 1/6] Move Dockerfile to dedicated directory --- .github/workflows/release.yml | 2 +- Makefile | 2 +- packaging/docker/{ => production}/Dockerfile | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename packaging/docker/{ => production}/Dockerfile (100%) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9db3312..81d4772 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -58,7 +58,7 @@ jobs: uses: docker/build-push-action@v5 with: context: . - file: ./packaging/docker/Dockerfile + file: ./packaging/docker/production/Dockerfile push: ${{ env.PUSH_IMAGE }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/Makefile b/Makefile index 916f247..56665af 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ build: build-docker: @echo "building docker" - ${EXECUTOR} build -t cobbler/cli:latest -f packaging/docker/Dockerfile . + ${EXECUTOR} build -t cobbler/cli:latest -f packaging/docker/production/Dockerfile . clean: go clean diff --git a/packaging/docker/Dockerfile b/packaging/docker/production/Dockerfile similarity index 100% rename from packaging/docker/Dockerfile rename to packaging/docker/production/Dockerfile From e3d95cb918092a269a795e5a06f7fb920b25d773 Mon Sep 17 00:00:00 2001 From: Enno Gotthold Date: Sun, 6 Apr 2025 20:36:58 +0200 Subject: [PATCH 2/6] RPM: Add support for docker-based builds --- .github/workflows/build.yml | 19 ++++++++++++++- .gitignore | 5 ++++ Makefile | 15 ++++++++++++ .../docker/openSUSE_Tumbleweed/Dockerfile | 23 +++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 packaging/docker/openSUSE_Tumbleweed/Dockerfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a49f589..d890657 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,7 +7,7 @@ on: branches: - main jobs: - build: + native: strategy: matrix: go: [ '1.22', '1.23' ] @@ -24,3 +24,20 @@ jobs: run: make build - name: Execute CLI help run: ./cobbler --help + - name: Upload binary Artifact + uses: actions/upload-artifact@v4 + with: + name: cobbler-cli-binary-${{ matrix.go }}-${{ matrix.os }} + path: ./cobbler + rpm: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Build RPM + run: make build-rpm-docker + - name: Upload RPM Artifact + uses: actions/upload-artifact@v4 + with: + name: cobbler-cli-rpm + path: ./rpms/**/*.rpm diff --git a/.gitignore b/.gitignore index 96c5ae2..cbcd8a5 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,8 @@ testing/cobbler_source/ extracted_iso_image/ *.iso coverage.out + +# Packaging +/vendor/ +/rpms/ + diff --git a/Makefile b/Makefile index 56665af..82386b5 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ BINARY_NAME=cobbler EXECUTOR?=docker COBBLER_SERVER_URL=http://localhost:8081/cobbler_api TEST?=$$(go list ./... |grep -v 'vendor') +VERSION=0.0.1 build: @echo "building package" @@ -13,6 +14,18 @@ build-docker: @echo "building docker" ${EXECUTOR} build -t cobbler/cli:latest -f packaging/docker/production/Dockerfile . +build-rpm-docker: + @docker build -t localhost/cobbler-cli-pkg:opensuse-tumblewed -f packaging/docker/openSUSE_Tumbleweed/Dockerfile . + @docker run --rm -v $(CURDIR)/rpms/openSUSE_Tumbleweed:/root/rpmbuild/RPMS -v $(CURDIR):/workspace localhost/cobbler-cli-pkg:opensuse-tumblewed + +build-rpm: + @cp packaging/rpm/cobbler-cli.spec /root/rpmbuild/SPECS/cobbler-cli.spec + @cd ..; tar --exclude dist --exclude ".idea" --exclude ubuntu-20.04.1-legacy-server-amd64.iso --exclude extracted_iso_image --transform="s/workspace/cobbler-cli-${VERSION}/" -zcvf "cobbler-cli-${VERSION}.tar.gz" /workspace + @mv ../cobbler-cli-${VERSION}.tar.gz /root/rpmbuild/SOURCES + @go mod vendor; tar -zcvf "vendor.tar.gz" vendor; mv vendor.tar.gz /root/rpmbuild/SOURCES + @rpmbuild --define "_topdir /root/rpmbuild" \ + --bb /root/rpmbuild/SPECS/cobbler-cli.spec + clean: go clean rm -f ${BINARY_NAME} @@ -43,3 +56,5 @@ shell_completions: ./${BINARY_NAME} completion fish > config/completions/fish/cobbler ./${BINARY_NAME} completion powershell > config/completions/powershell/cobbler ./${BINARY_NAME} completion zsh > config/completions/zsh/cobbler + +.PHONY: build build-docker build-rpm-docker build-rpm clean cleandoc doc run test shell_completions diff --git a/packaging/docker/openSUSE_Tumbleweed/Dockerfile b/packaging/docker/openSUSE_Tumbleweed/Dockerfile new file mode 100644 index 0000000..cd0224f --- /dev/null +++ b/packaging/docker/openSUSE_Tumbleweed/Dockerfile @@ -0,0 +1,23 @@ +# vim: ft=dockerfile +# hadolint ignore=DL3006 +FROM opensuse/tumbleweed + +# Create work directory +WORKDIR /workspace +VOLUME /workspace + +# Install required dependencies +RUN zypper -n --gpg-auto-import-keys refresh && \ + zypper -n install \ + rpm-build \ + go \ + bash-completion \ + zsh \ + fish \ + git \ + fdupes + +# Set up RPM build directories +RUN mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS} + +ENTRYPOINT ["make", "build-rpm"] From 2cd81ab3befd597b0270279c3c787f1148e5e10d Mon Sep 17 00:00:00 2001 From: Enno Gotthold Date: Sun, 6 Apr 2025 21:16:39 +0200 Subject: [PATCH 3/6] DEB: Add support for docker-based builds --- .github/workflows/build.yml | 14 ++++++++++++++ Makefile | 13 +++++++++++++ packaging/deb/debian.rules | 8 ++++---- packaging/docker/Debian_12/Dockerfile | 27 +++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 packaging/docker/Debian_12/Dockerfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d890657..14c79ca 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,3 +41,17 @@ jobs: with: name: cobbler-cli-rpm path: ./rpms/**/*.rpm + deb: + # This will fail until Debian 13 will arrive with a newer golang version + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Build DEB + continue-on-error: true + run: make build-deb-docker + - name: Upload DEB Artifact + uses: actions/upload-artifact@v4 + with: + name: cobbler-cli-deb + path: ./debs/**/*.deb diff --git a/Makefile b/Makefile index 82386b5..98e50ec 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,10 @@ build-rpm-docker: @docker build -t localhost/cobbler-cli-pkg:opensuse-tumblewed -f packaging/docker/openSUSE_Tumbleweed/Dockerfile . @docker run --rm -v $(CURDIR)/rpms/openSUSE_Tumbleweed:/root/rpmbuild/RPMS -v $(CURDIR):/workspace localhost/cobbler-cli-pkg:opensuse-tumblewed +build-deb-docker: + @docker build -t localhost/cobbler-cli-pkg:debian-12 -f packaging/docker/Debian_12/Dockerfile . + @docker run --rm -v $(CURDIR)/debs/Debian_12:/usr/src/cobbler-cli/deb-build -v $(CURDIR):/workspace localhost/cobbler-cli-pkg:debian-12 + build-rpm: @cp packaging/rpm/cobbler-cli.spec /root/rpmbuild/SPECS/cobbler-cli.spec @cd ..; tar --exclude dist --exclude ".idea" --exclude ubuntu-20.04.1-legacy-server-amd64.iso --exclude extracted_iso_image --transform="s/workspace/cobbler-cli-${VERSION}/" -zcvf "cobbler-cli-${VERSION}.tar.gz" /workspace @@ -26,6 +30,15 @@ build-rpm: @rpmbuild --define "_topdir /root/rpmbuild" \ --bb /root/rpmbuild/SPECS/cobbler-cli.spec +build-deb: + @mkdir debian; cp -r packaging/deb/* debian/ + @cd debian; rename "s/debian\.//" * + @go mod vendor; tar -zcvf "vendor.tar.gz" vendor; mv vendor.tar.gz debian/; rm -r vendor + @cd debian; tar -xvzf vendor.tar.gz + @debuild -us -uc + @rm -r debian + @cp ../cobbler-cli_* /usr/src/cobbler-cli/deb-build + clean: go clean rm -f ${BINARY_NAME} diff --git a/packaging/deb/debian.rules b/packaging/deb/debian.rules index 3a834e3..9ade926 100644 --- a/packaging/deb/debian.rules +++ b/packaging/deb/debian.rules @@ -6,11 +6,11 @@ export PATH := /usr/lib/go/bin:$(PATH) export CGO_ENABLED = 0 %: - dh $@ --with=bash-completion + dh $@ --with=bash-completion override_dh_auto_build: - @mv debian/vendor . - dh_auto_build + @mv debian/vendor . + dh_auto_build override_dh_auto_test: - @echo "Integrations-Tests disabled during build" + @echo "Integrations-Tests disabled during build" diff --git a/packaging/docker/Debian_12/Dockerfile b/packaging/docker/Debian_12/Dockerfile new file mode 100644 index 0000000..d44c948 --- /dev/null +++ b/packaging/docker/Debian_12/Dockerfile @@ -0,0 +1,27 @@ +# vim: ft=dockerfile +FROM docker.io/library/debian:12 + +ENV DEBIAN_FRONTEND=noninteractive + +# Create work directory +WORKDIR /workspace +VOLUME /workspace + +# hadolint ignore=DL3008 +RUN apt-get update -qq && \ + apt-get install --no-install-recommends -qqy \ + build-essential \ + debhelper \ + devscripts \ + dh-python \ + rename \ + git \ + bash-completion \ + golang-go && \ + apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +# Make directory for debs +RUN mkdir -p /usr/src/cobbler-cli/deb-build +VOLUME /usr/src/cobbler-cli/deb-build + +ENTRYPOINT ["make", "build-deb"] From ef975333ee3429df4be012141f4259eb2fcfcc6f Mon Sep 17 00:00:00 2001 From: Enno Gotthold Date: Sun, 6 Apr 2025 21:26:07 +0200 Subject: [PATCH 4/6] CI: Combine build and release workflows --- .github/workflows/build.yml | 57 ------------- .../{release.yml => build_and_release.yml} | 80 +++++++++++++++---- 2 files changed, 63 insertions(+), 74 deletions(-) delete mode 100644 .github/workflows/build.yml rename .github/workflows/{release.yml => build_and_release.yml} (63%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 14c79ca..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: Build -on: - push: - branches: - - main - pull_request: - branches: - - main -jobs: - native: - strategy: - matrix: - go: [ '1.22', '1.23' ] - os: [ubuntu-latest, macos-latest, windows-latest] - runs-on: ${{ matrix.os }} - steps: - - name: Install Go ${{ matrix.go }} - uses: actions/setup-go@v2 - with: - go-version: ${{ matrix.go }} - - name: Checkout code - uses: actions/checkout@v2 - - name: Build project - run: make build - - name: Execute CLI help - run: ./cobbler --help - - name: Upload binary Artifact - uses: actions/upload-artifact@v4 - with: - name: cobbler-cli-binary-${{ matrix.go }}-${{ matrix.os }} - path: ./cobbler - rpm: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 - - name: Build RPM - run: make build-rpm-docker - - name: Upload RPM Artifact - uses: actions/upload-artifact@v4 - with: - name: cobbler-cli-rpm - path: ./rpms/**/*.rpm - deb: - # This will fail until Debian 13 will arrive with a newer golang version - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 - - name: Build DEB - continue-on-error: true - run: make build-deb-docker - - name: Upload DEB Artifact - uses: actions/upload-artifact@v4 - with: - name: cobbler-cli-deb - path: ./debs/**/*.deb diff --git a/.github/workflows/release.yml b/.github/workflows/build_and_release.yml similarity index 63% rename from .github/workflows/release.yml rename to .github/workflows/build_and_release.yml index 81d4772..78630a8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/build_and_release.yml @@ -1,21 +1,9 @@ -# This GitHub action can publish assets for release when a tag is created. -# Currently its setup to run on any tag that matches the pattern "v*" (ie. v0.1.0). -# -# This uses an action (paultyng/ghaction-import-gpg) that assumes you set your -# private key in the `GPG_PRIVATE_KEY` secret and passphrase in the `PASSPHRASE` -# secret. If you would rather own your own GPG handling, please fork this action -# or use an alternative one for key handling. -# -# You will need to pass the `--batch` flag to `gpg` in your signing step -# in `goreleaser` to indicate this is being used in a non-interactive mode. -# - -name: release +name: Build & Release on: - pull_request: + push: branches: - main - push: + pull_request: branches: - main tags: @@ -25,8 +13,55 @@ permissions: contents: write jobs: - push_to_registry: - name: Push Docker image to GHCR + native: + strategy: + matrix: + go: [ '1.22', '1.23' ] + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Install Go ${{ matrix.go }} + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + - name: Checkout code + uses: actions/checkout@v2 + - name: Build project + run: make build + - name: Execute CLI help + run: ./cobbler --help + - name: Upload binary Artifact + uses: actions/upload-artifact@v4 + with: + name: cobbler-cli-binary-${{ matrix.go }}-${{ matrix.os }} + path: ./cobbler + rpm: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Build RPM + run: make build-rpm-docker + - name: Upload RPM Artifact + uses: actions/upload-artifact@v4 + with: + name: cobbler-cli-native-rpm + path: ./rpms/**/*.rpm + deb: + # This will fail until Debian 13 will arrive with a newer golang version + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Build DEB + continue-on-error: true + run: make build-deb-docker + - name: Upload DEB Artifact + uses: actions/upload-artifact@v4 + with: + name: cobbler-cli-native-deb + path: ./debs/**/*.deb + docker: runs-on: ubuntu-latest env: REGISTRY: ghcr.io @@ -71,6 +106,11 @@ jobs: push-to-registry: ${{ env.PUSH_IMAGE }} goreleaser: runs-on: ubuntu-latest + needs: + - native + - docker + - deb + - rpm steps: - name: Checkout # https://github.com/actions/checkout @@ -80,6 +120,12 @@ jobs: - name: Set up Go # https://github.com/actions/setup-go uses: actions/setup-go@v5 + - name: Download all artifacts + # https://github.com/actions/download-artifact + id: download-artifact + uses: actions/download-artifact@v4 + with: + pattern: "cobbler-cli-native-*" - name: Import GPG key # https://github.com/crazy-max/ghaction-import-gpg id: import_gpg From 2ebfdbe76291fb71b5ed1c9cc63b465454c105be Mon Sep 17 00:00:00 2001 From: Enno Gotthold Date: Sun, 6 Apr 2025 21:41:06 +0200 Subject: [PATCH 5/6] CI: Include DEB and RPM in goreleaser --- .goreleaser.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index dc2893e..957543e 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -35,6 +35,11 @@ archives: format_overrides: - goos: windows format: zip + files: + - 'LICENSE*' + - 'README*' + - '**/*.rpm' + - '**/*.deb' changelog: sort: asc From 6cf8fe0f073a86f6005820aff58dc5dd5440b317 Mon Sep 17 00:00:00 2001 From: Enno Gotthold Date: Sun, 6 Apr 2025 21:58:12 +0200 Subject: [PATCH 6/6] CI: Fix deprecated options --- .goreleaser.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 957543e..013a567 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -22,7 +22,7 @@ builds: - darwin archives: - - format: tar.gz + - formats: [ 'tar.gz' ] # this name template makes the OS and Arch compatible with the results of `uname`. name_template: >- {{ .ProjectName }}_ @@ -34,7 +34,7 @@ archives: # use zip for windows archives format_overrides: - goos: windows - format: zip + formats: [ 'zip' ] files: - 'LICENSE*' - 'README*'