-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
85 lines (69 loc) · 2.55 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
.DEFAULT_GOAL := help
SHELL := /bin/bash
DATE = $(shell date +%Y-%m-%dT%H:%M:%S)
APP_NAME ?= test-flask-app
APP_VERSION_FILE = version.py
GIT_COMMIT ?= $(shell git rev-parse HEAD 2> /dev/null || cat commit || echo "")
BUILD_TAG ?= ${APP_NAME}
BUILD_NUMBER ?= manual
BUILD_URL ?= manual
DEPLOY_BUILD_NUMBER ?= ${BUILD_NUMBER}
DOCKER_CONTAINER_PREFIX = ${USER}-${BUILD_TAG}
CF_MANIFEST_FILE ?= manifest.yml
CF_API ?= api.cloud.service.gov.uk
CF_ORG ?= csd-sso
CF_HOME ?= ${HOME}
$(eval export CF_HOME)
CF_SPACE ?= sandbox
DOCKER_IMAGE = kenlt/${APP_NAME}
DOCKER_IMAGE_TAG = ${CF_SPACE}
DOCKER_IMAGE_NAME = ${DOCKER_IMAGE}:${DOCKER_IMAGE_TAG}
DOCKER_TTY ?= $(if ${JENKINS_HOME},,t)
PORT ?= 5100
.PHONY: help
help:
@cat $(MAKEFILE_LIST) | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
define run_docker_container
docker run -i${DOCKER_TTY} --rm \
--name "${DOCKER_CONTAINER_PREFIX}-${1}" \
-p ${PORT}:${PORT} \
-e FLASK_APP=${FLASK_APP} \
-e FLASK_DEBUG=${FLASK_DEBUG} \
-e WERKZEUG_DEBUG_PIN=${WERKZEUG_DEBUG_PIN} \
-e BUILD_NUMBER=${BUILD_NUMBER} \
-e BUILD_URL=${BUILD_URL} \
-e APP_NAME=${APP_NAME} \
-e PORT=${PORT} \
-e http_proxy="${HTTP_PROXY}" \
-e HTTP_PROXY="${HTTP_PROXY}" \
-e https_proxy="${HTTPS_PROXY}" \
-e HTTPS_PROXY="${HTTPS_PROXY}" \
-e NO_PROXY="${NO_PROXY}" \
${DOCKER_IMAGE_NAME} \
${2}
endef
.PHONY: run-with-docker
run-with-docker: prepare-docker-build-image ## Build inside a Docker container
$(call run_docker_container)
.PHONY: prepare-docker-build-image
prepare-docker-build-image: ## Build docker image
docker build -f docker/Dockerfile \
--build-arg http_proxy="${http_proxy}" \
--build-arg https_proxy="${https_proxy}" \
--build-arg NO_PROXY="${NO_PROXY}" \
--build-arg APP_NAME=${APP_NAME} \
--build-arg PORT=${PORT} \
-t ${DOCKER_IMAGE_NAME} \
.
.PHONY: clean-docker-containers
clean-docker-containers: ## Clean up any remaining docker containers
docker rm -f $(shell docker ps -q -f "name=${DOCKER_CONTAINER_PREFIX}") 2> /dev/null || true
.PHONY: upload-to-dockerhub
upload-to-dockerhub: prepare-docker-build-image ## Upload the current version of the docker image to dockerhub
$(if ${DOCKERHUB_USERNAME},,$(error Must specify DOCKERHUB_USERNAME))
$(if ${DOCKERHUB_PASSWORD},,$(error Must specify DOCKERHUB_PASSWORD))
@docker login -u ${DOCKERHUB_USERNAME} -p ${DOCKERHUB_PASSWORD}
docker push ${DOCKER_IMAGE_NAME}
.PHONY: cf-deploy
cf-deploy: ## Deploys the app to Cloud Foundry
cf push ${APP_NAME} --docker-image ${DOCKER_IMAGE_NAME}