Skip to content
This repository has been archived by the owner on Jun 10, 2023. It is now read-only.

Adding support for a Dockerized build process #275

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 themes/hello-friend
# $ docker build . --tag <some_tag_name>
#
# Now, to rebuild the theme:
# $ cd themes/hello-friend
# $ docker run -it \
# --mount type=bind,source="$(pwd)",destination=/hello-friend \
# <some_tag_name>:latest
#
# The newly built theme files will be written back into the theme 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" ]
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <some_tag_name>
```
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 \
<some_tag_name>: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`).

Expand Down