diff --git a/.gitignore b/.gitignore index 6985cf1..c99350b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ Cargo.lock # MSVC Windows builds of rustc generate these, which store debugging information *.pdb + +scripts/build \ No newline at end of file diff --git a/scripts/Dockerfile.template b/scripts/Dockerfile.template new file mode 100644 index 0000000..42d598a --- /dev/null +++ b/scripts/Dockerfile.template @@ -0,0 +1,13 @@ +ARG OS +FROM $OS + +ARG PAC + +RUN rm /bin/sh && ln -s /bin/bash /bin/sh +RUN $PAC -y update && $PAC install -y git gcc curl + +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > /tmp/rustup && sh /tmp/rustup -y +ADD scripts/build-internal.sh / +RUN mkdir -p /dummy/src +COPY Cargo.toml /dummy +RUN source $HOME/.cargo/env && cd /dummy && echo "// dummy file" > src/lib.rs && cargo build --release diff --git a/scripts/PLATFORMS b/scripts/PLATFORMS new file mode 100644 index 0000000..1eba8f1 --- /dev/null +++ b/scripts/PLATFORMS @@ -0,0 +1,4 @@ +# short name # docker from # pac mgr cmd +centos7 centos:7.9.2009 yum +rocky9 rockylinux:9.3 yum +debian12 debian:12.4 apt-get diff --git a/scripts/build-internal.sh b/scripts/build-internal.sh new file mode 100755 index 0000000..0d97aba --- /dev/null +++ b/scripts/build-internal.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +if [ $# -ne 1 ]; then + echo usage $0 \ + exit 1 +fi + +cd / +git clone /src/ bigarchiver && \ +cd bigarchiver/ && \ +cargo test --release && cargo build --release && \ +mkdir -pv /src/scripts/build/$1/ && \ +cp -v target/release/bigarchiver /src/scripts/build/$1/ diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000..1db9b6f --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +set -e + +if [ $# -eq 0 ]; then + echo usage $0 --image\|--app [ os_ident ] + exit 1 +fi + +cat PLATFORMS | sed '/^#/d;/^[[:space:]]*$/d' | while read LINE; do + WORDS=($LINE) + if [ ${#WORDS[@]} -ne 3 ]; then + echo Invalid PLATFORMS file + exit 1 + fi + + IDENT=${WORDS[0]} + IMAGE_FROM=${WORDS[1]} + PAC_MGR=${WORDS[2]} + + if [ -n "$2" ]; then + if [ x"$IDENT" != x"$2" ] ; then + continue + fi + fi + + cd .. + case $1 in + --image) + echo preparing build image for $IDENT + docker build -t bigarchiver-$IDENT -f scripts/Dockerfile.template --build-arg OS=$IMAGE_FROM --build-arg PAC=$PAC_MGR . + ;; + --app) + echo building application for $IDENT + docker run -v=.:/src bigarchiver-$IDENT /bin/bash -l -c "/build-internal.sh $IDENT" + ;; + *) + echo invalid usage + exit 3 + esac + cd scripts +done + +echo all done