Improve Docker handling and documentation

This commit is contained in:
Christian Reitter 2024-04-28 15:42:12 +02:00
parent 7af3c18c50
commit 41400598e8
3 changed files with 29 additions and 23 deletions

View File

@ -2,6 +2,7 @@ Dockerfile
Makefile
_site/
site_export/
.jekyll-cache
.vscode/
.git/
.gitignore

View File

@ -1,25 +1,29 @@
# use Ruby as the foundation since Jekyll needs it
# Alpine to keep the container a bit lighter
FROM ruby:3-alpine AS builder
LABEL stage=milksad-website-builder
RUN apk update && apk add g++ make imagemagick imagemagick-dev imagemagick-libs
# install necessary system dependencies for Jekyll and plugins
RUN apk update && \
apk add g++ make imagemagick imagemagick-dev imagemagick-libs && \
rm -rf /var/cache/apk/*
RUN mkdir -p /home
COPY Gemfile /home
COPY Gemfile.lock /home
# copying _vendor is not needed at the moment
# COPY _vendor /home/_vendor
WORKDIR /home
# also creates user directory
RUN adduser -D builder
USER builder
RUN mkdir -p /home/builder/workdir
WORKDIR /home/builder/workdir
# copy the Jekyll website contents into the container
# this includes Gemfile and Gemfile.lock
# reminder: .dockerignore should specify a good ignorelist for this
COPY --chown=builder . .
# install Gems
RUN bundle install
COPY . /home
# do the initial website build
RUN jekyll build
# FROM debian:bookworm AS mime-types
# RUN apt-get update && apt-get install -y media-types
# RUN echo 'types {' > /tmp/mime.types
# RUN sed -e '/^$/d' -e 's/$/;/' /etc/mime.types >> /tmp/mime.types
# RUN echo '}' >> /tmp/mime.types
# FROM nginx:1.25
# COPY nginx.conf /etc/nginx/nginx.conf
# COPY --from=builder /home/_site /usr/share/nginx/html
# COPY --from=mime-types /tmp/mime.types /etc/nginx/mime.types
# COPY --from=builder /home/_site /usr/share/nginx/html
# note: this Dockerfile is no longer responsible for serving the content to end users

View File

@ -1,5 +1,6 @@
# flexible use with docker and podman
platform ?= docker
container_workdir = /home/builder/workdir/
.PHONY: build
build:
@ -13,12 +14,12 @@ fullclean: clean
.PHONY: clean
clean:
rm -r site_export
rm -rf site_export
site_export: build
rm -rf site_export
mkdir -p site_export
$(platform) run milksad-website tar c -C /home/_site . | tar x -C site_export
$(platform) run milksad-website tar c -C ${container_workdir}/_site . | tar x -C site_export
#.PHONY: serve
#serve: build
@ -35,8 +36,8 @@ build-dev:
.PHONY: dev
dev: build-dev
$(platform) run --rm --expose 4000 -p 127.0.0.1:4000:4000 -v ${PWD}:/home -it dev-milksad-website jekyll serve -H 0.0.0.0
$(platform) run --rm --expose 4000 -p 127.0.0.1:4000:4000 --mount type=bind,source=${PWD},target=${container_workdir} -it dev-milksad-website jekyll serve -H 0.0.0.0
.PHONY: dev-shell
dev-shell: build-dev
$(platform) run --rm --expose 4000 -p 127.0.0.1:4000:4000 -v ${PWD}:/home -it dev-milksad-website sh
$(platform) run --rm --expose 4000 -p 127.0.0.1:4000:4000 --mount type=bind,source=${PWD},target=${container_workdir} -it dev-milksad-website sh