mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-11-03 09:18:05 +00:00
This updates the build of the two image caches to use the `pkg/package.mk` infrastructure, albeit in a slightly (ok, very) atypical way. In order to share the bulk of the build code (including the `Dockerfile` and the `Makefile` machinery to download the images) we arrange for the necessary bits to be copied at build time into distinct subdirectories and for the `pkg/package.mk` to be aware of this possibility. Since pkg/package.mk is only set up to build a single package we use a single `image-cache/Makefile` to drive the whole process and recurse into `Makefile.pkg` to build individual packages. One particular subtlety is that the package hash is based on the `image-cache` directory (which is in `git`) rather than the generated subdirectories (which are not in `git`). Since all the generators (and their inputs) are in the `image-cache` directory this is what we want. This means that the two images are given the same tag, but this is deliberate and desirable. The generated directories are completely temporary to avoid picking up stale versions of images when versions are updated. Images are hardlinked into place. The images are moved to the linuxkitprojects org. Using a dev tag for now, will update once everything is in place. Also use "tag" rather than "build" where appropriate in the Makefile. There is no point in the .dockerignore now, but add a .gitignore. Signed-off-by: Ian Campbell <ijc@docker.com>
67 lines
1.7 KiB
Makefile
67 lines
1.7 KiB
Makefile
.PHONY: image tag show-tag
|
|
default: push
|
|
|
|
ORG?=linuxkit
|
|
SOURCE ?= .
|
|
|
|
# Hash is of $(CURDIR) not $(CURDIR)$(SOURCE) to allow autogenerated
|
|
# source subdirectories (which would not be covered by ls-tree, but
|
|
# the code which autogenerates should be in $(CURDIR) so that is what
|
|
# we want to use.
|
|
ifeq ($(HASH),)
|
|
HASH_COMMIT?=HEAD # Setting this is only really useful with the show-tag target
|
|
HASH?=$(shell git ls-tree --full-tree $(HASH_COMMIT) -- $(CURDIR) | awk '{print $$3}')
|
|
|
|
ifneq ($(HASH_COMMIT),HEAD) # Others can't be dirty by definition
|
|
DIRTY:=$(shell git update-index -q --refresh && git diff-index --quiet HEAD -- $(CURDIR) || echo "-dirty")
|
|
endif
|
|
endif
|
|
|
|
TAG:=$(ORG)/$(IMAGE):$(HASH)$(DIRTY)
|
|
|
|
REPO?=https://github.com/linuxkit/linuxkit
|
|
ifneq ($(REPO),)
|
|
REPO_LABEL=--label org.opencontainers.image.source=$(REPO)
|
|
endif
|
|
ifeq ($(DIRTY),)
|
|
REPO_COMMIT=$(shell git rev-parse HEAD)
|
|
COMMIT_LABEL=--label org.opencontainers.image.revision=$(REPO_COMMIT)
|
|
endif
|
|
LABELS=$(REPO_LABEL) $(COMMIT_LABEL)
|
|
|
|
BASE_DEPS=Dockerfile Makefile
|
|
|
|
# Get a release tag, if present
|
|
RELEASE:=$(shell git tag -l --points-at HEAD)
|
|
|
|
ifdef NETWORK
|
|
NET_OPT=
|
|
else
|
|
NET_OPT=--network=none
|
|
endif
|
|
|
|
ifeq ($(DOCKER_CONTENT_TRUST),)
|
|
ifndef NOTRUST
|
|
export DOCKER_CONTENT_TRUST=1
|
|
endif
|
|
endif
|
|
|
|
show-tag:
|
|
@echo $(TAG)
|
|
|
|
tag: $(BASE_DEPS) $(DEPS)
|
|
docker pull $(TAG) || docker build $(LABELS) $(NET_OPT) -t $(TAG) $(SOURCE)
|
|
|
|
forcetag: $(BASE_DEPS) $(DEPS)
|
|
docker build $(LABELS) $(NET_OPT) -t $(TAG) $(SOURCE)
|
|
|
|
push: tag
|
|
ifneq ($(DIRTY),)
|
|
$(error Your repository is not clean. Will not push package image.)
|
|
endif
|
|
docker pull $(TAG) || docker push $(TAG)
|
|
ifneq ($(RELEASE),)
|
|
docker tag $(TAG) $(ORG)/$(IMAGE):$(RELEASE)
|
|
docker push $(ORG)/$(IMAGE):$(RELEASE)
|
|
endif
|