From c014a4d7477a917cca72551a7a6d2ef08e41c479 Mon Sep 17 00:00:00 2001 From: Romain Gallet Date: Tue, 9 May 2023 17:44:52 +0200 Subject: [PATCH] Debian & Arch release pipeline (#9) Debian & Arch release pipeline (#9) --- .github/workflows/release.yml | 125 ++++++++++++++++++++++ .gitignore | 2 + Dockerfile | 23 +--- Makefile | 10 ++ build-aux/arch/kinesis-tailr-bin/PKGBUILD | 30 ++++++ build-aux/debian/control | 6 ++ build-aux/debian/postinst | 5 + docker-compose.yml | 8 ++ 8 files changed, 191 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 build-aux/arch/kinesis-tailr-bin/PKGBUILD create mode 100644 build-aux/debian/control create mode 100644 build-aux/debian/postinst create mode 100644 docker-compose.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f5ff330 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,125 @@ +on: + release: + types: + - created + +name: Continuous integration + +jobs: + ci: + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - 1.69.0 # MSRV + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Cache + uses: actions/cache@v2 + with: + path: | + ~/.cargo/release + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + - name: System dependencies + run: | + sudo apt-get update + sudo apt-get install -y sudo \ + make + + mkdir -p ~/.cargo/release + + - name: Rust toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + override: true + components: rustfmt, clippy + + - name: Build + uses: actions-rs/cargo@v1 + with: + command: build + + - name: Create Debian package + env: + DESTDIR: '~/kinesis-tailr-deb' + run: | + mkdir -p $DESTDIR + RELEASE_VERSION=${{ github.event.release.tag_name }} DESTDIR=$DESTDIR make debian-pkg + + - name: Upload Debian release + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: '${{ github.event.release.upload_url }}' + asset_path: 'kinesis-tailr-${{ github.event.release.tag_name }}-x86_64.deb' + asset_name: 'kinesis-tailr-${{ github.event.release.tag_name }}-x86_64.deb' + asset_content_type: application/octet-stream + + - name: Upload Debian release checksum + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: '${{ github.event.release.upload_url }}' + asset_path: 'kinesis-tailr-${{ github.event.release.tag_name }}-x86_64.deb.md5sum' + asset_name: 'kinesis-tailr-${{ github.event.release.tag_name }}-x86_64.deb.md5sum' + asset_content_type: text/plain + + arch: + runs-on: ubuntu-latest + needs: [ci] + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Prepare arch package metadata + run: | + wget https://github.com/grumlimited/kinesis-tailr/releases/download/${{ github.event.release.tag_name }}/kinesis-tailr-${{ github.event.release.tag_name }}-x86_64.deb -O build-aux/arch/kinesis-tailr-bin/kinesis-tailr-${{ github.event.release.tag_name }}-x86_64.deb + + MD5_SUM=$(md5sum build-aux/arch/kinesis-tailr-bin/kinesis-tailr-${{ github.event.release.tag_name }}-x86_64.deb | awk '{print $1}') + awk -v q="'" -v MD5_SUM=$MD5_SUM -i inplace 'BEGINFILE{print "md5sums=(" q MD5_SUM q ")"}{print}' build-aux/arch/kinesis-tailr-bin/PKGBUILD + awk -i inplace 'BEGINFILE{print "pkgver=${{ github.event.release.tag_name }}"}{print}' build-aux/arch/kinesis-tailr-bin/PKGBUILD + + - name: Validate PKGBUILD + id: validate-pkgbuild + uses: grumlimited/arch-pkgbuild-builder@b0f22da174699e6795f4434f252e15e6c8265b9e + with: + debug: true + target: pkgbuild + pkgname: build-aux/arch/kinesis-tailr-bin/ + + - name: Create arch package checksum file + run: | + sudo chown -R $USER . + md5sum build-aux/arch/kinesis-tailr-bin/*.zst >> build-aux/arch/kinesis-tailr-bin/kinesis-tailr-bin-${{ github.event.release.tag_name }}-1-x86_64.pkg.tar.zst.md5sum + + - name: Upload Arch Linux release + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: '${{ github.event.release.upload_url }}' + asset_path: 'build-aux/arch/kinesis-tailr-bin/kinesis-tailr-bin-${{ github.event.release.tag_name }}-1-x86_64.pkg.tar.zst' + asset_name: 'kinesis-tailr-bin-${{ github.event.release.tag_name }}-1-x86_64.pkg.tar.zst' + asset_content_type: application/octet-stream + + - name: Upload Arch Linux release checksum + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: '${{ github.event.release.upload_url }}' + asset_path: 'build-aux/arch/kinesis-tailr-bin/kinesis-tailr-bin-${{ github.event.release.tag_name }}-1-x86_64.pkg.tar.zst.md5sum' + asset_name: 'kinesis-tailr-bin-${{ github.event.release.tag_name }}-1-x86_64.pkg.tar.zst.md5sum' + asset_content_type: text/plain diff --git a/.gitignore b/.gitignore index 1cd74d2..bdc3b5f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ rpmbuild/RPMS rpmbuild/SRPMS +*.deb +*.md5sum diff --git a/Dockerfile b/Dockerfile index fe4d3a4..b2b9357 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,10 @@ -FROM amd64/centos:7 +FROM library/rust:1.69.0-slim-buster -ARG USER=grumlimited -ARG GROUP=grumlimited -ARG UID=1000 -ARG GID=1000 +RUN apt-get update && \ + apt-get install -y make sudo -ENV HOME=/home/$USER -# https://stackoverflow.com/questions/74345206/centos-7-docker-yum-installation-gets-stuck -RUN echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' > /etc/nsswitch.conf +WORKDIR /kinesis-tailr -RUN groupadd -g $GID $USER && \ - useradd $USER -d $HOME -g $GID -u $UID && \ - chown -R $USER:$GROUP $HOME +ENTRYPOINT ["make", "debian-pkg", "RELEASE_VERSION=0.1", "DESTDIR=build"] - -RUN ulimit -n 1024 && yum install -y epel-release -RUN ulimit -n 1024 && yum install -y epel-release && \ - yum update -y && \ - yum install -y rpm-build rust make cargo - -USER $USER diff --git a/Makefile b/Makefile index 00d0c15..cf39853 100644 --- a/Makefile +++ b/Makefile @@ -41,3 +41,13 @@ clean : uninstall : rm -f $(bindir)/$(NAME) + +debian-pkg : install + mkdir -p $(DESTDIR)/DEBIAN + cp build-aux/debian/control $(DESTDIR)/DEBIAN/ + echo "Version: $(RELEASE_VERSION)" >> $(DESTDIR)/DEBIAN/control + cp build-aux/debian/postinst $(DESTDIR)/DEBIAN/ + chmod 775 $(DESTDIR)/DEBIAN/postinst + dpkg-deb --build $(DESTDIR) kinesis-tailr-$(RELEASE_VERSION)-x86_64.deb + md5sum kinesis-tailr-$(RELEASE_VERSION)-x86_64.deb > kinesis-tailr-$(RELEASE_VERSION)-x86_64.deb.md5sum + diff --git a/build-aux/arch/kinesis-tailr-bin/PKGBUILD b/build-aux/arch/kinesis-tailr-bin/PKGBUILD new file mode 100644 index 0000000..09a1c7d --- /dev/null +++ b/build-aux/arch/kinesis-tailr-bin/PKGBUILD @@ -0,0 +1,30 @@ +# Maintainer: Romain Gallet +# Contributor: Romain Gallet +_packager="Romain Gallet " +_deb_pkgname=kinesis-tailr +pkgname=kinesis-tailr-bin +pkgrel=1 +pkgdesc='Kinesis tail tool' +arch=('x86_64') +url="https://github.com/grumlimited/$_deb_pkgname" +license=('GPLv3') +groups=() +depends=() +makedepends=() +checkdepends=() +optdepends=() +provides=() +replaces=() +backup=() +options=() +source=("$url/releases/download/$pkgver/$_deb_pkgname-$pkgver-$arch.deb") +noextract=() + +build() { + rm control.tar.zst + tar xvf data.tar.zst +} + +package() { + cp -fr usr/ ${pkgdir} +} diff --git a/build-aux/debian/control b/build-aux/debian/control new file mode 100644 index 0000000..1ac52b3 --- /dev/null +++ b/build-aux/debian/control @@ -0,0 +1,6 @@ +Package: kinesis-tailr +Section: development +Priority: optional +Architecture: all +Maintainer: rgallet_at_grumlimited.co.uk +Description: Kinesis tail tool diff --git a/build-aux/debian/postinst b/build-aux/debian/postinst new file mode 100644 index 0000000..0468cdc --- /dev/null +++ b/build-aux/debian/postinst @@ -0,0 +1,5 @@ +#!/bin/sh + +chmod +x /usr/bin/kinesis-tailr + +exit 0 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5c604ba --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +version: '3' +services: + rust: + build: . +# entrypoint: ['/bin/sleep', '60000'] + volumes: + - '.:/kinesis-tailr' + - '~/.cargo:/root/.cargo'