Files
selfhostbook/book/build.sh
T
Adam Monsen 04da5595e4 hide files used for builds
more book/ dir tidying

I guess my intent is to greatly emphasize files that are often viewed, maintained, and sought-after. These dotfiles are less important, in my humble opinion. I'm open to reverting this change, I'm just trying it out for now.
2024-03-12 12:58:24 -07:00

88 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
# Typeset book _Steadfast Self-Hosting_
# Copyright (C) 2024 Adam Monsen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##############################################################
# Performs typesetting in a container. #
# Requires Docker. #
##############################################################
set -o errexit
set -o nounset
set -o pipefail
SECONDS=0
echo "🏗️ start at $(date)"
BUILD_TYPE=full
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
WORK_DIR=/usr/src/app/book
GID="$(id -g)"
GROUP="$(id -gn)"
BUILD_DATE_TIME="$(date)"
BUILD_LOCALE_LANG="${LANG:-en_US.UTF-8}"
BUILD_GIT_COMMIT="$(git rev-parse --short HEAD || echo FIXME)"
BUILD_GIT_BRANCH="$(git branch --show-current || echo FIXME)"
BUILD_GIT_TAG="$(git describe --tags --abbrev=0 || echo FIXME)"
if [[ $OSTYPE =~ linux-gnu ]]; then
BUILD_OS_RELEASE="$(lsb_release --short --description || echo FIXME)"
imageDefinition=.Dockerfile
runContainerUserArg="--user $USER:$GROUP"
elif [[ $OSTYPE =~ darwin ]]; then
BUILD_OS_RELEASE="$OSTYPE"
imageDefinition=.Dockerfile.insecure
runContainerUserArg=''
else
echo "⚠️ sorry, $OSTYPE is not yet supported"
exit 1
fi
echo '🚢 build image'
# discard container checksum
docker build \
--tag shb-asciidoctor \
--build-arg WORK_DIR="$WORK_DIR" \
--build-arg USER="$USER" \
--build-arg UID="$UID" \
--build-arg GROUP="$GROUP" \
--build-arg GID="$GID" \
--file "$imageDefinition" \
--quiet \
. \
> /dev/null
echo '🚢 start container'
docker run \
--rm \
--interactive \
--tty \
$runContainerUserArg \
--volume "$SCRIPT_DIR:$WORK_DIR" \
--env BUILD_DATE_TIME="$BUILD_DATE_TIME" \
--env BUILD_LOCALE_LANG="$BUILD_LOCALE_LANG" \
--env BUILD_GIT_COMMIT="$BUILD_GIT_COMMIT" \
--env BUILD_GIT_BRANCH="$BUILD_GIT_BRANCH" \
--env BUILD_GIT_TAG="$BUILD_GIT_TAG" \
--env BUILD_OS_RELEASE="$BUILD_OS_RELEASE" \
--env BUILD_TYPE="$BUILD_TYPE" \
shb-asciidoctor \
"$@"
echo "🏗️ done (${SECONDS}s elapsed)"