Skip to content

Commit d6aaec5

Browse files
committed
Add make develop for developing in Docker
1 parent aa06bd5 commit d6aaec5

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

batch-processing/Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,27 @@ RUN go mod download
4242
COPY *.go ./
4343
COPY inputs /inputs
4444

45+
# This is required for test and run, but for develop it ensures we have a build cache
46+
RUN go build -o /out
4547

4648
##
4749
## TEST
4850
##
4951
FROM base as test
5052

51-
RUN go build -o /out
5253
ENTRYPOINT [ "go", "test", "-v" ]
5354

55+
##
56+
## DEVELOP
57+
##
58+
FROM base as develop
59+
60+
ENTRYPOINT [ "/bin/bash" ]
61+
5462
##
5563
## RUN
5664
##
5765
FROM base as run
5866

59-
RUN go build -o /out
6067
WORKDIR /
6168
ENTRYPOINT ["/out", "--input", "/inputs/example.csv"]

batch-processing/IMPLEMENTATION.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,37 @@ The download is simple — create a file in a temporary location, and `http.Get`
3131
### `imagemagick`
3232

3333
To run ImageMagick (and this whole thing) in a repeatable way, we will do it all in a Docker container based on `dpokidov/imagemagick:latest-bullseye` using multi-stage build. This will give us the `magick` command.
34+
35+
To be able to run the tests and the app, we end up with multiple targets:
36+
37+
```Dockerfile
38+
FROM golang:1.19-bullseye as base
39+
40+
# ... install dependencies & build ...
41+
42+
FROM base as test
43+
44+
# ... run tests ...
45+
46+
FROM base as run
47+
48+
# ... run app ...
49+
```
50+
51+
Which can then be built by specifying the `--target`:
52+
53+
```console
54+
> docker build --target test -t test .
55+
```
56+
57+
### Developing in Docker
58+
59+
To develop the app with Docker, we need a slightly fancier command:
60+
61+
```Makefile
62+
develop:
63+
mkdir -p mount
64+
docker build --target develop -t develop .
65+
docker run -it --mount type=bind,source="$$(pwd)",target=/app --mount type=bind,source="/tmp",target=/tmp --rm develop
66+
rm -rf ./mount
67+
```

batch-processing/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ test:
44
docker build --target test -t test .
55
docker run --rm test
66

7+
develop:
8+
mkdir -p mount
9+
docker build --target develop -t develop .
10+
docker run -it --mount type=bind,source="$$(pwd)",target=/app --mount type=bind,source="/tmp",target=/tmp --rm develop
11+
rm -rf ./mount
12+
713
run:
814
docker build --target run -t run .
915
docker run --rm run

0 commit comments

Comments
 (0)