Skip to content

Commit 13e4b8c

Browse files
make: add docker-dev-* targets for building dev images
Adds three make targets that wrap dev.Dockerfile: - docker-dev-build builds an lnd dev image, tagged $(DOCKER_DEV_IMAGE) (default lnd-dev:<short-hash>). - docker-dev-lndinit-build layers an lndinit image on top, tagged $(LNDINIT_REPO):lnd-dev-<short-hash> (default lndinit:...). - docker-dev-lndinit-build-push builds and pushes the lndinit image. All three targets go through `docker buildx build` so the BuildKit cache mounts added in 20e6518 are used.
1 parent f771e14 commit 13e4b8c

3 files changed

Lines changed: 106 additions & 4 deletions

File tree

Makefile

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,58 @@ docker-tools:
213213
@$(call print, "Building tools docker image.")
214214
docker build -q -t lnd-tools $(TOOLS_DIR)
215215

216+
# Short commit hash of the working tree, with a `-dirty` suffix if there are
217+
# uncommitted changes. Unlike $(COMMIT), this never picks up submodule tags
218+
# like `kvdb/v1.5.1` — `/` is not a valid character in a docker image tag.
219+
# `--match='__no_such_tag__'` forces `git describe` to ignore all tags so
220+
# `--always` falls back to the short hash.
221+
DOCKER_DEV_COMMIT := $(shell git describe --always --dirty --match='__no_such_tag__')
222+
223+
# Image (name:tag) produced by `docker-dev-build`. Also consumed by
224+
# `docker-dev-lndinit-build` so the lndinit image is always layered on
225+
# whatever `docker-dev-build` just built. Defaults to `lnd-dev:<short-hash>`
226+
# (e.g. `lnd-dev:f5a093c1f` on commit f5a093c1f).
227+
DOCKER_DEV_IMAGE ?= lnd-dev:$(DOCKER_DEV_COMMIT)
228+
229+
# Repository name for the lndinit dev image; the tag is always
230+
# `lnd-dev-$(DOCKER_DEV_COMMIT)` so it's obvious which docker-dev-build image
231+
# the lndinit image was layered on.
232+
LNDINIT_REPO ?= lndinit
233+
234+
# Build context (path or git URL with optional #ref) for lndinit's dev.Dockerfile.
235+
# NOTE: `#` is escaped as `\#` so make doesn't treat the ref as a comment.
236+
LNDINIT_CONTEXT ?= https://github.com/lightninglabs/lndinit.git\#main
237+
238+
# Full lndinit image name:tag, derived from LNDINIT_REPO and DOCKER_DEV_COMMIT.
239+
LNDINIT_IMAGE := $(LNDINIT_REPO):lnd-dev-$(DOCKER_DEV_COMMIT)
240+
241+
# dev.Dockerfile uses BuildKit cache mounts unconditionally, so these targets
242+
# always go through `docker buildx build`.
243+
#? docker-dev-build: Build a development docker image from dev.Dockerfile (override DOCKER_DEV_IMAGE=<name:tag>)
244+
docker-dev-build:
245+
@$(call print, "Building dev docker image $(DOCKER_DEV_IMAGE).")
246+
docker buildx build -t $(DOCKER_DEV_IMAGE) -f dev.Dockerfile .
247+
248+
#? docker-dev-lndinit-build: Build an lndinit dev image layered on the docker-dev-build image (override LNDINIT_REPO=<name>, LNDINIT_CONTEXT=<git ref or path>)
249+
docker-dev-lndinit-build: docker-dev-build
250+
@$(call print, "Building lndinit docker image $(LNDINIT_IMAGE) on top of $(DOCKER_DEV_IMAGE).")
251+
IMG='$(DOCKER_DEV_IMAGE)'; \
252+
CTX='$(LNDINIT_CONTEXT)'; \
253+
if [ -d "$$CTX" ]; then \
254+
DOCKERFILE="$$CTX/dev.Dockerfile"; \
255+
else \
256+
DOCKERFILE=dev.Dockerfile; \
257+
fi; \
258+
docker buildx build \
259+
--build-arg BASE_IMAGE="$${IMG%:*}" \
260+
--build-arg BASE_IMAGE_VERSION="$${IMG##*:}" \
261+
-t $(LNDINIT_IMAGE) -f "$$DOCKERFILE" "$$CTX"
262+
263+
#? docker-dev-lndinit-build-push: Build the lndinit dev image (via docker-dev-lndinit-build) and push $(LNDINIT_IMAGE). `docker login` to that registry must already be done.
264+
docker-dev-lndinit-build-push: docker-dev-lndinit-build
265+
@$(call print, "Pushing lndinit docker image $(LNDINIT_IMAGE).")
266+
docker push $(LNDINIT_IMAGE)
267+
216268
scratch: build
217269

218270

@@ -551,4 +603,7 @@ clean-docker-volumes:
551603
android \
552604
mobile \
553605
clean \
554-
clean-docker-volumes
606+
clean-docker-volumes \
607+
docker-dev-build \
608+
docker-dev-lndinit-build \
609+
docker-dev-lndinit-build-push

docs/DOCKER.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,45 @@ There are two flavors of Dockerfiles available:
1010

1111
## Development/testing
1212

13-
To build a standalone development image from the local source directory, use the
14-
following command:
13+
To build a standalone development image from the local source directory:
1514

1615
```shell
17-
$ docker build --tag=myrepository/lnd-dev -f dev.Dockerfile .
16+
$ make docker-dev-build
17+
```
18+
19+
The image is tagged `lnd-dev:<short-hash>` by default (with a `-dirty`
20+
suffix if the working tree has uncommitted changes); override with
21+
`make docker-dev-build DOCKER_DEV_IMAGE=myrepository/lnd-dev:mytag`.
22+
23+
To additionally build an `lndinit` image layered on top of the dev image
24+
(pulling `lndinit`'s `dev.Dockerfile` from upstream main):
25+
26+
```shell
27+
$ make docker-dev-lndinit-build
28+
```
29+
30+
The image is tagged `<LNDINIT_REPO>:lnd-dev-<short-hash>` (e.g.
31+
`lndinit:lnd-dev-f5a093c1f`) so the tag makes it obvious which
32+
`docker-dev-build` image it was layered on. `LNDINIT_REPO` defaults to
33+
`lndinit`; override to push to a registry, e.g. `myrepository/lndinit`.
34+
`LNDINIT_CONTEXT` is the build context that `docker buildx` pulls
35+
`lndinit`'s `dev.Dockerfile` from — defaults to
36+
`https://github.com/lightninglabs/lndinit.git#main`, but can be a local path
37+
(e.g. `../lndinit`) or any other git URL with an optional `#<ref>` suffix
38+
(branch, tag, or commit SHA). For example, to build lndinit from a local
39+
checkout under the `myrepository/lndinit` repo name:
40+
41+
```shell
42+
$ make docker-dev-lndinit-build \
43+
LNDINIT_REPO=myrepository/lndinit \
44+
LNDINIT_CONTEXT=../lndinit
45+
```
46+
47+
To build the `lndinit` image and push it to a registry you're already logged
48+
into in one step:
49+
50+
```shell
51+
$ make docker-dev-lndinit-build-push
1852
```
1953

2054
There is also a `docker-compose` setup available for development or testing that

docs/release-notes/release-notes-0.22.0.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,19 @@
111111
the build context is a remote git repository because COPY layers are more
112112
smartly compared to cache.
113113

114+
* [New `make` targets for `dev.Dockerfile`](https://github.com/lightningnetwork/lnd/pull/TBD):
115+
`docker-dev-build` builds a development image from `dev.Dockerfile`
116+
(tagged `lnd-dev:<short-hash>` by default; override with
117+
`DOCKER_DEV_IMAGE=`). `docker-dev-lndinit-build` layers an
118+
[`lndinit`](https://github.com/lightninglabs/lndinit) image on top of it
119+
(using `lndinit`'s upstream `dev.Dockerfile`; tagged
120+
`<LNDINIT_REPO>:lnd-dev-<short-hash>` so the tag reflects the underlying
121+
dev image — override the repo name with `LNDINIT_REPO=` and the build
122+
context with `LNDINIT_CONTEXT=`). `docker-dev-lndinit-build-push` builds
123+
and then pushes the lndinit image. All three go through
124+
`docker buildx build` so BuildKit cache mounts are used. See
125+
[`docs/DOCKER.md`](../DOCKER.md) for examples.
126+
114127
# Contributors (Alphabetical Order)
115128

116129
* bitromortac

0 commit comments

Comments
 (0)