diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index a49f589..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Build -on: - push: - branches: - - main - pull_request: - branches: - - main -jobs: - build: - 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 diff --git a/.github/workflows/release.yml b/.github/workflows/build_and_release.yml similarity index 62% rename from .github/workflows/release.yml rename to .github/workflows/build_and_release.yml index 9db3312..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 @@ -58,7 +93,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 }} @@ -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 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/.goreleaser.yaml b/.goreleaser.yaml index dc2893e..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,12 @@ archives: # use zip for windows archives format_overrides: - goos: windows - format: zip + formats: [ 'zip' ] + files: + - 'LICENSE*' + - 'README*' + - '**/*.rpm' + - '**/*.deb' changelog: sort: asc diff --git a/Makefile b/Makefile index 916f247..98e50ec 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" @@ -11,7 +12,32 @@ 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 . + +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 + @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 + +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 @@ -43,3 +69,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/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"] 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"] 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