Skip to content

Commit 26052f0

Browse files
committed
Makefile: implement "fully source containers" HMS-3883
1 parent bf7bbb9 commit 26052f0

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ dnf-json
1111
local.env
1212
__debug*
1313
coverage.txt
14+
container_built.info
15+
go.local.mod
16+
go.local.sum

Diff for: Makefile

+47
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,50 @@ push-check: generate build unit-tests
7373
exit 1; \
7474
fi
7575
@echo "All looks good - congratulations"
76+
77+
78+
# source where the other repos are locally
79+
# has to end with a trailing slash
80+
SRC_DEPS_EXTERNAL_CHECKOUT_DIR ?= ../
81+
82+
# either "docker" or "sudo podman"
83+
# podman needs to build as root as it also needs to run as root afterwards
84+
CONTAINER_EXECUTABLE ?= sudo podman
85+
DOCKER_IMAGE := image-builder_devel
86+
DOCKERFILE := distribution/Dockerfile-ubi
87+
88+
SRC_DEPS_EXTERNAL_NAMES := community-gateway osbuild-composer
89+
SRC_DEPS_EXTERNAL_DIRS := $(addprefix $(SRC_DEPS_EXTERNAL_CHECKOUT_DIR),$(SRC_DEPS_EXTERNAL_NAMES))
90+
91+
SRC_DEPS_DIRS := internal cmd
92+
93+
# All files to check for rebuild!
94+
SRC_DEPS := $(shell find $(SRC_DEPS_DIRS) -name *.go)
95+
SRC_DEPS_EXTERNAL := $(shell find $(SRC_DEPS_EXTERNAL_DIRS) -name *.go)
96+
97+
$(SRC_DEPS_EXTERNAL_DIRS):
98+
@for DIR in $@; do if ! [ -d $$DIR ]; then echo "Please checkout $$DIR so it is available at $$DIR"; exit 1; fi; done
99+
100+
GOPROXY ?= https://proxy.golang.org,direct
101+
102+
GOMODARGS ?= -modfile=go.local.mod
103+
104+
go.local.mod go.local.sum: $(SRC_DEPS_EXTERNAL_DIRS) go.mod $(SRC_DEPS_EXTERNAL) $(SRC_DEPS)
105+
cp go.mod go.local.mod
106+
cp go.sum go.local.sum
107+
go mod edit $(GOMODARGS) -replace github.com/osbuild/osbuild-composer/pkg/splunk_logger=$(SRC_DEPS_EXTERNAL_CHECKOUT_DIR)osbuild-composer/pkg/splunk_logger
108+
go mod edit $(GOMODARGS) -replace github.com/osbuild/community-gateway=$(SRC_DEPS_EXTERNAL_CHECKOUT_DIR)community-gateway
109+
env GOPROXY=$(GOPROXY) go mod vendor $(GOMODARGS)
110+
111+
container_built.info: go.local.mod $(DOCKERFILE) $(SRC_DEPS)
112+
$(CONTAINER_EXECUTABLE) build -t $(DOCKER_IMAGE) -f $(DOCKERFILE) --build-arg GOMODARGS=$(GOMODARGS) .
113+
echo "Container last built on" > $@
114+
date >> $@
115+
116+
.PHONY: container
117+
container: container_built.info
118+
119+
.PHONY: clean
120+
clean:
121+
rm -f container_built.info
122+
rm -f go.local.*

Diff for: distribution/Dockerfile-ubi

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ WORKDIR $GOPATH/go/src/github.com/osbuild/image-builder
77
# a repository owned by a different user.
88
COPY --chown=1001 . .
99
ENV GOFLAGS=-mod=vendor
10-
RUN go install ./...
10+
11+
ARG GOPROXY=https://proxy.golang.org,direct
12+
RUN go env -w GOPROXY=$GOPROXY
13+
14+
ARG GOMODARGS=""
15+
16+
RUN go install $GOMODARGS ./...
1117

1218
FROM registry.access.redhat.com/ubi9/go-toolset:latest AS builder2
1319
RUN go install github.com/jackc/tern@latest

0 commit comments

Comments
 (0)