From 58a3fc9ff7e2df8d74a0672cff53ff7b1f9d3b1a Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Thu, 27 Apr 2023 02:34:04 +0200 Subject: [PATCH] Implemented the docker build and housekeeping workflows in the Makefile file. --- Makefile | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ef3f514 --- /dev/null +++ b/Makefile @@ -0,0 +1,51 @@ +# --- IMPORTS --- + +# Imports environment variables. +environment_vars ?= .env + +include $(environment_vars) +export $(shell sed 's/=.*//' $(environment_vars)) + +# --- ARGUMENTS --- + +override tag?=${DOCKER_IMAGE_TAG} +override platform?=${DOCKER_IMAGE_PLATFORM} +override config?=${SWIFT_BUILD_CONFIGURATION} + +# --- BUILDING --- + +build: build-image remove-image ## Build this package against a Swift docker instance. + +build-image: + @docker run \ + --rm \ + --volume ${PWD}:${DOCKER_VOLUME_TARGET} \ + --workdir ${DOCKER_VOLUME_TARGET} \ + --platform ${platform} \ + ${DOCKER_IMAGE_NAME}:${tag} \ + swift build --configuration ${config} + +remove-image: + @docker rmi ${DOCKER_IMAGE_NAME}:${tag} + +# --- HOUSEKEEPING --- + +remove-images: ## Remove all outstanding Swift docker images. + @docker images --all | grep ${DOCKER_IMAGE_NAME} | awk '{print $$3}' | xargs docker rmi --force + +clean: ## Clean the build artifacts for the package. + @swift package clean + +reset: ## Reset the build folder for the package. + @swift package reset + +# --- HELP --- + +# Outputs the documentation for each of the defined tasks when `help` is called. +# Reference: https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html +.PHONY: help + +help: ## Prints the written documentation for all the defined tasks. + @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) + +.DEFAULT_GOAL := help \ No newline at end of file