Skip to content

Commit

Permalink
Makefile: implement "fully source containers" HMS-3883
Browse files Browse the repository at this point in the history
  • Loading branch information
schuellerf committed Apr 22, 2024
1 parent b8d97b7 commit 64e2fe1
Show file tree
Hide file tree
Showing 12 changed files with 721 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ __pycache__
/tools/appsre-ansible/inventory

/docs/osbuild-composer.7
go.local.mod
go.local.sum
container_worker_built.info
container_composer_built.info
72 changes: 72 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ install: build
clean:
rm -rf $(BUILDDIR)/bin/
rm -rf $(CURDIR)/rpmbuild
rm -rf $(BUILDDIR)/build/
rm -f $(BUILDDIR)/go.local.*
rm -f $(BUILDDIR)/container_worker_built.info
rm -f $(BUILDDIR)/container_composer_built.info

.PHONY: push-check
push-check: build unit-tests srpm man
Expand Down Expand Up @@ -274,3 +278,71 @@ scratch: $(RPM_SPECFILE) $(RPM_TARBALL)
--nocheck \
$(RPM_SPECFILE)


# either "docker" or "sudo podman"
# podman needs to build as root as it also needs to run as root afterwards
CONTAINER_EXECUTABLE ?= sudo podman

DOCKER_IMAGE_WORKER := osbuild-worker_devel
DOCKERFILE_WORKER := distribution/Dockerfile-worker_srcinstall

DOCKER_IMAGE_COMPOSER := osbuild-composer_devel
DOCKERFILE_COMPOSER := distribution/Dockerfile-composer_srcinstall

GOPROXY ?= https://proxy.golang.org,direct

# source where the other repos are locally
# has to end with a trailing slash
SRC_DEPS_EXTERNAL_CHECKOUT_DIR ?= ../

# names of folder that have to be git-cloned additionally to be able
# to build all code
SRC_DEPS_EXTERNAL_NAMES := images pulp-client
SRC_DEPS_EXTERNAL_DIRS := $(addprefix $(SRC_DEPS_EXTERNAL_CHECKOUT_DIR),$(SRC_DEPS_EXTERNAL_NAMES))

$(SRC_DEPS_EXTERNAL_DIRS):
@for DIR in $@; do if ! [ -d $$DIR ]; then echo "Please checkout $$DIR so it is available at $$DIR"; exit 1; fi; done


SRC_DEPS_DIRS := internal cmd pkg repositories

# All files to check for rebuild!
SRC_DEPS := $(shell find $(SRC_DEPS_DIRS) -name *.go -or -name *.json)
SRC_DEPS_EXTERNAL := $(shell find $(SRC_DEPS_EXTERNAL_DIRS) -name *.go)

# dependencies to rebuild worker
WORKER_SRC_DEPS := $(SRC_DEPS)
# dependencies to rebuild composer
COMPOSER_SRC_DEPS := $(SRC_DEPS)

GOMODARGS ?= -modfile=go.local.mod

USE_BTRFS ?= yes

go.local.mod go.local.sum: $(SRC_DEPS_EXTERNAL_DIRS) go.mod $(SRC_DEPS_EXTERNAL) $(WORKER_SRC_DEPS) $(COMPOSER_SRC_DEPS) Makefile
cp go.mod go.local.mod
cp go.sum go.local.sum

go mod edit $(GOMODARGS) -replace github.com/osbuild/images=$(SRC_DEPS_EXTERNAL_CHECKOUT_DIR)images
go mod edit $(GOMODARGS) -replace github.com/osbuild/pulp-client=$(SRC_DEPS_EXTERNAL_CHECKOUT_DIR)pulp-client
go mod edit $(GOMODARGS) -replace github.com/osbuild/osbuild-composer/pkg/splunk_logger=./pkg/splunk_logger
env GOPROXY=$(GOPROXY) go mod tidy $(GOMODARGS)
env GOPROXY=$(GOPROXY) go mod vendor $(GOMODARGS)

container_worker_built.info: go.local.mod $(WORKER_SRC_DEPS) $(DOCKERFILE_WORKER)
$(CONTAINER_EXECUTABLE) build -t $(DOCKER_IMAGE_WORKER) -f $(DOCKERFILE_WORKER) --build-arg GOMODARGS=$(GOMODARGS) --build-arg USE_BTRFS=$(USE_BTRFS) .
echo "Worker last built on" > $@
date >> $@

container_composer_built.info: go.local.mod $(COMPOSER_SRC_DEPS) $(DOCKERFILE_COMPOSER)
$(CONTAINER_EXECUTABLE) build -t $(DOCKER_IMAGE_COMPOSER) -f $(DOCKERFILE_COMPOSER) --build-arg GOMODARGS=$(GOMODARGS) .
echo "Composer last built on" > $@
date >> $@

# build a container with a worker from full source
.PHONY: container_worker
container_worker: container_worker_built.info

# build a container with the composer from full source
.PHONY: container_composer
container_composer: container_composer_built.info
Loading

0 comments on commit 64e2fe1

Please sign in to comment.