From 6388f47aa79b9e563f2da1466fea2d9512f0f7d1 Mon Sep 17 00:00:00 2001 From: Mike Kolesnik Date: Wed, 6 Dec 2023 13:15:11 +0200 Subject: [PATCH] Genericize base dapper logic 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 --- .dapper | 3 +- .github/workflows/consuming.yml | 6 +- Dockerfile.dapper | 3 +- Makefile.dapper | 76 ++---------------------- Makefile.dapper.base | 79 +++++++++++++++++++++++++ Makefile.inc | 1 + package/Dockerfile.shipyard-dapper-base | 2 +- package/Dockerfile.shipyard-linting | 2 +- 8 files changed, 94 insertions(+), 78 deletions(-) create mode 100644 Makefile.dapper.base diff --git a/.dapper b/.dapper index 71326dddb..b7f5cbabc 100755 --- a/.dapper +++ b/.dapper @@ -46,7 +46,7 @@ do set -x ;; --version|-v) - echo Submariner Dapper + echo Shipyard Dapper exit 0 ;; --mount-suffix|-S) @@ -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}" \ . diff --git a/.github/workflows/consuming.yml b/.github/workflows/consuming.yml index dc5f3c180..f8cf68df7 100644 --- a/.github/workflows/consuming.yml +++ b/.github/workflows/consuming.yml @@ -59,7 +59,7 @@ jobs: run: make -C shipyard images - name: Copy Shipyard resources - run: cp -n shipyard/{Dockerfile.*,Makefile.dapper,.dapper} . + run: cp -n shipyard/{Dockerfile.*,Makefile.dapper*,.dapper} . - name: Make sure ${{ matrix.project }} is using the built Shipyard image run: sed -i 's/shipyard-dapper-base:*.*/shipyard-dapper-base:dev/' Dockerfile.dapper @@ -107,7 +107,7 @@ jobs: path: ${{ matrix.project }} - name: Copy Shipyard resources - run: cp -n Dockerfile.* Makefile.dapper .dapper ${{ matrix.project }}/ + run: cp -n Dockerfile.* Makefile.dapper* .dapper ${{ matrix.project }}/ - name: Make sure ${{ matrix.project }} is using the built Shipyard image run: sed -i 's/shipyard-dapper-base:*.*/shipyard-dapper-base:dev/' ${{ matrix.project }}/Dockerfile.dapper @@ -162,7 +162,7 @@ jobs: path: ${{ matrix.project }} - name: Copy Shipyard resources - run: cp -n Dockerfile.* Makefile.dapper .dapper ${{ matrix.project }}/ + run: cp -n Dockerfile.* Makefile.dapper* .dapper ${{ matrix.project }}/ - name: Make sure ${{ matrix.project }} is using the built Shipyard image run: sed -i 's/shipyard-dapper-base:*.*/shipyard-dapper-base:dev/' ${{ matrix.project }}/Dockerfile.dapper diff --git a/Dockerfile.dapper b/Dockerfile.dapper index f162560bc..76eea7dbe 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -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 diff --git a/Makefile.dapper b/Makefile.dapper index a73e854c0..6ed07ed04 100644 --- a/Makefile.dapper +++ b/Makefile.dapper @@ -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 @@ -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 diff --git a/Makefile.dapper.base b/Makefile.dapper.base new file mode 100644 index 000000000..4b9d08f02 --- /dev/null +++ b/Makefile.dapper.base @@ -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) diff --git a/Makefile.inc b/Makefile.inc index 8cb9b8f7e..6a783200c 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -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) diff --git a/package/Dockerfile.shipyard-dapper-base b/package/Dockerfile.shipyard-dapper-base index 42988e488..af8cbf052 100644 --- a/package/Dockerfile.shipyard-dapper-base +++ b/package/Dockerfile.shipyard-dapper-base @@ -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/ . diff --git a/package/Dockerfile.shipyard-linting b/package/Dockerfile.shipyard-linting index b93ecca53..831fdaedd 100644 --- a/package/Dockerfile.shipyard-linting +++ b/package/Dockerfile.shipyard-linting @@ -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/ .