Linux SRV-16 6.18.44-paas #1 SMP PREEMPT_DYNAMIC Thu Aug 13 10:08:12 UTC 2026 x86_64
/
srv
/
admin
/
scripts
/
builder
/
/srv/admin/scripts/builder/build.sh
#!/bin/bash readonly VHOST=${1:-default} readonly TREEISH=${2:-master} readonly REMOTE_REPO=${3:-} readonly BUILDDIR=$(mktemp -d /tmp/build.XXXXXXXXXX) readonly ENGINE_SCRIPTS_DIR="/srv/admin/scripts/builder/$WWW_ENGINE" # https://docs.gandi.net/fr/hebergement_web/langages/nodejs.html#trucs-et-astuces-pour-le-deploiement export GANDI="$(hostname)" msg() { echo "-----> $@" } run() { local description="$1" shift msg "$description" "$@" || { msg "$description failed" msg 'Aborting deployment' clean_build_dir exit 1 } } clean_build_dir() { if [ -d "$BUILDDIR" ]; then cd / rm -rf "$BUILDDIR" fi } fetch() { local git_dir="/srv/data/vcs/git/$VHOST.git" if [ -n "$REMOTE_REPO" ]; then # Do a shallow clone of the latest commit on master git clone --branch "$TREEISH" --depth=1 -- "$REMOTE_REPO" "$BUILDDIR" else [ -d "$git_dir" ] || return 1 env GIT_WORK_TREE="$BUILDDIR" \ GIT_DIR="$git_dir" \ git checkout -q -f "$TREEISH" fi } build() { "$ENGINE_SCRIPTS_DIR/install.sh" "$BUILDDIR" } copy() { local vhostpath="/srv/data/web/vhosts/$VHOST/" "$ENGINE_SCRIPTS_DIR/copy.sh" "$BUILDDIR" "$vhostpath" rsync --exclude-from="$ENGINE_SCRIPTS_DIR/exclude" \ -rlp --ignore-times -v "$BUILDDIR/" "$vhostpath" # Doing a shallow clone then a copy of the repo leaves the .git directory # inside the vhost, we need to remove it. if [ -n "$REMOTE_REPO" ]; then rm -r "$vhostpath"/.git fi } # remove sgid before chmod (was allowed on solaris) chmod g-s "$BUILDDIR" # avoid rsync to try to change mode on vhosts/default # it is owned by root and rsync will fail chmod 775 "$BUILDDIR" cd "$BUILDDIR" msg "Starting new deployment ($VHOST - $TREEISH)" run 'Fetching application code' fetch run 'Building new application' build run 'Copying new application' copy msg 'Build complete' msg 'Cleaning temporary files' clean_build_dir