Basically I have it on the root directory, and then hold all the dockerfiles in subdirectories under the “dockerfiles” dir, so you can pass as a parameter the name of the container youy want to build. Nothing too crazy, and sure I’m doing something wrong ^_^
├── Makefile ├── README ├── dockerfiles │ ├── base │ │ ├── Dockerfile │ │ └── entrypoint.sh │ ├── consul │ │ └── Dockerfile │ ├── java │ │ └── Dockerfile │ ├── mucous │ │ ├── Dockerfile │ │ └── config │ ├── museekd │ │ ├── Dockerfile │ │ └── config.xml │ ├── node-npm │ │ ├── Dockerfile │ │ └── entrypoint.sh │ ├── ssh-server │ │ └── Dockerfile │ └── terraform │ └── Dockerfile
The Makefile
-
Project Dir ROOT_DIR := (realpath (MAKEFILE_LIST))))
-
Directory that holds lambda source code SOURCE_DIR = $(ROOT_DIR)/dockerfiles
-
Container prefix PREFIX:= local
-
Container name to build CONTAINER_NAME := base
-
Container name to build VERSION := latest
-
Known Functions in source Dir CONTAINER_DIR_NAMES := {shell cd (SOURCE_DIR) && find -maxdepth 1 -mindepth 1 -type d -exec basename {} ;}
.DEFAULT_TARGET := build #.PHONY: build
build: _check-params
pushd (CONTAINER_NAME);
docker build -t (CONTAINER_NAME):(DONE)
build-clean: _check-params
pushd (CONTAINER_NAME);
docker build -t (CONTAINER_NAME):(DONE)
build-all: @for f in (CONTAINER_DIR_NAMES); do \ make build CONTAINER_NAME=$$f; \ done @(DONE)
test: _check-params
pushd (CONTAINER_NAME);
docker run -it —rm (CONTAINER_NAME):(DONE)
tag_latest: _check-params
pushd (CONTAINER_NAME);
docker tag (CONTAINER_NAME):(PREFIX)/(DONE)
release: _check-params test tag_latest
pushd (CONTAINER_NAME);
@if ! docker images (CONTAINER_NAME) | awk ’{ print $$2 }’ | grep -q -F (PREFIX)/(VERSION) is not yet built. Please run ‘make build’”; false; fi ;
docker push (CONTAINER_NAME) ;
@echo ”*** Don’t forget to create a tag. git tag rel-(VERSION) && git push origin rel-(VERSION)” ;
popd
@$(DONE)
run: _check-params
pushd (CONTAINER_NAME);
docker run -i -P (CONTAINER_NAME):(DONE)
_check-params: ifndef CONTAINER_NAME @echo “You must provide a CONTAINER_NAME variable”; @echo “Select a valid container name @false; endif