aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/docker-compose.yml
blob: cb7087752f6e441c7bd2a927ba0a9747248bc531 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# About the two images...
#
# I had conflicting requirements:
# * make Makefile available during the build to avoid code duplication,
# * make out-of-tree builds possible (i.e. this directory, along with Makefile,
# shouldn't be required to reside inside the project directory).
#
# So, I basically had two build contexts (PROJECT_DIR and this directory),
# which is unsupported.
# On the other hand, I only need the Makefile from this directory, so I could
# hack it by passing the contents of the Makefile as a build argument.
# I thought this was too much though, so I came up with making two images, one
# containing the Makefile (and Ruby, etc.), and the other extending the base
# one.
# This has some nice properties (there's now a common base image for all Jekyll
# projects), but some drawbacks as well.

version: '3'
services:
  base:
    build:
      context: .
      dockerfile: Dockerfile.base
      args:
        - JEKYLL_UID
        - JEKYLL_GID
    user: "$JEKYLL_UID:$JEKYLL_GID"
  project:
    build:
      context: "${PROJECT_DIR:-..}"
      # Dockerfile outside of the build context.
      # This is supposedly supported by Docker since 18.03, but I couldn't find
      # a less hacky way to do it in docker-compose.
      # Source: https://github.com/docker/compose/issues/4926.
      dockerfile: "$PWD/Dockerfile.project"
    depends_on:
      # It actually doesn't depend on anything, but the base image needs to be
      # built before this image.
      - base
    ports:
      - 4000:4000
    user: "$JEKYLL_UID:$JEKYLL_GID"
    volumes:
      - "${PROJECT_DIR:-..}:/project"