This repository has been archived by the owner on May 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
68 lines (58 loc) · 3.31 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
IMAGE_NAME = rb-graphql-template
DOCKER_ORG = docker-org-here
BUILDKITE_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD) # current branch name
BUILDKITE_BUILD_NUMBER ?= 0
BRANCH_TAG != echo ${BUILDKITE_BRANCH} | sed 's:/:-:g'
.PHONY: help build tag push test run all clean
help: ## Display this help page
@echo "Welcome to the GraphQL Template API!"
@printf "\n\033[32mEnvironment Variables\033[0m\n"
@cat $(MAKEFILE_LIST) | egrep -o "\\$$\{[a-zA-Z0-9_]*\}" | sort | uniq | \
sed -E 's/^[\$$\{]*|\}$$//g' | xargs -I % echo % % | \
xargs printf "echo \"\033[93m%-30s\033[0m \$$(printenv %s)\n\"" | bash | sed "s/echo //"
@printf "\n\033[32mMake Targets\033[0m\n"
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@echo ""
build: ## Build the ${DOCKER_ORG}/rb-graphql-template Docker image
@echo "--- Pulling build image (contains dependency cache)"
docker pull ${DOCKER_ORG}/${IMAGE_NAME}-build:latest
@echo "--- Compiling the application"
docker run --name=${IMAGE_NAME}-compile -v `pwd`/app:/app ${DOCKER_ORG}/${IMAGE_NAME}-build:latest sbt stage
@echo "--- Building the runtime image"
docker build --pull -t ${DOCKER_ORG}/${IMAGE_NAME}:latest .
@echo "--- Saving the compile container for future caching benefits"
# These steps are just an optimisation, so we don't really care if they fail.
-docker commit ${IMAGE_NAME}-compile ${DOCKER_ORG}/${IMAGE_NAME}-build:latest
-docker push ${DOCKER_ORG}/${IMAGE_NAME}-build:latest
-docker rm ${IMAGE_NAME}-compile
tag: build ## Tag the ${DOCKER_ORG}/rb-graphql-template Docker image
@echo "--- Tagging image"
docker tag ${DOCKER_ORG}/${IMAGE_NAME}:latest ${DOCKER_ORG}/${IMAGE_NAME}:${BRANCH_TAG}
docker tag ${DOCKER_ORG}/${IMAGE_NAME}:latest ${DOCKER_ORG}/${IMAGE_NAME}:${BUILDKITE_BUILD_NUMBER}
push: tag ## Push the ${DOCKER_ORG}/rb-graphql-template tags to Docker Hub
@echo "--- Pushing to Docker registry"
docker push ${DOCKER_ORG}/${IMAGE_NAME}:${BUILDKITE_BUILD_NUMBER}
docker push ${DOCKER_ORG}/${IMAGE_NAME}:${BRANCH_TAG}
docker push ${DOCKER_ORG}/${IMAGE_NAME}:latest
test: ## Run the test suite
@echo "--- Pulling build image (contains dependency cache)"
docker pull ${DOCKER_ORG}/${IMAGE_NAME}-build:latest
@echo "--- Running unit tests"
docker run --rm --env-file=app/etc/test.env -v `pwd`/app:/app ${DOCKER_ORG}/${IMAGE_NAME}-build:latest sbt ci coverageAggregate
run: ## Run the current branch locally
@echo "Pulling build image (contains dependency cache)"
docker pull ${DOCKER_ORG}/${IMAGE_NAME}-build:latest
@echo "Starting the API on port 8080"
docker run -p 8080:80 --env-file=app/etc/development.env -v `pwd`/app:/app ${DOCKER_ORG}/${IMAGE_NAME}:master sbt run
clean: ## Clean the artifacts, Docker images and containers created by the build and test commands
@echo "--- Cleaning up the file system"
-docker run --rm -v `pwd`/app:/app ${DOCKER_ORG}/rb-graphql-template:latest chmod -R a+w /app
git clean -dfq
@echo "--- Cleaning up Docker images"
-docker rm $(docker ps -aq) 2> /dev/null
-docker rmi ${DOCKER_ORG}/${IMAGE_NAME}:latest 2> /dev/null
-docker rmi ${DOCKER_ORG}/${IMAGE_NAME}:${BRANCH_TAG} 2> /dev/null
-docker rmi ${DOCKER_ORG}/${IMAGE_NAME}:${BUILDKITE_BUILD_NUMBER} 2> /dev/null
-docker rmi $(docker images -f "dangling=true" -q) 2> /dev/null
all: build tag push