Skip to content
This repository was archived by the owner on Dec 7, 2021. It is now read-only.

Commit 2355bcc

Browse files
committed
dev: improve support for Linux dev host
Cross-platform build environments can be a real pain due to OS specific implementation details. In this Docker Compose based system, we would like to support at least MacOS and Linux development hosts. `docker compose` is the Docker Compose version 2.x command name. We are switching to the `docker-compose` (version 1.x) command as it is more commonly supported by Linux distribution package managers. Docker Desktop for MacOS does some nice things to handle effective UID & GID remapping for mounted volumes. Linux Docker implementations use volume drivers which do not uniformly provide this support. A cross-platform trick is to set the runtime user for the Docker container to match the UID & GID of the host user so that the container user can write to the mounted volume regardless of volume driver implementation.
1 parent 40f85ff commit 2355bcc

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
.DS_Store
21
*.pyc
2+
.DS_Store
33
/*.egg-info/
4+
/.env
45
/site/

Makefile

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,37 @@ help:
2929
awk 'BEGIN {FS = ":.*?## "}; {printf "%-20s %s\n", $$1, $$2}'
3030
.PHONY: help
3131

32-
start: $(DOCKERFILES) ## Start the docker-compose stack
33-
docker compose up --build --detach
32+
start: .env $(DOCKERFILES) ## Start the docker-compose stack
33+
docker-compose up --build --detach
3434
.PHONY: start
3535

3636
stop: ## Stop the docker-compose stack
37-
docker compose stop
37+
docker-compose stop
3838
.PHONY: stop
3939

4040
restart: stop start ## Restart the docker-compose stack
4141
.PHONY: restart
4242

4343
status: ## Show status of the docker-compose stack
44-
docker compose ps
44+
docker-compose ps
4545
.PHONY: status
4646

4747
shell: ## Get an interactive shell inside the container
48-
docker compose exec portal bash
48+
docker-compose exec portal sh -c " \
49+
export HOME=/tmp/runtime-home; \
50+
exec /bin/bash \
51+
"
4952
.PHONY: shell
5053

5154
tail: ## Tail logs from the docker-compose stack
52-
docker compose logs -f
55+
docker-compose logs -f
5356
.PHONY: tail
5457

5558
build: ## Build static site
56-
docker compose exec portal \
57-
poetry run mkdocs --verbose build
59+
docker-compose exec portal sh -c " \
60+
export HOME=/tmp/runtime-home; \
61+
exec poetry run mkdocs --verbose build \
62+
"
5863
.PHONY: build
5964
docs: build
6065
.PHONY: docs
@@ -64,6 +69,9 @@ clean: ## Clean up Docker images and containers
6469
yes | docker container prune
6570
.PHONY: clean
6671

72+
.env: ## Generate a .env file for local development
73+
./bin/make_env.sh ./.env
74+
6775
%.Dockerfile: $(PIPELINE_DIR)/blubber.yaml
6876
echo "# Dockerfile for *local development*." > $@
6977
echo "# Generated by Blubber from .pipeline/blubber.yaml" >> $@

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ $ make build
1919
$ open http://127.0.0.1:9000/
2020
```
2121

22+
NOTE: `open` is a MacOS command to open a file, directory, or url in the
23+
default application for that media type. On a Linux host you can either
24+
manually open the URL or use a similar URL opening script like `xdg-open`,
25+
`sensible-browser`, `x-www-browser`, or `gnome-open`.
26+
2227
License
2328
-------
2429
Wikimedia Developer Portal code and configuration is licensed under the [GNU GPLv3+][] license. Textual content is licensed under the [CC-BY-SA 3.0][] license.

bin/make_env.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
cat > ${1:?Missing target file} << _EOF
3+
LOCAL_UID=$(id -u)
4+
LOCAL_GID=$(id -g)
5+
_EOF

docker-compose.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ services:
66
context: .
77
dockerfile: .pipeline/local.Dockerfile
88
image: "wmdevportal:local"
9-
user: somebody
9+
# Run container as local user to allow Linux mount writes
10+
user: "${LOCAL_UID:?run `make .env`}:${LOCAL_GID:?run `make .env`}"
1011
working_dir: /srv/app
1112
command:
1213
- bash
1314
- -c
1415
- >-
16+
mkdir -p /tmp/runtime-home &&
17+
export HOME=/tmp/runtime-home &&
1518
poetry run mkdocs --verbose build &&
1619
exec nginx -c /srv/app/contrib/nginx/nginx.conf
1720
volumes:

0 commit comments

Comments
 (0)