Skip to content

Commit

Permalink
Genericize base dapper logic
Browse files Browse the repository at this point in the history
Make base dapper logic project agnostic so that it can be consumed by
projects outside the submariner org.
This mainly involves moving out basic dapper functions out to
`Makefile.dapper.base` and adding an `ORG` argument to specify the
organization.
References to `submariner-io` have been removed where possible.

Signed-off-by: Mike Kolesnik <[email protected]>
  • Loading branch information
mkolesnik committed Dec 6, 2023
1 parent efed096 commit 52bf7c3
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 75 deletions.
3 changes: 2 additions & 1 deletion .dapper
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ do
set -x
;;
--version|-v)
echo Submariner Dapper
echo Shipyard Dapper
exit 0
;;
--mount-suffix|-S)
Expand Down Expand Up @@ -74,6 +74,7 @@ gitid="${gitid:-$(git show --format=%h -s)}"
container="$(basename "$(pwd)"):${gitid}"
DOCKER_BUILDKIT=1 docker build -t "${container}" -f "${file}" \
--build-arg "BASE_BRANCH=${BASE_BRANCH:-devel}" \
--build-arg "ORG=${ORG}" \
--build-arg "PROJECT=${PROJECT}" \
.

Expand Down
3 changes: 2 additions & 1 deletion Dockerfile.dapper
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
ARG BASE_BRANCH
FROM quay.io/submariner/shipyard-dapper-base:${BASE_BRANCH}

ARG ORG
ARG PROJECT
ENV DAPPER_ENV="CI QUAY_USERNAME QUAY_PASSWORD MAKEFLAGS PLUGIN TEST_ARGS E2E_TESTDIR GITHUB_USER GITHUB_TOKEN USING" \
DAPPER_SOURCE=/go/src/github.com/submariner-io/${PROJECT} DAPPER_DOCKER_SOCKET=true
DAPPER_SOURCE=/go/src/github.com/${ORG}/${PROJECT} DAPPER_DOCKER_SOCKET=true
ENV OVN_DIR=${DAPPER_SOURCE}/ovn-kubernetes
ENV DAPPER_OUTPUT=${DAPPER_SOURCE}/output

Expand Down
76 changes: 5 additions & 71 deletions Makefile.dapper
Original file line number Diff line number Diff line change
@@ -1,72 +1,16 @@
# This Makefile contains the rules required to set up our
# Dapper-based build environment

, := ,
ORG ?= submariner-io
PROJECT ?= $(notdir $(CURDIR))
BASE_DAPPER := Dockerfile.dapper
USING = $(subst $(,), ,$(using))
LINTING_DAPPER := Dockerfile.linting
LINTING_GOALS := gitlint shellcheck yamllint markdownlint
NON_DAPPER_GOALS += .dapper shell targets $(LINTING_GOALS)
export MAKEFLAGS
export ORG
export PROJECT
export USING

# Define LOCAL_BUILD to build directly on the host and not inside a Dapper container
ifdef LOCAL_BUILD
DAPPER_HOST_ARCH ?= $(shell go env GOHOSTARCH)
SHIPYARD_DIR ?= ../shipyard
SCRIPTS_DIR ?= $(SHIPYARD_DIR)/scripts/shared

export DAPPER_HOST_ARCH
export SHIPYARD_DIR
export SCRIPTS_DIR

RUN_IN_DAPPER :=

.dapper:

else

.dapper:
@echo Downloading dapper
@curl -sfLO https://raw.githubusercontent.com/submariner-io/shipyard/$(BASE_BRANCH)/$@
@chmod +x .dapper
@./.dapper -v

SELINUX_CONTEXT := $(shell (selinuxenabled && echo -S z) 2>/dev/null)
RUN_IN_DAPPER = ./.dapper $(DAPPER_ARGS) $(SELINUX_CONTEXT) --

endif

ifeq (true,$(DEBUG_PRINT))
MAKE_DEBUG_FLAG = --debug=b
endif

USING = $(subst $(,), ,$(using))
_using = ${USING}

ifneq (,$(filter dual-stack,$(_using)))
IPV6_FLAGS = --ipv6 --subnet fc00:1234:4444::/64
endif

# Only run command line goals in dapper (except things that have to run outside of dapper).
# Otherwise, make applies this rule to various files and tries to build them in dapper (which doesn't work, obviously).
$(filter-out .dapper prune-images shell targets $(NON_DAPPER_GOALS),$(MAKECMDGOALS)): .dapper $(BASE_DAPPER)
@[ -z "$$CI" ] || echo "::group::Launching a container to run 'make $@'"
-docker network create $(IPV6_FLAGS) -d bridge kind
+$(RUN_IN_DAPPER) make $(MAKE_DEBUG_FLAG) $@

# The original dockerfiles will live in Shipyard and be downloaded by consuming projects.
$(BASE_DAPPER) $(LINTING_DAPPER):
Makefile.dapper.base:
@echo Downloading $@
@curl -sfLO https://raw.githubusercontent.com/submariner-io/shipyard/$(BASE_BRANCH)/$@

# Run silently as the commands are pretty straightforward and `make` hasn't a lot to do
$(LINTING_GOALS): DAPPER_ARGS := -f $(LINTING_DAPPER)
$(LINTING_GOALS): .dapper $(LINTING_DAPPER)
@[ -z "$$CI" ] || echo "::group::Launching a container to run 'make $@'"
@$(RUN_IN_DAPPER) make $@
include Makefile.dapper.base

# [prune-images] removes all Submariner-provided images and all untagged images
# Use this to ensure you use current images
Expand All @@ -81,14 +25,4 @@ prune-images:
fi \
done

shell: DAPPER_ARGS := -s
shell: .dapper $(BASE_DAPPER)
$(RUN_IN_DAPPER)

# Run silently to just list the targets (hence we can't use the generic dapper wrapper recipe).
# This only lists targets accessible inside dapper (which are 99% of targets we use)
targets: DAPPER_ARGS := -f $(LINTING_DAPPER)
targets: $(LINTING_DAPPER)
@$(RUN_IN_DAPPER) eval "\$${SCRIPTS_DIR}/targets.sh"

.PHONY: prune-images shell targets $(LINTING_GOALS)
.PHONY: prune-images
79 changes: 79 additions & 0 deletions Makefile.dapper.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# This Makefile contains the rules required to set up our
# Dapper-based build environment

, := ,
BASE_DAPPER := Dockerfile.dapper
USING = $(subst $(,), ,$(using))
LINTING_DAPPER := Dockerfile.linting
LINTING_GOALS := gitlint shellcheck yamllint markdownlint
NON_DAPPER_GOALS += .dapper shell targets $(LINTING_GOALS)
export MAKEFLAGS
export USING

# Define LOCAL_BUILD to build directly on the host and not inside a Dapper container
ifdef LOCAL_BUILD
DAPPER_HOST_ARCH ?= $(shell go env GOHOSTARCH)
SHIPYARD_DIR ?= ../shipyard
SCRIPTS_DIR ?= $(SHIPYARD_DIR)/scripts/shared

export DAPPER_HOST_ARCH
export SHIPYARD_DIR
export SCRIPTS_DIR

RUN_IN_DAPPER :=

.dapper:

else

.dapper:
@echo Downloading dapper
@curl -sfLO https://raw.githubusercontent.com/submariner-io/shipyard/$(BASE_BRANCH)/$@
@chmod +x .dapper
@./.dapper -v

SELINUX_CONTEXT := $(shell (selinuxenabled && echo -S z) 2>/dev/null)
RUN_IN_DAPPER = ./.dapper $(DAPPER_ARGS) $(SELINUX_CONTEXT) --

endif

ifeq (true,$(DEBUG_PRINT))
MAKE_DEBUG_FLAG = --debug=b
endif

USING = $(subst $(,), ,$(using))
_using = ${USING}

ifneq (,$(filter dual-stack,$(_using)))
IPV6_FLAGS = --ipv6 --subnet fc00:1234:4444::/64
endif

# Only run command line goals in dapper (except things that have to run outside of dapper).
# Otherwise, make applies this rule to various files and tries to build them in dapper (which doesn't work, obviously).
$(filter-out .dapper prune-images shell targets $(NON_DAPPER_GOALS),$(MAKECMDGOALS)): .dapper $(BASE_DAPPER)
@[ -z "$$CI" ] || echo "::group::Launching a container to run 'make $@'"
-docker network create $(IPV6_FLAGS) -d bridge kind
+$(RUN_IN_DAPPER) make $(MAKE_DEBUG_FLAG) $@

# The original dockerfiles will live in Shipyard and be downloaded by consuming projects.
$(BASE_DAPPER) $(LINTING_DAPPER):
@echo Downloading $@
@curl -sfLO https://raw.githubusercontent.com/submariner-io/shipyard/$(BASE_BRANCH)/$@

# Run silently as the commands are pretty straightforward and `make` hasn't a lot to do
$(LINTING_GOALS): DAPPER_ARGS := -f $(LINTING_DAPPER)
$(LINTING_GOALS): .dapper $(LINTING_DAPPER)
@[ -z "$$CI" ] || echo "::group::Launching a container to run 'make $@'"
@$(RUN_IN_DAPPER) make $@

shell: DAPPER_ARGS := -s
shell: .dapper $(BASE_DAPPER)
$(RUN_IN_DAPPER)

# Run silently to just list the targets (hence we can't use the generic dapper wrapper recipe).
# This only lists targets accessible inside dapper (which are 99% of targets we use)
targets: DAPPER_ARGS := -f $(LINTING_DAPPER)
targets: $(LINTING_DAPPER)
@$(RUN_IN_DAPPER) eval "\$${SCRIPTS_DIR}/targets.sh"

.PHONY: shell targets $(LINTING_GOALS)
1 change: 1 addition & 0 deletions Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ endef
check_shipyard_file=$(if $(wildcard $(SHIPYARD_DIR)/$(1)),$(if $(wildcard $(1)),$(call _check_shipyard_file,$(1)),),)

$(call check_shipyard_file,Makefile.dapper)
$(call check_shipyard_file,Makefile.dapper.base)
$(call check_shipyard_file,Dockerfile.dapper)
$(call check_shipyard_file,Dockerfile.linting)

Expand Down
2 changes: 1 addition & 1 deletion package/Dockerfile.shipyard-dapper-base
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ COPY Makefile.* .gitlint ${SHIPYARD_DIR}/
# Copy the global dapper file so that we can make sure consuming projects are up to date
COPY Dockerfile.dapper ${SHIPYARD_DIR}/

# Copy CI deployment scripts into image to share with all submariner-io/* projects
# Copy CI deployment scripts into image to share with all projects
WORKDIR $SCRIPTS_DIR
COPY scripts/shared/ .

Expand Down
2 changes: 1 addition & 1 deletion package/Dockerfile.shipyard-linting
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ COPY Makefile.* .gitlint ${SHIPYARD_DIR}/
# Copy the global dapper file so that we can make sure consuming projects are up to date
COPY Dockerfile.linting ${SHIPYARD_DIR}/

# Copy shared scripts into image to share with all submariner-io/* projects
# Copy shared scripts into image to share with all projects
WORKDIR $SCRIPTS_DIR
COPY scripts/shared/ .

0 comments on commit 52bf7c3

Please sign in to comment.