Skip to content

Commit 8112794

Browse files
committed
Add build script
So that we can execute a local production build the same way we do in CI Signed-off-by: Robert Young <[email protected]>
1 parent b0ebcb2 commit 8112794

File tree

5 files changed

+48
-14
lines changed

5 files changed

+48
-14
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.jekyll-cache
22
.gitignore
33
run.sh
4+
build.sh
45
Dockerfile
56
.dockerignore
67
.git

.github/workflows/jekyll-gh-pages.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,13 @@ jobs:
6363
# this is to enable forks to override the url and baseurl
6464
run: echo "${{ vars.JEKYLL_CONFIG_OVERRIDES }}" > _config-overrides.yml
6565
- name: Build with Jekyll
66-
# Outputs to the './_site' directory by default
66+
# Outputs to the './_site' directory
6767
run: |
68-
docker run \
69-
--rm \
70-
-u "$(id -u):$(id -g)" \
71-
-v "$(pwd):/site" \
72-
localhost:5000/kroxy-jekyll:latest \
73-
bash -c 'eval "$(rbenv init -)" && cp -r /css/_sass/bootstrap /site/_sass/ && JEKYLL_ENV=production bundle exec jekyll build --config=_config.yml,_config-overrides.yml'
68+
./build.sh
7469
env:
75-
JEKYLL_ENV: production
70+
CONTAINER_ENGINE: docker
71+
CONFIG_OVERRIDES: _config-overrides.yml
72+
BUILD_IMAGE_SPEC: localhost:5000/kroxy-jekyll:latest
7673
- name: Upload artifact
7774
# Automatically uploads an artifact from the './_site' directory by default
7875
uses: actions/upload-pages-artifact@v3

.github/workflows/pr-build.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ jobs:
3232
cache-to: type=gha,mode=max
3333

3434
- name: Build with Jekyll
35+
# Outputs to the './_site' directory
3536
run: |
36-
docker run \
37-
--rm \
38-
-u "$(id -u):$(id -g)" \
39-
-v "$(pwd):/site" \
40-
localhost:5000/kroxy-jekyll:latest \
41-
bash -c 'eval "$(rbenv init -)" && cp -r /css/_sass/bootstrap /site/_sass/ && JEKYLL_ENV=production bundle exec jekyll build --config=_config.yml'
37+
./build.sh
38+
env:
39+
CONTAINER_ENGINE: docker
40+
BUILD_IMAGE_SPEC: localhost:5000/kroxy-jekyll:latest

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ exclude:
4747
- .idea
4848
- docs/README.md
4949
- Dockerfile
50+
- build.sh
5051
- run.sh
5152
- bootstrap_setup.sh
5253
- README.md

build.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 a '_site' directory in the project directory
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

Comments
 (0)