|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# This script exists to run a production build of the code. Users can: |
| 4 | +# * Supply a builder image with BUILD_IMAGE_SPEC, otherwise we build the image |
| 5 | +# * Include additional configuration overrides with ${CONFIG_OVERRIDES}, additional |
| 6 | +# override files should be added to the project directory. Eg I add an _config-overrides.yml |
| 7 | +# and set CONFIG_OVERRIDES=_config-overrides.yml |
| 8 | +# * Control their container engine binary by setting CONTAINER_ENGINE, for example to 'docker'. |
| 9 | +# The output of the build will be emitted to an _site directory in the project director |
| 10 | +trap "exit" INT |
| 11 | +set +euo pipefail |
| 12 | + |
| 13 | +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) |
| 14 | +cd ${SCRIPT_DIR} |
| 15 | +CONTAINER_ENGINE=${CONTAINER_ENGINE:-podman} |
| 16 | +if [ -z "${BUILD_IMAGE_SPEC}" ]; then |
| 17 | + ${CONTAINER_ENGINE} build . -t kroxylicious-website |
| 18 | + export BUILD_IMAGE_SPEC=kroxylicious-website |
| 19 | +fi |
| 20 | +if [ -n "${CONFIG_OVERRIDES}" ]; then |
| 21 | + export CONFIG_OVERRIDES=",${CONFIG_OVERRIDES}" |
| 22 | +else |
| 23 | + export CONFIG_OVERRIDES="" |
| 24 | +fi |
| 25 | +RUN_ARGS=() |
| 26 | +if [ "$CONTAINER_ENGINE" = 'podman' ]; then |
| 27 | + RUN_ARGS+=(-v "$(pwd):/site/:Z") |
| 28 | +else |
| 29 | + RUN_ARGS+=(-v "$(pwd):/site") |
| 30 | + RUN_ARGS+=(-u $(id -u):$(id -g)) |
| 31 | +fi |
| 32 | +RUN_ARGS+=(-e JEKYLL_ENV="${JEKYLL_ENV:-production}" --rm "${BUILD_IMAGE_SPEC}") |
| 33 | +BUILD_COMMAND='eval "$(rbenv init -)" && cp -r /css/_sass/bootstrap /site/_sass/ && bundle exec jekyll build --config=_config.yml'"${CONFIG_OVERRIDES}" |
| 34 | +RUN_ARGS+=(bash -c "${BUILD_COMMAND}") |
| 35 | +echo "${RUN_ARGS[@]}" |
| 36 | +${CONTAINER_ENGINE} run "${RUN_ARGS[@]}" |
0 commit comments