Skip to content

Commit 2d97e3f

Browse files
authored
Simplify Makefile / Dockerfile interactions using docker-compose.yml (#785)
* simplify Makefile / Dockerfile interactions using docker-compose.yml # Conflicts: # Makefile * Update README.md * Update README.md
1 parent e771831 commit 2d97e3f

File tree

4 files changed

+90
-104
lines changed

4 files changed

+90
-104
lines changed

Makefile

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,48 @@
11
# Project-specific vars
2-
PFX=ssvc
3-
DOCKER=docker
4-
DOCKER_BUILD=$(DOCKER) build
5-
DOCKER_RUN=$(DOCKER) run --tty --rm
6-
PROJECT_VOLUME=--volume $(shell pwd):/app
72
MKDOCS_PORT=8765
8-
9-
# docker names
10-
TEST_DOCKER_TARGET=test
11-
TEST_IMAGE = $(PFX)_test
12-
DOCS_DOCKER_TARGET=docs
13-
DOCS_IMAGE = $(PFX)_docs
3+
DOCKER_DIR=docker
144

155
# Targets
16-
.PHONY: all dockerbuild_test dockerrun_test dockerbuild_docs dockerrun_docs docs docker_test clean help
6+
.PHONY: all test docs docker_test clean help
177

188
all: help
199

2010
mdlint_fix:
2111
@echo "Running markdownlint..."
2212
markdownlint --config .markdownlint.yml --fix .
2313

24-
dockerbuild_test:
25-
@echo "Building the test Docker image..."
26-
$(DOCKER_BUILD) --target $(TEST_DOCKER_TARGET) --tag $(TEST_IMAGE) .
27-
28-
dockerrun_test:
29-
@echo "Running the test Docker image..."
30-
$(DOCKER_RUN) $(PROJECT_VOLUME) $(TEST_IMAGE)
14+
test:
15+
@echo "Running tests locally..."
16+
pytest -v src/test
3117

32-
dockerbuild_docs:
33-
@echo "Building the docs Docker image..."
34-
$(DOCKER_BUILD) --target $(DOCS_DOCKER_TARGET) --tag $(DOCS_IMAGE) .
18+
docker_test:
19+
@echo "Running tests in Docker..."
20+
pushd $(DOCKER_DIR) && docker-compose run --rm test
3521

36-
dockerrun_docs:
37-
@echo "Running the docs Docker image..."
38-
$(DOCKER_RUN) --publish $(MKDOCS_PORT):8000 $(PROJECT_VOLUME) $(DOCS_IMAGE)
22+
docs:
23+
@echo "Building and running docs in Docker..."
24+
pushd $(DOCKER_DIR) && docker-compose up docs
3925

26+
up:
27+
@echo "Starting Docker services..."
28+
pushd $(DOCKER_DIR) && docker-compose up -d
4029

41-
docs: dockerbuild_docs dockerrun_docs
42-
docker_test: dockerbuild_test dockerrun_test
30+
down:
31+
@echo "Stopping Docker services..."
32+
pushd $(DOCKER_DIR) && docker-compose down
4333

4434
clean:
45-
@echo "Cleaning up..."
46-
$(DOCKER) rmi $(TEST_IMAGE) $(DOCS_IMAGE) || true
35+
@echo "Cleaning up Docker resources..."
36+
pushd $(DOCKER_DIR) && docker-compose down --rmi local || true
4737

4838
help:
4939
@echo "Usage: make [target]"
5040
@echo ""
5141
@echo "Targets:"
5242
@echo " all - Display this help message"
5343
@echo " mdlint_fix - Run markdownlint with --fix"
54-
@echo " docs - Build and run the docs Docker image"
55-
@echo " docker_test - Build and run the test Docker image"
56-
@echo ""
57-
@echo " dockerbuild_test - Build the test Docker image"
58-
@echo " dockerrun_test - Run the test Docker image"
59-
@echo " dockerbuild_docs - Build the docs Docker image"
60-
@echo " dockerrun_docs - Run the docs Docker image"
61-
@echo ""
62-
@echo " clean - Remove the Docker images"
63-
@echo " help - Display this help message"
64-
65-
66-
44+
@echo " test - Run the tests in a local shell"
45+
@echo " docs - Build and run the docs Docker service"
46+
@echo " docker_test - Run the tests in a Docker container"
47+
@echo " clean - Remove Docker containers and images"
48+
@echo " help - Display this help message"

README.md

Lines changed: 28 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ These json files are generated examples from the python `ssvc` module.
6161

6262
These files are used by the `ssvc-calc` module.
6363

64+
## `/docker/*`
65+
66+
The `docker` directory contains Dockerfiles and related configurations for to
67+
create images that can run the SSVC documentation site and unit tests.
68+
69+
Example:
70+
71+
```bash
72+
cd docker
73+
docker-compose up test
74+
docker-compose up docs
75+
```
76+
6477
## `/src/*`
6578

6679
This directory holds helper scripts that can make managing or using SSVC easier.
@@ -103,75 +116,30 @@ To preview any `make` command without actually executing it, run:
103116
make -n <command>
104117
```
105118

106-
### Run Local Server With Docker
107-
108-
The easiest way to get started is using make to build a docker image and run the site:
109-
110-
```bash
111-
make docs
112-
```
113-
114-
Then navigate to <http://localhost:8765/SSVC/> to see the site.
115-
116-
Note that the docker container will display a message with the URL to visit, for
117-
example: `Serving on http://0.0.0.0:8000/SSVC/` in the output. However, that port
118-
is only available inside the container. The host port 8765 is mapped to the container's
119-
port 8000, so you should navigate to <http://localhost:8765/SSVC/> to see the site.
119+
### Run Local Docs Server
120120

121-
Or, if make is not available:
121+
The easiest way to get started is using make to build a docker image and run the site. However, we provide a few other options below.
122122

123-
```bash
124-
docker build --target docs --tag ssvc_docs .
125-
docker run --tty --rm -p 8765:8000 --volume .:/app ssvc_docs
126-
```
123+
| Environment | Command |
124+
|-------------|---------|
125+
| Make, Docker | `make docs` |
126+
| ~~Make~~, Docker | `cd docker && docker-compose up docs` |
127+
| ~~Make~~, ~~Docker~~ | `mkdocs serve` |
127128

128-
### Run Local Server Without Docker
129-
130-
If you prefer to run the site locally without Docker, you can do so with mkdocs.
131-
We recommend using a virtual environment to manage dependencies:
132-
133-
```bash
134-
python3 -m venv ssvc_venv
135-
pip install -r requirements.txt
136-
```
137-
138-
Start a local server:
139-
140-
```bash
141-
mkdocs serve
142-
```
143-
144-
By default, the server will run on port 8001.
145-
This is configured in the `mkdocs.yml` file.
146-
Navigate to <http://localhost:8001/> to see the site.
147-
148-
(Hint: You can use the `--dev-addr` argument with mkdocs to change the port, e.g. `mkdocs serve --dev-addr localhost:8000`)
129+
Then navigate to <http://localhost:8000/SSVC/> to see the site.
149130

150131
## Run tests
151132

152133
We include a few tests for the `ssvc` module.
134+
Options for running the test suite are provided below.
153135

154-
### Run Tests With Docker
155-
156-
The easiest way to run tests is using make to build a docker image and run the tests:
136+
| Environment | Command | Comment |
137+
|-------------|---------|---------|
138+
| Make, Docker | `make docker_test` | runs in docker container |
139+
| ~~Make~~, Docker | `cd docker && docker-compose run -rm test` | runs in docker container |
140+
| Make, ~~Docker~~ | `make test` | runs in host OS |
141+
| ~~Make~~, ~~Docker~~ | `pytest src/test` | runs in host OS |
157142

158-
```bash
159-
make docker_test
160-
```
161-
162-
Or, if make is not available:
163-
164-
```bash
165-
docker build --target test --tag ssvc_test .
166-
docker run --tty --rm --volume .:/app ssvc_test
167-
```
168-
169-
### Run Tests Without Docker
170-
171-
```bash
172-
pip install pytest
173-
pytest src/test
174-
```
175143

176144
## Environment Variables
177145

Dockerfile renamed to docker/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ WORKDIR /app
55
FROM base AS dependencies
66

77
# install requirements
8-
COPY requirements.txt .
8+
COPY ../requirements.txt .
99
RUN pip install -r requirements.txt
1010
# Copy the files we need
11-
COPY . /app
11+
COPY .. /app
1212
# Set the environment variable
1313
ENV PYTHONPATH=/app/src
1414

docker/docker-compose.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
services:
2+
base:
3+
build:
4+
context: ..
5+
dockerfile: docker/Dockerfile
6+
target: base
7+
image: base:latest
8+
9+
dependencies:
10+
build:
11+
context: ..
12+
dockerfile: docker/Dockerfile
13+
target: dependencies
14+
image: dependencies:latest
15+
depends_on:
16+
- base
17+
18+
test:
19+
build:
20+
context: ..
21+
dockerfile: docker/Dockerfile
22+
target: test
23+
image: test:latest
24+
depends_on:
25+
- dependencies
26+
27+
docs:
28+
build:
29+
context: ..
30+
dockerfile: docker/Dockerfile
31+
target: docs
32+
image: docs:latest
33+
depends_on:
34+
- dependencies
35+
ports:
36+
- "8000:8000"

0 commit comments

Comments
 (0)