Skip to content

Commit

Permalink
add back build scripts, they were removed from calaos-build
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulh committed Jan 11, 2024
1 parent f2e5be9 commit c3b37f1
Show file tree
Hide file tree
Showing 4 changed files with 288 additions and 4 deletions.
7 changes: 3 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ USER ${USER}
# Define entry point
WORKDIR /src

RUN git clone https://github.com/calaos/calaos-build.git
COPY build/* /usr/bin

RUN cd calaos-build && \
scripts/get_pkgbuilds.sh && \
scripts/build_pkg.sh "calaos-home" "" "$ARCH" "$COMMIT" "$APP_VERSION"
RUN get_pkgbuilds.sh && \
build_pkg.sh "calaos-home" "" "$ARCH" "$COMMIT" "$APP_VERSION"

RUN sudo pacman -S --noconfirm libxinerama readline bash perl libxtst libxft texinfo libxrandr gnupg

Expand Down
87 changes: 87 additions & 0 deletions docker/build/build_pkg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash

set -e

SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $SCRIPTDIR/calaos_lib.sh

pkgname=$1
repo=$2
arch=$3
commit=$4
pkgversion=$(echo $5 | tr - _)

fix_docker_perms

if [ -z "$pkgname" ]
then
echo "No package name given. Usage: $0 calaos-ddns|calaos-home|calaos-server <repo> <arch> <commit> <pkgversion>"
exit 1
fi

if [ -z "$arch" ]
then
arch="x86_64"
fi

echo "Building package for repo: $repo and arch: $arch"
echo "Commit: $commit"
echo "Package version: $pkgversion"

setup_calaos_repo
import_gpg_key

cd $build_dir/pkgbuilds/$pkgname

#Only change PKGBUILD if it is a calaos package
if grep 'pkgname=.*calaos.*' PKGBUILD > /dev/null
then
echo "--> Updating PKGBUILD with version/commit"

#Update PKGBUILD with version
if [ ! -z "$pkgversion" ]
then
sed -E -i "s/pkgver=[0-9\.]+/pkgver=$pkgversion/" PKGBUILD
else
echo "--> No version set, use git to get version info"
#no version set, get version from git
cat >> PKGBUILD <<- 'EOF'
pkgver() {
cd "$srcdir/$_pkgdir"
echo "$(git describe --long --tags --always)" | tr - _
}
EOF
fi

#Update PKGBUILD with commit
if [ ! -z "$commit" ]
then
sed -E -i "s/commit=[a-z0-9]+/commit=$commit/" PKGBUILD
else
echo "--> No commit, use default branch"
#no commit set, user default master branch
sed -E -i "s/#commit=[a-z0-9]+//" PKGBUILD
fi

cat PKGBUILD
fi

if [ $signing_available -eq 1 ]
then
makepkg -f -s --sign --noconfirm
else
makepkg -f -s --noconfirm
fi

mkdir -p $build_dir/out/pkgs/$arch
cp $build_dir/pkgbuilds/$pkgname/*pkg.tar.zst* $build_dir/out/pkgs/$arch

#Only upload package if repo is set
if [ ! -z "$repo" ]
then
echo "--> Uploading package to repo $repo"
upload_pkg $build_dir/pkgbuilds/$pkgname/*pkg.tar.zst $repo $arch
else
echo "--> Not uploading package"
fi
188 changes: 188 additions & 0 deletions docker/build/calaos_lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
#!/bin/env bash

set -e

NOCOLOR='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
LIGHTGRAY='\033[0;37m'
DARKGRAY='\033[1;30m'
LIGHTRED='\033[1;31m'
LIGHTGREEN='\033[1;32m'
YELLOW='\033[1;33m'
LIGHTBLUE='\033[1;34m'
LIGHTPURPLE='\033[1;35m'
LIGHTCYAN='\033[1;36m'
WHITE='\033[1;37m'

export build_dir="/src"
export outdir="$build_dir/out"
export signing_available=0

green()
{
echo -e "${LIGHTGREEN}$*${NOCOLOR}"
}

info()
{
echo -e "${CYAN}$*${NOCOLOR}"
}

warn()
{
echo -e "${ORANGE}$*${NOCOLOR}"
}

err()
{
echo -e "${LIGHTRED}$*${NOCOLOR}"
}

#Usage: get_version /path/to/repo
get_version()
{
repo=$1
pushd $repo > /dev/null
git describe --tags --abbrev=0
popd > /dev/null
}

beginsWith()
{
case $2 in "$1"*) true;; *) false;; esac;
}

endsWith()
{
case $2 in *"$1") true;; *) false;; esac;
}

#Usage: sync_repo $SRCDIR http://github.com/group/project.git master
sync_repo()
{
echo "Syncing repository $2"

dir=$1
gitrepo=$2
branch=$3

if [ -e ${dir}/.build_ignore_git ] ; then
echo "Git clone ignored."
return 0
fi

if ! [ -e ${dir} ] ; then
git clone $gitrepo $dir
( cd $dir; git checkout $branch; )
else
cd $dir
remote="$(git config --get remote.origin.url)"
cd ..

if [ "$remote" = "$gitrepo" ]; then
( cd $dir;
git clean -d -f -x
git reset --hard
git checkout $branch
git pull --rebase
git tag -l | xargs git tag -d
git fetch --tags )
else
echo "*** Remote has changed ***"
test -z "$dir" || test -d $dir && rm -fr $dir
git clone $gitrepo $dir
( cd $dir; git checkout $branch; )
fi
fi
}

import_gpg_key()
{
if [ ! -e $build_dir/gpg-key.asc ]
then
echo "No gpg key to import. Skipping signing..."
else
echo "Setup gpg keys"

#Increase ttl cache time
mkdir -p $HOME/.gnupg
cat > $HOME/.gnupg/gpg-agent.conf <<- 'EOF'
default-cache-ttl 34560000
max-cache-ttl 34560000
EOF

tmpfile=$(mktemp /tmp/gpg-calaos.XXXXXX)
gpg --import --batch --no-tty $build_dir/gpg-key.asc
echo "hello world" > $tmpfile
gpg --detach-sig --yes -v --output=/dev/null --pinentry-mode loopback --passphrase "$(cat $build_dir/passphrase.txt)" $tmpfile
rm $tmpfile

signing_available=1
fi
}

#Usage: upload_pkg packages/calaos-ddns/calaos-ddns-1.0-1-x86_64.pkg.tar.zst $repo x86_64
# with $repo can be: 'calaos' or 'calaos-dev'
upload_pkg()
{
if [ ! -e $build_dir/upload_token ]
then
echo "No upload token set. Skipping upload..."
else
FNAME=$1
FNAMESIG=$1.sig
REPO=$2
ARCH=$3
UPPATH=${REPO}/${ARCH}

UPLOAD_KEY=$(cat $build_dir/upload_token)

echo "Uploading package $FNAME"
curl -X POST \
-H "Content-Type: multipart/form-data" \
-F "upload_key=$UPLOAD_KEY" \
-F "upload_folder=$UPPATH" \
-F "upload_file_sig=@$FNAMESIG" \
-F "upload_file=@$FNAME" \
-F "upload_update_repo=true" \
-F "upload_replace=true" \
-F "upload_repo=$REPO" \
https://arch.calaos.fr/upload
fi
}

#Set permissions on docker mounted volume which belongs to root by default
fix_docker_perms()
{
#Fix permission issue for non root user calaos
sudo chown -R calaos:docker $build_dir
}

setup_calaos_repo()
{
sudo pacman-key --recv-keys AEE23917D88BD96A
sudo pacman-key --lsign-key AEE23917D88BD96A

if ! grep arch.calaos.fr /etc/pacman.conf > /dev/null
then
sudo tee -a /etc/pacman.conf > /dev/null <<- 'EOF'
[calaos]
Server = https://arch.calaos.fr/$repo/$arch
SigLevel = Required DatabaseOptional
[calaos-dev]
Server = https://arch.calaos.fr/$repo/$arch
SigLevel = Required DatabaseOptional
EOF
fi

#Do not fail if our repo is not usable
set +e
sudo pacman -Sy --noconfirm
set -e
}
10 changes: 10 additions & 0 deletions docker/build/get_pkgbuilds.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -e

SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $SCRIPTDIR/calaos_lib.sh

fix_docker_perms

sync_repo $build_dir/pkgbuilds https://github.com/calaos/pkgbuilds.git master

0 comments on commit c3b37f1

Please sign in to comment.