|
| 1 | +# Makefile.docker |
| 2 | +# |
| 3 | +# This file defines all Docker targets. |
| 4 | + |
| 5 | +PROJECT_ROOT := $(dir $(abspath $(lastword ${MAKEFILE_LIST}))) |
| 6 | +PROJECT_VERSION := $(shell make --no-print-directory -C ${PROJECT_ROOT} -f Makefile.package info-version) |
| 7 | + |
| 8 | +UBUNTU_NAME := ubuntu |
| 9 | +UBUNTU_VERSIONS := 18.04 20.04 22.04 |
| 10 | + |
| 11 | +DOCKER := DOCKER_BUILDKIT=1 docker |
| 12 | +DOCKER_IMAGE_NAME := cloe/cloe-engine |
| 13 | +DOCKER_IMAGE_VERSION := ${PROJECT_VERSION} |
| 14 | +DOCKER_IMAGE := ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION} |
| 15 | +DOCKER_CONTEXT := ${PROJECT_ROOT} |
| 16 | + |
| 17 | +DOCKER_USER_ARGS += |
| 18 | +DOCKER_BUILD_ARGS += --build-arg PROJECT_VERSION=${PROJECT_VERSION} |
| 19 | +DOCKER_RUN_ARGS += -it --rm |
| 20 | + |
| 21 | +ifndef (${https_proxy},) |
| 22 | + DOCKER_NETWORK := host |
| 23 | + DOCKER_BUILD_ARGS += --network=host \ |
| 24 | + --build-arg https_proxy="${https_proxy}" \ |
| 25 | + --build-arg http_proxy="${http_proxy}" \ |
| 26 | + --build-arg no_proxy="${no_proxy}" |
| 27 | + DOCKER_RUN_ARGS += --network=host \ |
| 28 | + --env https_proxy="${https_proxy}" \ |
| 29 | + --env http_proxy="${http_proxy}" \ |
| 30 | + --env no_proxy="${no_proxy}" |
| 31 | +else |
| 32 | + DOCKER_NETWORK := internal |
| 33 | +endif |
| 34 | + |
| 35 | +ifeq ($(shell [ -f ${PROJECT_ROOT}/setup.sh ] && echo "true"),true) |
| 36 | +DOCKER_BUILD_ARGS += --secret id=setup,src=${PROJECT_ROOT}/setup.sh |
| 37 | +DOCKER_RUN_ARGS += -v ${PROJECT_ROOT}/setup.sh:/root/setup.sh |
| 38 | +endif |
| 39 | + |
| 40 | +ifneq (${CONAN_PROFILE},) |
| 41 | +DOCKER_BUILD_ARGS += --build-arg CONAN_PROFILE=${CONAN_PROFILE} |
| 42 | +endif |
| 43 | + |
| 44 | +ifneq (${VENDOR_TARGET},) |
| 45 | +DOCKER_BUILD_ARGS += --build-arg VENDOR_TARGET=${VENDOR_TARGET} |
| 46 | +endif |
| 47 | + |
| 48 | +ifneq (${PACKAGE_TARGET},) |
| 49 | +DOCKER_BUILD_ARGS += --build-arg PACKAGE_TARGET=${PACKAGE_TARGET} |
| 50 | +endif |
| 51 | + |
| 52 | +ifeq (${KEEP_SOURCES},1) |
| 53 | +DOCKER_BUILD_ARGS += --build-arg KEEP_SOURCES=1 |
| 54 | +endif |
| 55 | + |
| 56 | +# ----------------------------------------------------------------------------- |
| 57 | + |
| 58 | +include ${PROJECT_ROOT}/Makefile.help |
| 59 | + |
| 60 | +.PHONY: help |
| 61 | +.SILENT: help |
| 62 | +help:: |
| 63 | + $(call print_help_usage) |
| 64 | + echo |
| 65 | + $(call print_help_section, "Available Docker targets") |
| 66 | + $(call print_help_target, all, "build and test all Ubuntu versions") |
| 67 | + $(call print_help_target, ubuntu-VERSION, "build and test the Ubuntu VERSION image") |
| 68 | + $(call print_help_target, build-all, "build all Ubuntu versions") |
| 69 | + $(call print_help_target, build-ubuntu-VERSION, "build the Ubuntu VERSION image") |
| 70 | + $(call print_help_target, test-all, "build all Ubuntu versions") |
| 71 | + $(call print_help_target, test-ubuntu-VERSION, "test the Ubuntu VERSION image") |
| 72 | + $(call print_help_target, run-ubuntu-VERSION, "run the Ubuntu VERSION image") |
| 73 | + $(call print_help_target, release-all, "release all Ubuntu versions") |
| 74 | + $(call print_help_target, release-ubuntu-VERSION, "release the Ubuntu VERSION image") |
| 75 | + $(call print_help_target, remove-current-images, "remove and prune all ${DOCKER_IMAGE} Docker images") |
| 76 | + $(call print_help_target, remove-all-images, "remove and prune all ${DOCKER_IMAGE_NAME} Docker images") |
| 77 | + echo |
| 78 | + $(call print_help_section, "User configuration") |
| 79 | + $(call print_help_define, CONAN_PROFILE, ${CONAN_PROFILE}) |
| 80 | + $(call print_help_define, VENDOR_TARGET, ${VENDOR_TARGET}) |
| 81 | + $(call print_help_define, PACKAGE_TARGET, ${PACKAGE_TARGET}) |
| 82 | + $(call print_help_define, KEEP_SOURCES, ${KEEP_SOURCES}) |
| 83 | + $(call print_help_args_lines, DOCKER_USER_ARGS, ${DOCKER_USER_ARGS}) |
| 84 | + echo |
| 85 | + $(call print_help_section, "Docker configuration") |
| 86 | + $(call print_help_define, UBUNTU_NAME, "${UBUNTU_NAME}") |
| 87 | + $(call print_help_define_lines, UBUNTU_VERSIONS, ${UBUNTU_VERSIONS}) |
| 88 | + $(call print_help_define, DOCKER, "${DOCKER}") |
| 89 | + $(call print_help_define, DOCKER_CONTEXT, "${DOCKER_CONTEXT}") |
| 90 | + $(call print_help_define, DOCKER_NETWORK, "${DOCKER_NETWORK}") |
| 91 | + $(call print_help_define, DOCKER_IMAGE, "${DOCKER_IMAGE}") |
| 92 | + $(call print_help_args_lines, DOCKER_BUILD_ARGS, ${DOCKER_BUILD_ARGS}) |
| 93 | + $(call print_help_args_lines, DOCKER_RUN_ARGS, ${DOCKER_RUN_ARGS}) |
| 94 | + echo |
| 95 | + |
| 96 | +.SILENT: FORCE |
| 97 | +FORCE: |
| 98 | + # Targets containing patterns (%) cannot be made .PHONY. The standard |
| 99 | + # solution to work around this is to add a FORCE target to the |
| 100 | + # prerequisites of every target with patterns. |
| 101 | + |
| 102 | +.PHONY: build-all |
| 103 | +build-all: $(addprefix build-ubuntu-,${UBUNTU_VERSIONS}) |
| 104 | + |
| 105 | +.PHONY: test-all |
| 106 | +test-all: $(addprefix test-ubuntu-,${UBUNTU_VERSIONS}) |
| 107 | + |
| 108 | +.PHONY: release-all |
| 109 | +release-all: $(addprefix release-ubuntu-,${UBUNTU_VERSIONS}) |
| 110 | + |
| 111 | +ubuntu-%: FORCE build-ubuntu-% test-ubuntu-% |
| 112 | + @echo |
| 113 | + @echo "Completed building and testing: ${DOCKER_IMAGE}-$@" |
| 114 | + |
| 115 | +.PHONY: all |
| 116 | +all: $(addprefix ubuntu-,${UBUNTU_VERSIONS}) |
| 117 | + |
| 118 | +build-ubuntu-%: FORCE Dockerfile |
| 119 | + ${DOCKER} build -f Dockerfile ${DOCKER_BUILD_ARGS} ${DOCKER_USER_ARGS} \ |
| 120 | + --build-arg UBUNTU_VERSION=$* \ |
| 121 | + -t ${DOCKER_IMAGE}-ubuntu-$* \ |
| 122 | + ${DOCKER_CONTEXT} |
| 123 | + |
| 124 | +test-ubuntu-%: FORCE |
| 125 | + docker run ${DOCKER_RUN_ARGS} ${DOCKER_USER_ARGS} ${DOCKER_IMAGE}-ubuntu-$* \ |
| 126 | + bash -ec "[ -f /root/setup.sh ] && source /root/setup.sh; make smoketest" |
| 127 | + |
| 128 | +run-ubuntu-%: FORCE |
| 129 | + docker run ${DOCKER_RUN_ARGS} ${DOCKER_USER_ARGS} ${DOCKER_IMAGE}-ubuntu-$* |
| 130 | + |
| 131 | +release-ubuntu-%: FORCE |
| 132 | + @test -f setup.sh || echo 'Error: require setup.sh for user authentication' |
| 133 | + ${DOCKER} run ${DOCKER_RUN_ARGS} ${DOCKER_USER_ARGS} ${DOCKER_IMAGE}-ubuntu-$* \ |
| 134 | + bash -ec 'source /root/setup.sh && conan upload --force --all -c "*"' |
| 135 | + |
| 136 | +.PHONY: require-setup-sh |
| 137 | +require-setup-sh: |
| 138 | + @if [ ! -f ${PROJECT_ROOT}/setup.sh ]; then \ |
| 139 | + echo "ERROR: require ${PROJECT_ROOT}/setup.sh to proceed"; \ |
| 140 | + exit 1; \ |
| 141 | + fi |
| 142 | + |
| 143 | +.PHONY: remove-current-images |
| 144 | +remove-current-images: |
| 145 | + docker rmi $$(docker images --format '{{.Repository}}:{{.Tag}}' | grep '${DOCKER_IMAGE}') |
| 146 | + |
| 147 | +.PHONY: remove-all-images |
| 148 | +remove-all-images: |
| 149 | + docker rmi $$(docker images --format '{{.Repository}}:{{.Tag}}' | grep '${DOCKER_IMAGE_NAME}:') |
| 150 | + |
0 commit comments