Skip to content

Commit

Permalink
Tools to build deb and rpm packages
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborcsardi committed Sep 1, 2023
1 parent 3d4182c commit 2e1d76d
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 28 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ jobs:
if: success()
with:
name: rig-linux-x86_64
path: 'rig-*.tar.gz'
path: |
rig-*.tar.gz
rig-*_amd64.deb
rig-*.x86_64.rpm
linux-tests-x86_64-setup:
needs: linux-build-x86_64
Expand Down Expand Up @@ -146,7 +149,10 @@ jobs:
if: success()
with:
name: rig-linux-aarch64
path: 'rig-*.tar.gz'
path: |
rig-*.tar.gz
rig-*_arm64.deb
rig-*.aarch64.rpm
linux-tests-aarch64-setup:
needs: linux-build-aarch64
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ _rim.ps1
/tests/results
/build
/rig-*.tar.gz
/*.deb
/*.rpm
14 changes: 10 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ RUN cd openssl-* && \
rm -rf /usr/local/bin/openssl \
/usr/local/share/{man/doc}

# install rust toolchain for 'rig' user ===================================
# install rust toolchain for 'rigbuild' user ==============================

RUN adduser rig -D
USER rig
RUN adduser rigbuild -D
USER rigbuild
RUN cd && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o rust.sh && sh rust.sh -y
USER root
ENV PATH="/home/rig/.cargo/bin:$PATH"
ENV PATH="/home/rigbuild/.cargo/bin:$PATH"
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT [ "sh", "/entrypoint.sh" ]
Expand All @@ -39,3 +39,9 @@ ENTRYPOINT [ "sh", "/entrypoint.sh" ]

RUN mkdir /work
WORKDIR /work

# packageer ===============================================================

RUN curl -LO https://github.com/goreleaser/nfpm/releases/download/v2.32.0/nfpm_2.32.0_$(arch).apk && \
apk add --allow-untrusted nfpm*.apk && \
rm nfpm*.apk
50 changes: 36 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@ gsudo.exe:

# -------------------------------------------------------------------------

ifeq "$(DOCKER_DEFAULT_PLATFORM)" ""
DOCKER_ARCH :=
else
DOCKER_ARCH := --platform=$(DOCKER_DEFAULT_PLATFORM)
endif

linux: export OPENSSL_DIR = /usr/local/
linux: export OPENSSL_INCLUDE_DIR = /usr/local/include/
linux: export OPENSSL_LIB_DIR = /usr/local/lib/
linux: export OPENSSL_STATIC = 1
linux: export DEP_OPENSSL_INCLUDE = /usr/local/include/
linux: rig-$(VERSION).tar.gz
linux: rig-$(VERSION).tar.gz rig-$(VERSION).deb rig-$(VERSION).rpm

rig-$(VERSION).tar.gz: target/release/rig
ls -l target/release/rig
Expand All @@ -55,28 +61,39 @@ rig-$(VERSION).tar.gz: target/release/rig
mkdir -p build/share/rig
curl -L -o build/share/rig/cacert.pem 'https://curl.se/ca/cacert.pem'
tar cz -C build -f $@ bin share
cp $@ rig-$(VERSION)-`arch`.tar.gz

rig-$(VERSION).deb: rig-$(VERSION).tar.gz tools/linux/make-deb.sh
VERSION=$(VERSION) ./tools/linux/make-deb.sh $< $@

rig-$(VERSION).rpm: rig-$(VERSION).tar.gz tools/linux/make-rpm.sh
VERSION=$(VERSION) ./tools/linux/make-rpm.sh $< $@

shell-linux:
docker compose build
docker run -ti -v .:/work rlib/rig-builder:latest bash
docker run -ti -v .:/work \
-e LOCAL_UID=`id -u` -e LOCAL_GID=`id -g` $(DOCKER_ARCH) \
rlib/rig-builder:latest bash

VARIANTS = ubuntu-20.04 ubuntu-22.04 debian-11 debian-12 centos-7 rockylinux-8 rockylinux-9 opensuse/leap-15.3 opensuse/leap-15.4 fedora-37 fedora-38 almalinux-8 almalinux-9
print-linux-variants:
@echo $(VARIANTS)
print-linux-variants-json:
@echo $(VARIANTS) | sed 's/ /","/g' | sed 's/^/["/' | sed 's/$$/"]/'
linux-amd64-in-docker:
@echo "make linux-amd64-in-docker is only reliable after make clean"
DOCKER_DEFAULT_PLATFORM=linux/amd64 make linux-in-docker

linux-arm64-in-docker:
@echo "make linux-arm64-in-docker is only reliable after make clean"
DOCKER_DEFAULT_PLATFORM=linux/arm64 make linux-in-docker

linux-in-docker:
docker compose build
docker run -v .:/work \
-e LOCAL_UID=`id -u` -e LOCAL_GID=`id -g` \
rlib/rig-builder:latest make linux

ifeq "$(DOCKER_DEFAULT_PLATFORM)" ""
DOCKER_ARCH :=
else
DOCKER_ARCH := --platform=$(DOCKER_DEFAULT_PLATFORM)
endif
VARIANTS = ubuntu-20.04 ubuntu-22.04 debian-11 debian-12 centos-7 rockylinux-8 rockylinux-9 opensuse/leap-15.3 opensuse/leap-15.4 fedora-37 fedora-38 almalinux-8 almalinux-9
print-linux-variants:
@echo $(VARIANTS)
print-linux-variants-json:
@echo $(VARIANTS) | sed 's/ /","/g' | sed 's/^/["/' | sed 's/$$/"]/'

define GEN_TESTS
linux-test-$(variant):
Expand All @@ -90,6 +107,7 @@ linux-test-$(variant):
touch tests/results/`echo $(variant) | tr / -`.fail
shell-$(variant):
docker run -ti --rm -v $(PWD):/work `echo $(variant) | tr - :` bash
.PHONY: linux-test-$(variant) shell-$(variant)
TEST_IMAGES += linux-test-$(variant)
endef
$(foreach variant, $(VARIANTS), $(eval $(GEN_TESTS)))
Expand Down Expand Up @@ -202,7 +220,11 @@ build.stamp: target/release/rig target/x86_64-apple-darwin/release/rig \

# -------------------------------------------------------------------------

.PHONY: release clean all macos win linux Rig.app
.PHONY: release clean all macos win linux Rig.app shell-linux \
linux-in-docker linux-amd64-in-docker linux-arm64-in-docker \
linux-test-all

clean:
rm -rf build.stamp build-* Resources *.pkg distribution.xml gon.hcl Output *.exe
cargo clean
rm -rf build.stamp build-* Resources *.pkg distribution.xml \
gon.hcl Output *.exe *.deb *.rpm *.tar.gz build
16 changes: 8 additions & 8 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

group=`getent group $LOCAL_GID | cut -f1 -d:`
if [ -z "$group" ]; then
addgroup -g "$LOCAL_GID" rig
group=rig
addgroup -g "$LOCAL_GID" rigbuild
group=rigbuild
fi

# Recreate rig user with the right UID and GID
# Recreate rigbuild user with the right UID and GID

deluser rig 2>/dev/null
adduser -u $LOCAL_UID -G $group -D -H rig
deluser rigbuild 2>/dev/null
adduser -u $LOCAL_UID -G $group -D -H rigbuild

# We only need acceess to these and it would takes ~10s to chown all the
# files of the rust toolchain

chown rig:$group /home/rig/
chown rig:$group /home/rig/.cargo
chown rigbuild:$group /home/rigbuild/
chown rigbuild:$group /home/rigbuild/.cargo

exec su -s /bin/sh rig sh -c "$*"
exec su -s /bin/sh rigbuild sh -c "$*"
55 changes: 55 additions & 0 deletions tools/linux/make-deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#! /bin/bash

set -e

if [ "$#" != 2 ]; then
echo "Usaga: $1 <input-tar-gz> <output-package>"
exit 1
fi

arch="`arch`"
if [ "$arch" == "aarch64" ]; then
arch=arm64
elif [ "$arch" == "x86_64" ]; then
arch=amd64
else
echo "Unsupported architecture: $arch"
exit 2
fi

rm -rf /tmp/nfpm-deb
mkdir -p /tmp/nfpm-deb
tar xzf "$1" -C /tmp/nfpm-deb

rm -rf /tmp/nfpm
mkdir -p /tmp/nfpm

cat <<EOF >/tmp/nfpm-deb.yaml
name: rig
version: ${VERSION}
release: 1
section: universe/math
priority: normal
arch: "${arch}"
maintainer: Gabor Csardi <[email protected]>
description: |
The R Installation Manager
vendor: Gabor Csardi
homepage: https://github.com/r-lib/rig
license: MIT
deb:
fields:
Bugs: https://github.com/r-lib/rig/issues
contents:
- src: /tmp/nfpm-deb
dst: /usr/local
EOF

nfpm package \
-f /tmp/nfpm-deb.yaml \
-p deb \
-t /tmp/nfpm

out="`ls /tmp/nfpm`"
cp "/tmp/nfpm/$out" .
ln -sf "`basename $out`" $2
52 changes: 52 additions & 0 deletions tools/linux/make-rpm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#! /bin/bash

set -e

if [ "$#" != 2 ]; then
echo "Usaga: $1 <input-tar-gz> <output-package>"
exit 1
fi

arch="`arch`"
if [ "$arch" == "aarch64" ]; then
arch=arm64
elif [ "$arch" == "x86_64" ]; then
arch=amd64
else
echo "Unsupported architecture: $arch"
exit 2
fi

rm -rf /tmp/nfpm-rpm
mkdir -p /tmp/nfpm-rpm
tar xzf "$1" -C /tmp/nfpm-rpm

rm -rf /tmp/nfpm
mkdir -p /tmp/nfpm

cat <<EOF >/tmp/nfpm-rpm.yaml
name: rig
version: ${VERSION}
release: 1
section: universe/math
priority: normal
arch: "${arch}"
maintainer: Gabor Csardi <[email protected]>
description: |
The R Installation Manager
vendor: Gabor Csardi
homepage: https://github.com/r-lib/rig
license: MIT
contents:
- src: /tmp/nfpm-rpm
dst: /usr/local
EOF

nfpm package \
-f /tmp/nfpm-rpm.yaml \
-p rpm \
-t /tmp/nfpm

out="`ls /tmp/nfpm`"
cp "/tmp/nfpm/$out" .
ln -sf "`basename $out`" $2

0 comments on commit 2e1d76d

Please sign in to comment.