From 4dd72dd5b97cea4b788f770b4c62ac461c1e5b54 Mon Sep 17 00:00:00 2001 From: Ben Chapman <5124569+Ben-Chapman@users.noreply.github.com> Date: Tue, 11 Jan 2022 16:31:35 -0500 Subject: [PATCH 1/3] Adding support for Dockerized builds --- .dockerignore | 1 + Dockerfile | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..b512c09d4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..ca3ff82f7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +# A simple and lightweight Docker container for building the Hello Friend Hugo Theme +# +# To use: +# First, build a Docker image: +# $ cd $theme_dir +# $ docker build . --tag +# +# Now, to rebuild the theme: +# $ cd $theme_dir +# $ docker run -it \ +# --mount type=bind,source="$(pwd)",destination=/hello-friend \ +# :latest +# +# The newly built theme files will be written back into your theme's directory +# through the magic of Docker bind mounts + +FROM alpine:latest + +# You must rebuild the Docker image if you modify either of these files +ADD package.json yarn.lock ./ + +RUN apk add --no-cache npm && \ + npm install --global husky yarn && \ + npm install --global && \ + npx browserslist@latest --update-db && \ + yarn + +WORKDIR /hello-friend + +# This is executed each time you `docker run` the container +ENTRYPOINT [ "npx", "webpack", "--mode=production" ] From 60cc6d155681c501cdc775bf87bce4a5cc572c8e Mon Sep 17 00:00:00 2001 From: Ben <5124569+Ben-Chapman@users.noreply.github.com> Date: Wed, 12 Jan 2022 10:47:50 -0500 Subject: [PATCH 2/3] Adding Docker build instructions --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index eeca20f76..6c54e1fc9 100644 --- a/README.md +++ b/README.md @@ -255,6 +255,23 @@ or rebuild theme ```bash yarn build ``` +### Rebuild the theme using Docker +If you don't have, or don't want to install `npm`, `yarn` and their dependencies on your system you can easily rebuild this theme using a Docker container. `npm`, `yarn`, and all dependant packages will be installed and configured within a dedicated Docker image, and rebuilding the theme is a single command. + +First, build a Docker image: +```bash +cd themes/hello-friend +docker build . --tag +``` +When the Docker build step completes, you now have a Docker image with all software needed to rebuild the theme. You should only need to rebuild the Docker image if you make changes to `package.json` or `yarn.lock`. + +To rebuild the theme, start a new Docker container which upon startup will automatically execute `webpack --mode=production`. The theme directory is presented to the Docker container through the `--mount` option. +```bash +docker run -it \ +--mount type=bind,source="$(pwd)",destination=/hello-friend \ +:latest +``` +The build step should take a few seconds, and the newly built theme files will be written back into the theme directory. To see the changes (remember to restart `hugo server`). From 6cdd4d51bd08916cc8872ef29025f57e07490d62 Mon Sep 17 00:00:00 2001 From: Ben <5124569+Ben-Chapman@users.noreply.github.com> Date: Wed, 12 Jan 2022 10:50:22 -0500 Subject: [PATCH 3/3] Update Dockerfile --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index ca3ff82f7..4c11d9f58 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,16 +2,16 @@ # # To use: # First, build a Docker image: -# $ cd $theme_dir +# $ cd themes/hello-friend # $ docker build . --tag # # Now, to rebuild the theme: -# $ cd $theme_dir +# $ cd themes/hello-friend # $ docker run -it \ # --mount type=bind,source="$(pwd)",destination=/hello-friend \ # :latest # -# The newly built theme files will be written back into your theme's directory +# The newly built theme files will be written back into the theme directory # through the magic of Docker bind mounts FROM alpine:latest