Makefile 2.76 KB
Newer Older
Alex Castaño's avatar
Alex Castaño committed
1 2 3 4 5 6 7 8 9 10 11
.PHONY: help

APP_NAME ?= `grep 'app:' mix.exs | sed -e 's/\[//g' -e 's/ //g' -e 's/app://' -e 's/[:,]//g'`
APP_VSN ?= `grep 'version:' mix.exs | cut -d '"' -f2`
APP_BUILD ?= `git rev-parse --short HEAD`

help:
	@echo "$(APP_NAME):$(APP_VSN)-$(APP_BUILD)"
	@perl -nle'print $& if m{^[a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

build: ## Build the Docker image
Alex Castaño's avatar
Alex Castaño committed
12 13
	@echo APP_NAME=$(APP_NAME)
	@echo APP_VSN=$(APP_VSN)
14
	@echo APP_BUILD=$(APP_BUILD)
Alex Castaño's avatar
Alex Castaño committed
15 16 17 18 19 20
	@echo docker build \
		--no-cache \
		--build-arg APP_NAME=$(APP_NAME) \
		--build-arg APP_VSN=$(APP_VSN) \
		-t moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) .
	@docker build \
Alex Castaño's avatar
Alex Castaño committed
21 22 23
		--no-cache \
		--build-arg APP_NAME=$(APP_NAME) \
		--build-arg APP_VSN=$(APP_VSN) \
24 25
		-t moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) .
	@echo moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD)
Alex Castaño's avatar
Alex Castaño committed
26

Alex Castaño's avatar
Alex Castaño committed
27
build_with_cache: ## Build the Docker image using previous cache
Alex Castaño's avatar
Alex Castaño committed
28 29
	@echo APP_NAME=$(APP_NAME)
	@echo APP_VSN=$(APP_VSN)
30
	@echo APP_BUILD=$(APP_BUILD)
Alex Castaño's avatar
Alex Castaño committed
31 32 33 34 35
	@echo docker build \
		--build-arg APP_NAME=$(APP_NAME) \
		--build-arg APP_VSN=$(APP_VSN) \
		-t moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) .
	@docker build \
Alex Castaño's avatar
Alex Castaño committed
36 37
		--build-arg APP_NAME=$(APP_NAME) \
		--build-arg APP_VSN=$(APP_VSN) \
38 39 40
		-t moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) .
	@echo moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD)

Alex Castaño's avatar
Alex Castaño committed
41
push: ## Add latest tag to last build and push
Alex Castaño's avatar
Alex Castaño committed
42 43 44 45 46
	@echo docker tag moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) moodlenet/moodlenet:latest
	@docker tag moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) moodlenet/moodlenet:latest
	@echo docker push moodlenet/moodlenet:latest
	@docker push moodlenet/moodlenet:latest

Alex Castaño's avatar
Alex Castaño committed
47
push_stable: ## Tag stable, latest and version tags to the last build and push
48
	@echo docker tag moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) moodlenet/moodlenet:latest
49 50 51
	@docker tag moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) moodlenet/moodlenet:latest
	@echo docker tag moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) moodlenet/moodlenet:$(APP_VSN)
	@docker tag moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) moodlenet/moodlenet:$(APP_VSN)
Alex Castaño's avatar
Alex Castaño committed
52 53
	@echo docker tag moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) moodlenet/moodlenet:stable
	@docker tag moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) moodlenet/moodlenet:stable
54 55
	@echo docker push moodlenet/moodlenet:latest
	@docker push moodlenet/moodlenet:latest
Alex Castaño's avatar
Alex Castaño committed
56 57
	@echo docker push moodlenet/moodlenet:stable
	@docker push moodlenet/moodlenet:stable
58 59 60 61
	@echo docker push moodlenet/moodlenet:$(APP_VSN)
	@docker push moodlenet/moodlenet:$(APP_VSN)
	@echo docker push moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD)
	@docker push moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD)
Alex Castaño's avatar
Alex Castaño committed
62

Alex Castaño's avatar
Alex Castaño committed
63 64 65 66 67
run: ## Run the app in Docker
	docker run\
		--env-file config/docker.env \
		--expose 4000 -p 4000:4000 \
		--rm -it moodlenet:latest