From 4e162d19494bf0839001ce6313a0bf456deb7ffd Mon Sep 17 00:00:00 2001 From: askiiart <dev@askiiart.net> Date: Thu, 6 Mar 2025 13:09:47 -0600 Subject: [PATCH 1/8] initial commit --- .drone.yml | 17 +++++++++++++++++ README.md | 17 +++++++++++++++++ compilation.sh | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 .drone.yml create mode 100644 README.md create mode 100755 compilation.sh diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..22cc171 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,17 @@ +kind: pipeline +type: docker +name: default + +steps: + - name: Build cavif + image: debian + commands: + - '/drone/src/compilation.sh' + volumes: + - name: program-archives + path: /compiled + +volumes: + - name: program-archives + host: + path: /mnt/user/files/repos/archives \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..8029025 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# Cavif build + +- Builds [cavif](https://github.com/kornelski/cavif-rs) and places it in `$COMPILED_DIR/cavif/cavif.tar.zst` +- Version file at `$COMPILED_DIR/cavif/version` + +## Archive details + +``` +. +├── cavif +``` + +Recommended: + +| File | Location | Permissions | +| --------------- | -------------------------------------- | ----------- | +| `./cavif` | `/usr/bin/cavif` | 755 | diff --git a/compilation.sh b/compilation.sh new file mode 100755 index 0000000..5e53112 --- /dev/null +++ b/compilation.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +set -euo pipefail + +workdir=$(mktemp -d) +built_dir=${COMPILED_DIR:-/compiled}/cavif +mkdir -p $built_dir +version_file=$built_dir/version +touch $version_file + +apt update +apt install curl jq -y + +# clone and check whether it's up-to-date +mkdir -p $workdir/cavif/ +cd $workdir/cavif/ +# check version +version=$(curl -L 'https://crates.io/api/v1/crates/cavif' | jq '.crate.default_version' -r) +if grep -q $version $version_file; then + echo "already up to date, exiting" + exit +fi +# get build deps +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y +. ~/.cargo/env +apt install gcc nasm -y + +# build cavif +cargo install cavif +cp ~/.cargo/bin/cavif $workdir/cavif/ + +# crate .tar.zst archive +cd $workdir/cavif/ +mkdir -p ${COMPILED_DIR:-/compiled}/cavif/ +apt install zstd -y +tar --zstd -cf $built_dir/cavif.tar.zst . +echo $version >$version_file + +echo "cavif updated to $version" From fa3eb288476368738f5b943dc7e42b005bd9c08d Mon Sep 17 00:00:00 2001 From: askiiart <dev@askiiart.net> Date: Thu, 6 Mar 2025 13:30:17 -0600 Subject: [PATCH 2/8] initial commit --- .drone.yml | 26 ++++++++++++++++++++++++++ README.md | 10 ++++++++++ cavif.spec | 29 +++++++++++++++++++++++++++++ run.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 .drone.yml create mode 100644 README.md create mode 100644 cavif.spec create mode 100644 run.sh diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..e3944ce --- /dev/null +++ b/.drone.yml @@ -0,0 +1,26 @@ +kind: pipeline +type: docker +name: default + +environment: + RPM_PACKAGER_NAME: 'askiiart' + RPM_PACKAGER_EMAIL: 'rpm@askiiart.net' + +steps: + - name: Build cavif fedora package + image: fedora + commands: + - '/drone/src/run.sh' + volumes: + - name: program-archives + path: /compiled + - name: fedora-repo + path: /repo + +volumes: + - name: program-archives + host: + path: /mnt/user/files/repos/archives/ + - name: fedora-repo + host: + path: /mnt/user/files/repos/fedora/x86_64/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..b430908 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# Cavif (fedora) + +TODO: Add proper changelog updates + +## Environment variables + +**REQUIRED** + +- RPM packager name - `RPM_PACKAGER_NAME` +- RPM packager email - `RPM_PACKAGER_EMAIL` diff --git a/cavif.spec b/cavif.spec new file mode 100644 index 0000000..41e6a9a --- /dev/null +++ b/cavif.spec @@ -0,0 +1,29 @@ +Name: cavif +Version: 6.6.6 +Release: %autorelease +Summary: AVIF image creator in pure Rust + +License: BSD-3-Clause +URL: https://github.com/kornelski/cavif-rs + +BuildRequires: tar zstd + +%description +An AVIF image creator in pure Rust + +%prep +mkdir ./cavif/ +cd ./cavif/ +tar --zstd -xf ${COMPILED_DIR:-/compiled}/cavif/cavif.tar.zst + +%install +cd ./cavif/ +mkdir -p %{buildroot}%{_bindir} +install -Dm755 ./cavif %{buildroot}%{_bindir}/cavif + +%files +%{_bindir}/cavif + +%changelog +* DATE_HERE RPM_PACKAGER_NAME <RPM_PACKAGER_EMAIL> +- CHANGELOG_MESSAGE_HERE \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..530e820 --- /dev/null +++ b/run.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +set -euo pipefail + +built_dir=${COMPILED_DIR:-/compiled}/cavif +version=$(cat $built_dir/version) +repo_dir=${REPO_DIR:-/repo} + +# skip if already up-to-date +# TODO: use the repo instead and check the version with dnf +# yeah this is bad; see also the cavif-aaaaaa thing below +touch cavif-tmp +if $(ls $repo_dir/cavif-* | grep -q "$version"); then + rm cavif-tmp + echo "package is already up to date, exiting" + exit +fi +rm cavif-tmp + +# prep +dnf install fedora-packager rpmdevtools createrepo_c -y +rpmdev-setuptree + +# update spec file +sed -i "s/Version:.*/Version: $version/g" cavif.spec +sed -i "s/DATE_HERE/$(date '+%a %b %d %Y')/g" cavif.spec +sed -i "s/CHANGELOG_MESSAGE_HERE/Update to $version/g" cavif.spec +sed -i "s/RPM_PACKAGER_NAME/$RPM_PACKAGER_NAME/g" cavif.spec +sed -i "s/RPM_PACKAGER_EMAIL/$RPM_PACKAGER_EMAIL/g" cavif.spec + +# build package and move to the repo +rpmbuild -bb cavif.spec +mv ~/rpmbuild/RPMS/x86_64/cavif-$version-* $repo_dir/ + +# remove old versions +cd $repo_dir +# this is the easiest way to make sure it doesn't just fail because no cavif-* exists +# (which only happens on first run) +touch cavif-aaaaaa.rpm +rm $(ls cavif-*.rpm | sort --version-sort | sed '$d') +rm cavif-aaaaaa.rpm + +# update repo +createrepo_c . + +echo "package is at $repo_dir/$(ls $repo_dir/cavif-*.rpm)" From bdca60f939b3a75ae0a71c133f8f3c5a17b9ec68 Mon Sep 17 00:00:00 2001 From: askiiart <dev@askiiart.net> Date: Thu, 6 Mar 2025 13:31:27 -0600 Subject: [PATCH 3/8] fix perms --- run.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 run.sh diff --git a/run.sh b/run.sh old mode 100644 new mode 100755 From eb8a8cf166d4fe7e2f63bc6c26d4df6a51876519 Mon Sep 17 00:00:00 2001 From: askiiart <dev@askiiart.net> Date: Thu, 6 Mar 2025 13:34:32 -0600 Subject: [PATCH 4/8] fix this --- run.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/run.sh b/run.sh index 530e820..e4966b1 100755 --- a/run.sh +++ b/run.sh @@ -8,13 +8,13 @@ repo_dir=${REPO_DIR:-/repo} # skip if already up-to-date # TODO: use the repo instead and check the version with dnf # yeah this is bad; see also the cavif-aaaaaa thing below -touch cavif-tmp +touch $repo_dir/cavif-tmp if $(ls $repo_dir/cavif-* | grep -q "$version"); then - rm cavif-tmp + rm $repo_dir/cavif-tmp echo "package is already up to date, exiting" exit fi -rm cavif-tmp +rm $repo_dir/cavif-tmp # prep dnf install fedora-packager rpmdevtools createrepo_c -y From e49b6361d28cc91a7d07df019f6872651b179d37 Mon Sep 17 00:00:00 2001 From: askiiart <dev@askiiart.net> Date: Thu, 6 Mar 2025 13:41:24 -0600 Subject: [PATCH 5/8] enable debug --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index e4966b1..9b358fc 100755 --- a/run.sh +++ b/run.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -euo pipefail +set -euxo pipefail built_dir=${COMPILED_DIR:-/compiled}/cavif version=$(cat $built_dir/version) From 23ab1b4c69852665f4be86ed2cb8285831b2878c Mon Sep 17 00:00:00 2001 From: askiiart <dev@askiiart.net> Date: Thu, 6 Mar 2025 13:46:21 -0600 Subject: [PATCH 6/8] fix sorting for sementic versioning --- run.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run.sh b/run.sh index 9b358fc..dcdcd00 100755 --- a/run.sh +++ b/run.sh @@ -35,9 +35,9 @@ mv ~/rpmbuild/RPMS/x86_64/cavif-$version-* $repo_dir/ cd $repo_dir # this is the easiest way to make sure it doesn't just fail because no cavif-* exists # (which only happens on first run) -touch cavif-aaaaaa.rpm +touch cavif-0.rpm rm $(ls cavif-*.rpm | sort --version-sort | sed '$d') -rm cavif-aaaaaa.rpm +rm cavif-0.rpm # update repo createrepo_c . From 2303f9905b1157391b215409e9e69c507be7c973 Mon Sep 17 00:00:00 2001 From: askiiart <dev@askiiart.net> Date: Thu, 6 Mar 2025 13:47:35 -0600 Subject: [PATCH 7/8] disable debug --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index dcdcd00..d20edc2 100755 --- a/run.sh +++ b/run.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -euxo pipefail +set -euo pipefail built_dir=${COMPILED_DIR:-/compiled}/cavif version=$(cat $built_dir/version) From b37191657c510f5f1f077dfd898908c420d70ff1 Mon Sep 17 00:00:00 2001 From: askiiart <dev@askiiart.net> Date: Thu, 6 Mar 2025 13:52:39 -0600 Subject: [PATCH 8/8] add error handling in case this is the first run --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index d20edc2..eab01a4 100755 --- a/run.sh +++ b/run.sh @@ -37,7 +37,7 @@ cd $repo_dir # (which only happens on first run) touch cavif-0.rpm rm $(ls cavif-*.rpm | sort --version-sort | sed '$d') -rm cavif-0.rpm +rm cavif-0.rpm || true # update repo createrepo_c .