Skip to content

Commit a406f13

Browse files
committed
Build the website using the same Dockerfile in the github action
1. we build the image and cache the layers it to gha, this means the build step should usually be very fast. 2. we do not copy in all the sources into the image because we mount the sources in locally and in the workflow. this makes the image very cacheable. 3. moves a2s into /usr/local/bin so that the github user id can access it (previously it was under /root). Signed-off-by: Robert Young <[email protected]>
1 parent 913ccd6 commit a406f13

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

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

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,41 @@ jobs:
2525
# Build job
2626
build:
2727
runs-on: ubuntu-latest
28+
services:
29+
# we spin up a registry to share the image built by build-push-action with the later docker run step
30+
registry:
31+
image: registry:2
32+
ports:
33+
- 5000:5000
2834
steps:
2935
- name: Checkout
3036
uses: actions/checkout@v3
31-
- name: Setup Ruby
32-
uses: ruby/setup-ruby@v1
33-
with:
34-
ruby-version: '3.4.4' # Not needed with a .ruby-version file
35-
cache-version: 0 # Increment this number if you need to re-download cached gems
3637
- name: Setup Pages
3738
uses: actions/configure-pages@v3
38-
- name: Install rake
39-
run: gem install rake
40-
- name: Update Bundler and Setup Jekyll
41-
run: bundle install && bundle update --bundler
42-
- name: Setup Go
43-
uses: actions/setup-go@v5
44-
- name: Setup ASCIIToSVG
45-
run: go install github.com/asciitosvg/asciitosvg/cmd/a2s@latest
46-
- name: Download Bootstrap 5 SCSS Sources
47-
run: ./bootstrap_setup.sh
39+
40+
- name: Set up Docker Buildx
41+
uses: docker/setup-buildx-action@v3
42+
with:
43+
# this is required for the subsequent build to be able to push to the registry on localhost:5000
44+
driver-opts: network=host
45+
46+
- name: Build Docker image
47+
uses: docker/build-push-action@v6
48+
with:
49+
context: .
50+
push: true
51+
tags: localhost:5000/kroxy-jekyll:latest
52+
cache-from: type=gha
53+
cache-to: type=gha,mode=max
4854
- name: Build with Jekyll
4955
# Outputs to the './_site' directory by default
50-
run: bundle exec jekyll build --baseurl "${{ steps.pages.outputs.base_path }}"
56+
run: |
57+
docker run \
58+
--rm \
59+
-u "$(id -u):$(id -g)" \
60+
-v "$(pwd):/site" \
61+
localhost:5000/kroxy-jekyll:latest \
62+
bash -c 'eval "$(rbenv init -)" && cp -r /css/_sass/bootstrap /site/_sass/ && bundle exec jekyll build --baseurl "${{ steps.pages.outputs.base_path }}"'
5163
env:
5264
JEKYLL_ENV: production
5365
- name: Upload artifact

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ _site
44
.jekyll-metadata
55
vendor
66
.idea
7+
*.iml
78
*/bootstrap/

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ ENV RBENV_ROOT /usr/local/rbenv
2121
RUN git clone https://github.com/rbenv/rbenv.git ${RBENV_ROOT} && \
2222
git clone https://github.com/rbenv/ruby-build.git ${RBENV_ROOT}/plugins/ruby-build
2323

24-
ENV PATH="${RBENV_ROOT}/bin:/root/go/bin:${PATH}"
24+
ENV PATH="${RBENV_ROOT}/bin:${PATH}"
2525
RUN eval "$(rbenv init -)" && \
2626
rbenv install 3.4.4 && \
2727
rbenv global 3.4.4 && \
2828
gem install bundler && \
29-
go install github.com/asciitosvg/asciitosvg/cmd/a2s@latest
29+
go install github.com/asciitosvg/asciitosvg/cmd/a2s@latest && \
30+
mv /root/go/bin/a2s /usr/local/bin/ && \
31+
chmod 777 /usr/local/bin/a2s
3032

3133
COPY Gemfile .
3234
COPY Gemfile.lock .
@@ -41,7 +43,6 @@ RUN ./bootstrap_setup.sh
4143

4244
RUN mkdir /site/
4345
WORKDIR /site/
44-
4546
EXPOSE 4000
4647
# Note --incremental mode is ineffective on the Mac owing to https://github.com/containers/podman/issues/22343. Use force_regenerate.sh to trigger the incremental reload after changing the file on the host.
4748
CMD eval "$(rbenv init -)" && cp -r /css/_sass/bootstrap /site/_sass/ && bundle exec jekyll serve --host ${JEKYLL_SERVE_BIND} --incremental --disable-disk-cache --destination /tmp/site

0 commit comments

Comments
 (0)