-
Notifications
You must be signed in to change notification settings - Fork 2.3k
make: add docker-dev-* targets for building dev images #10912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ZZiigguurraatt
wants to merge
1
commit into
lightningnetwork:master
Choose a base branch
from
ZZiigguurraatt:make_dev_Dockerfile
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+115
−4
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -213,6 +213,67 @@ docker-tools: | |
| @$(call print, "Building tools docker image.") | ||
| docker build -q -t lnd-tools $(TOOLS_DIR) | ||
|
|
||
| # Short commit hash of the working tree, with a `-dirty` suffix if there are | ||
| # uncommitted changes. Unlike $(COMMIT), this never picks up submodule tags | ||
| # like `kvdb/v1.5.1` — `/` is not a valid character in a docker image tag. | ||
| # `--match='__no_such_tag__'` forces `git describe` to ignore all tags so | ||
| # `--always` falls back to the short hash. | ||
| DOCKER_DEV_COMMIT := $(shell git describe --always --dirty --match='__no_such_tag__') | ||
|
|
||
| # Image (name:tag) produced by `docker-dev-build`. Also consumed by | ||
| # `docker-dev-lndinit-build` so the lndinit image is always layered on | ||
| # whatever `docker-dev-build` just built. Defaults to `lnd-dev:<short-hash>` | ||
| # (e.g. `lnd-dev:f5a093c1f` on commit f5a093c1f). | ||
| DOCKER_DEV_IMAGE ?= lnd-dev:$(DOCKER_DEV_COMMIT) | ||
|
|
||
| # Repository name for the lndinit dev image; the tag is always | ||
| # `lnd-dev-$(DOCKER_DEV_COMMIT)` so it's obvious which docker-dev-build image | ||
| # the lndinit image was layered on. | ||
| LNDINIT_REPO ?= lndinit | ||
|
|
||
| # Build context (path or git URL with optional #ref) for lndinit's dev.Dockerfile. | ||
| # NOTE: `#` is escaped as `\#` so make doesn't treat the ref as a comment. | ||
| LNDINIT_CONTEXT ?= https://github.com/lightninglabs/lndinit.git\#main | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want to set this to a release instead of tracking the default branch? cons are we would have to remember to update here when we have new lndinit releases. |
||
|
|
||
| # Full lndinit image name:tag, derived from LNDINIT_REPO and DOCKER_DEV_COMMIT. | ||
| LNDINIT_IMAGE := $(LNDINIT_REPO):lnd-dev-$(DOCKER_DEV_COMMIT) | ||
|
|
||
| # dev.Dockerfile uses BuildKit cache mounts unconditionally, so these targets | ||
| # always go through `docker buildx build`. | ||
| #? docker-dev-build: Build a development docker image from dev.Dockerfile (override DOCKER_DEV_IMAGE=<name:tag>) | ||
| docker-dev-build: | ||
| @$(call print, "Building dev docker image $(DOCKER_DEV_IMAGE).") | ||
| docker buildx build -t $(DOCKER_DEV_IMAGE) -f dev.Dockerfile . | ||
|
|
||
| #? 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>) | ||
| docker-dev-lndinit-build: docker-dev-build | ||
| @$(call print, "Building lndinit docker image $(LNDINIT_IMAGE) on top of $(DOCKER_DEV_IMAGE).") | ||
| IMG='$(DOCKER_DEV_IMAGE)'; \ | ||
| TAG="$${IMG##*:}"; \ | ||
| case "$$IMG" in \ | ||
| *:*) case "$$TAG" in */*) HAS_TAG=no ;; *) HAS_TAG=yes ;; esac ;; \ | ||
| *) HAS_TAG=no ;; \ | ||
| esac; \ | ||
| if [ "$$HAS_TAG" != yes ]; then \ | ||
| echo "DOCKER_DEV_IMAGE=$$IMG has no tag; set DOCKER_DEV_IMAGE=<name>:<tag>" >&2; \ | ||
| exit 1; \ | ||
| fi; \ | ||
| CTX='$(LNDINIT_CONTEXT)'; \ | ||
| if [ -d "$$CTX" ]; then \ | ||
| DOCKERFILE="$$CTX/dev.Dockerfile"; \ | ||
| else \ | ||
| DOCKERFILE=dev.Dockerfile; \ | ||
| fi; \ | ||
| docker buildx build \ | ||
| --build-arg BASE_IMAGE="$${IMG%:*}" \ | ||
| --build-arg BASE_IMAGE_VERSION="$$TAG" \ | ||
| -t $(LNDINIT_IMAGE) -f "$$DOCKERFILE" "$$CTX" | ||
|
ZZiigguurraatt marked this conversation as resolved.
|
||
|
|
||
| #? 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. | ||
| docker-dev-lndinit-build-push: docker-dev-lndinit-build | ||
| @$(call print, "Pushing lndinit docker image $(LNDINIT_IMAGE).") | ||
| docker push $(LNDINIT_IMAGE) | ||
|
|
||
| scratch: build | ||
|
|
||
|
|
||
|
|
@@ -551,4 +612,7 @@ clean-docker-volumes: | |
| android \ | ||
| mobile \ | ||
| clean \ | ||
| clean-docker-volumes | ||
| clean-docker-volumes \ | ||
| docker-dev-build \ | ||
| docker-dev-lndinit-build \ | ||
| docker-dev-lndinit-build-push | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
makeis run outside of a git repository (e.g., from a source archive or in a bare container),git describewill fail and print an error to stderr, resulting in an emptyDOCKER_DEV_COMMIT. This causesDOCKER_DEV_IMAGEto be tagged aslnd-dev:, which is an invalid Docker tag. Adding a fallback tolatestand redirecting stderr to/dev/nullmakes the build more robust in non-git environments.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we care about this since we already have
gitused by another of other things in the makefile without this safeguard?