-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Cleaner Makefile using variable targets
- Loading branch information
Showing
1 changed file
with
24 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,37 @@ | ||
BUILDER_NAME?=craft-builder | ||
BUILD_PLATFORMS?=linux/$(shell arch) | ||
BUILD_COMMAND?=docker buildx build --load --platform ${BUILD_PLATFORMS} --builder ${BUILDER_NAME} | ||
BUILD_PLATFORM?=linux/$(shell arch) | ||
BUILD_COMMAND?=docker buildx build --load --platform ${BUILD_PLATFORM} --builder ${BUILDER_NAME} | ||
IMAGE_NAMESPACE?=nystudio107 | ||
.PHONY: create-builder | ||
PHP_PROD_NAMESPACE?=php-prod-base | ||
PHP_DEV_NAMESPACE?=php-dev-base | ||
NODE_NAMESPACE?=node-dev-base | ||
|
||
PHP_VERSIONS?=php-7.4-alpine php-8.0-alpine php-8.1-alpine php-8.2-alpine | ||
NODE_VERSIONS?=node-14-alpine node-16-alpine node-18-alpine node-20-alpine | ||
|
||
.PHONY: all create-builder php $(PHP_VERSIONS) node $(NODE_VERSIONS) | ||
|
||
# Build all base images | ||
all: php node | ||
|
||
# Ensure a builder exists for docker buildx | ||
create-builder: | ||
-@if [ ! "$$(docker buildx inspect ${BUILDER_NAME} 2>/dev/null)" ]; then \ | ||
echo "No builder exists, creating builder: ${BUILDER_NAME}" ; \ | ||
docker buildx create --name ${BUILDER_NAME} ; \ | ||
fi | ||
# Build an image with docker buildx | ||
build-image: create-builder | ||
${BUILD_COMMAND} -t ${IMAGE_NAMESPACE}/${TARGET_VERSION} ${TARGET_BASE}/${TARGET_VERSION} | ||
|
||
# Build & load all php base images | ||
php: php8.0 php8.1 php8.2 | ||
|
||
# Build & load php prod & dev base 8.0 images | ||
php8.0: php-prod-base8.0 php-dev-base8.0 | ||
# Build & load php prod base 8.0 images | ||
php-prod-base8.0: TARGET_BASE=php-prod-base | ||
php-prod-base8.0: TARGET_VERSION=8.0-alpine | ||
php-prod-base8.0: build-image | ||
# Build & load php dev base 8.0 images | ||
php-dev-base8.0: TARGET_BASE=php-dev-base | ||
php-dev-base8.0: TARGET_VERSION=8.0-alpine | ||
php-dev-base8.0: build-image | ||
|
||
# Build & load php prod & dev base 8.1 images | ||
php8.1: php-prod-base8.1 php-dev-base8.1 | ||
# Build & load php prod base 8.1 images | ||
php-prod-base8.1: TARGET_BASE=php-prod-base | ||
php-prod-base8.1: TARGET_VERSION=8.1-alpine | ||
php-prod-base8.1: build-image | ||
# Build & load php dev base 8.1 images | ||
php-dev-base8.1: TARGET_BASE=php-dev-base | ||
php-dev-base8.1: TARGET_VERSION=8.1-alpine | ||
php-dev-base8.1: build-image | ||
|
||
# Build & load php prod & dev base 8.2 images | ||
php8.2: php-prod-base8.2 php-dev-base8.2 | ||
# Build & load php prod base 8.2 images | ||
php-prod-base8.2: TARGET_BASE=php-prod-base | ||
php-prod-base8.2: TARGET_VERSION=8.2-alpine | ||
php-prod-base8.2: build-image | ||
# Build & load php dev base 8.2 images | ||
php-dev-base8.2: TARGET_BASE=php-dev-base | ||
php-dev-base8.2: TARGET_VERSION=8.2-alpine | ||
php-dev-base8.2: build-image | ||
|
||
# Build & load all node base images | ||
node: node14 node16 node18 node20 | ||
|
||
# Build & load node 14 images | ||
node14: TARGET_BASE=node-dev-base | ||
node14: TARGET_VERSION=14-alpine | ||
node14: build-image | ||
# Build all php base images | ||
php:$(PHP_VERSIONS) | ||
|
||
# Build & load node 16 images | ||
node16: TARGET_BASE=node-dev-base | ||
node16: TARGET_VERSION=16-alpine | ||
node16: build-image | ||
# Build specific php prod & dev base images | ||
$(PHP_VERSIONS):create-builder | ||
${BUILD_COMMAND} -t ${IMAGE_NAMESPACE}/${PHP_PROD_NAMESPACE}:$(subst php-,,$@) ${PHP_PROD_NAMESPACE}/$(subst php-,,$@) | ||
${BUILD_COMMAND} -t ${IMAGE_NAMESPACE}/${PHP_DEV_NAMESPACE}:$(subst php-,,$@) ${PHP_DEV_NAMESPACE}/$(subst php-,,$@) | ||
|
||
# Build & load node 18 images | ||
node18: TARGET_BASE=node-dev-base | ||
node18: TARGET_VERSION=18-alpine | ||
node18: build-image | ||
# Build all node base images | ||
node:$(NODE_VERSIONS) | ||
|
||
# Build & load node 20 images | ||
node20: TARGET_BASE=node-dev-base | ||
node20: TARGET_VERSION=20-alpine | ||
node20: build-image | ||
# Build specific node base images | ||
$(NODE_VERSIONS):create-builder | ||
${BUILD_COMMAND} -t ${IMAGE_NAMESPACE}/${NODE_NAMESPACE}:$(subst node-,,$@) ${NODE_NAMESPACE}/$(subst node-,,$@) |