mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-11 07:42:20 -05:00
Run API on Paas
This commit is contained in:
121
Makefile
121
Makefile
@@ -8,7 +8,8 @@ APP_VERSION_FILE = app/version.py
|
||||
GIT_BRANCH ?= $(shell git symbolic-ref --short HEAD 2> /dev/null || echo "detached")
|
||||
GIT_COMMIT ?= $(shell git rev-parse HEAD)
|
||||
|
||||
DOCKER_BUILDER_IMAGE_NAME = govuk/notify-api-builder
|
||||
DOCKER_IMAGE_TAG := $(shell cat docker/VERSION)
|
||||
DOCKER_BUILDER_IMAGE_NAME = govuk/notify-api-builder:${DOCKER_IMAGE_TAG}
|
||||
|
||||
BUILD_TAG ?= notifications-api-manual
|
||||
BUILD_NUMBER ?= 0
|
||||
@@ -17,6 +18,10 @@ BUILD_URL ?=
|
||||
|
||||
DOCKER_CONTAINER_PREFIX = ${USER}-${BUILD_TAG}
|
||||
|
||||
CF_API ?= api.cloud.service.gov.uk
|
||||
CF_ORG ?= govuk-notify
|
||||
CF_SPACE ?= ${DEPLOY_ENV}
|
||||
|
||||
.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}'
|
||||
@@ -25,8 +30,8 @@ help:
|
||||
venv: venv/bin/activate ## Create virtualenv if it does not exist
|
||||
|
||||
venv/bin/activate:
|
||||
test -d venv || virtualenv venv
|
||||
./venv/bin/pip install pip-accel
|
||||
test -d venv || virtualenv venv -p python3
|
||||
. venv/bin/activate && pip install pip-accel
|
||||
|
||||
.PHONY: check-env-vars
|
||||
check-env-vars: ## Check mandatory environment variables
|
||||
@@ -35,6 +40,12 @@ check-env-vars: ## Check mandatory environment variables
|
||||
$(if ${AWS_ACCESS_KEY_ID},,$(error Must specify AWS_ACCESS_KEY_ID))
|
||||
$(if ${AWS_SECRET_ACCESS_KEY},,$(error Must specify AWS_SECRET_ACCESS_KEY))
|
||||
|
||||
.PHONY: sandbox
|
||||
sandbox: ## Set environment to sandbox
|
||||
$(eval export DEPLOY_ENV=sandbox)
|
||||
$(eval export DNS_NAME="cloudapps.digital")
|
||||
@true
|
||||
|
||||
.PHONY: preview
|
||||
preview: ## Set environment to preview
|
||||
$(eval export DEPLOY_ENV=preview)
|
||||
@@ -56,7 +67,7 @@ production: ## Set environment to production
|
||||
.PHONY: dependencies
|
||||
dependencies: venv ## Install build dependencies
|
||||
mkdir -p ${PIP_ACCEL_CACHE}
|
||||
PIP_ACCEL_CACHE=${PIP_ACCEL_CACHE} ./venv/bin/pip-accel install -r requirements_for_test.txt
|
||||
. venv/bin/activate && PIP_ACCEL_CACHE=${PIP_ACCEL_CACHE} pip-accel install -r requirements_for_test.txt
|
||||
|
||||
.PHONY: generate-version-file
|
||||
generate-version-file: ## Generates the app version file
|
||||
@@ -64,7 +75,10 @@ generate-version-file: ## Generates the app version file
|
||||
|
||||
.PHONY: build
|
||||
build: dependencies generate-version-file ## Build project
|
||||
./venv/bin/pip-accel wheel --wheel-dir=wheelhouse -r requirements.txt
|
||||
. venv/bin/activate && PIP_ACCEL_CACHE=${PIP_ACCEL_CACHE} pip-accel wheel --wheel-dir=wheelhouse -r requirements.txt
|
||||
|
||||
.PHONY: cf-build
|
||||
cf-build: dependencies generate-version-file ## Build project for PAAS
|
||||
|
||||
.PHONY: build-codedeploy-artifact
|
||||
build-codedeploy-artifact: ## Build the deploy artifact for CodeDeploy
|
||||
@@ -105,12 +119,12 @@ deploy-delivery: check-env-vars ## Trigger CodeDeploy for the delivery app
|
||||
|
||||
.PHONY: coverage
|
||||
coverage: venv ## Create coverage report
|
||||
./venv/bin/coveralls
|
||||
. venv/bin/activate && coveralls
|
||||
|
||||
.PHONY: prepare-docker-build-image
|
||||
prepare-docker-build-image: ## Prepare the Docker builder image
|
||||
mkdir -p ${PIP_ACCEL_CACHE}
|
||||
make -C docker build-build-image
|
||||
make -C docker build
|
||||
|
||||
.PHONY: build-with-docker
|
||||
build-with-docker: prepare-docker-build-image ## Build inside a Docker container
|
||||
@@ -129,6 +143,23 @@ build-with-docker: prepare-docker-build-image ## Build inside a Docker container
|
||||
${DOCKER_BUILDER_IMAGE_NAME} \
|
||||
make build
|
||||
|
||||
.PHONY: cf-build-with-docker
|
||||
cf-build-with-docker: prepare-docker-build-image ## Build inside a Docker container
|
||||
@docker run -i --rm \
|
||||
--name "${DOCKER_CONTAINER_PREFIX}-build" \
|
||||
-v "`pwd`:/var/project" \
|
||||
-v "${PIP_ACCEL_CACHE}:/var/project/cache/pip-accel" \
|
||||
-e GIT_COMMIT=${GIT_COMMIT} \
|
||||
-e BUILD_NUMBER=${BUILD_NUMBER} \
|
||||
-e BUILD_URL=${BUILD_URL} \
|
||||
-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_BUILDER_IMAGE_NAME} \
|
||||
make cf-build
|
||||
|
||||
.PHONY: test-with-docker
|
||||
test-with-docker: prepare-docker-build-image create-docker-test-db ## Run tests inside a Docker container
|
||||
@docker run -i --rm \
|
||||
@@ -182,5 +213,79 @@ coverage-with-docker: prepare-docker-build-image ## Generates coverage report in
|
||||
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: clean
|
||||
clean:
|
||||
rm -rf node_modules cache target venv .coverage build tests/.cache
|
||||
rm -rf node_modules cache target venv .coverage build tests/.cache wheelhouse
|
||||
|
||||
.PHONY: cf-login
|
||||
cf-login: ## Log in to Cloud Foundry
|
||||
$(if ${CF_USERNAME},,$(error Must specify CF_USERNAME))
|
||||
$(if ${CF_PASSWORD},,$(error Must specify CF_PASSWORD))
|
||||
$(if ${CF_SPACE},,$(error Must specify CF_SPACE))
|
||||
@echo "Logging in to Cloud Foundry on ${CF_API}"
|
||||
@cf login -a "${CF_API}" -u ${CF_USERNAME} -p "${CF_PASSWORD}" -o "${CF_ORG}" -s "${CF_SPACE}"
|
||||
|
||||
.PHONY: cf-deploy-api
|
||||
cf-deploy-api: ## Deploys the API to Cloud Foundry
|
||||
$(eval export ORIG_INSTANCES=$(shell cf curl /v2/apps/$(shell cf app --guid notify-api) | jq -r ".entity.instances"))
|
||||
@echo "Original instance count: ${ORIG_INSTANCES}"
|
||||
cf check-manifest notify-api -f manifest-api-${CF_SPACE}.yml
|
||||
cf zero-downtime-push notify-api -f manifest-api-${CF_SPACE}.yml
|
||||
cf scale -i ${ORIG_INSTANCES} notify-api
|
||||
|
||||
.PHONY: cf-push-api
|
||||
cf-push-api: ##
|
||||
cf push notify-api -f manifest-api-${CF_SPACE}.yml
|
||||
|
||||
.PHONY: cf-deploy-api-db-migration
|
||||
cf-deploy-api-db-migration: ## Deploys the API db migration to Cloud Foundry
|
||||
cf check-manifest notify-api-db-migration -f manifest-api-db-migration.yml
|
||||
cf push notify-api-db-migration -f manifest-api-db-migration.yml
|
||||
|
||||
cf-push-api-db-migration: cf-deploy-api-db-migration ## Deploys the API db migration to Cloud Foundry
|
||||
|
||||
.PHONY: cf-deploy-delivery
|
||||
cf-deploy-delivery: ## Deploys a delivery app to Cloud Foundry
|
||||
$(if ${CF_APP},,$(error Must specify CF_APP))
|
||||
$(eval export ORIG_INSTANCES=$(shell cf curl /v2/apps/$(shell cf app --guid ${CF_APP}) | jq -r ".entity.instances"))
|
||||
@echo "Original instance count: ${ORIG_INSTANCES}"
|
||||
cf check-manifest ${CF_APP} -f manifest-$(subst notify-,,${CF_APP}).yml
|
||||
cf zero-downtime-push ${CF_APP} -f manifest-$(subst notify-,,${CF_APP}).yml
|
||||
cf scale -i ${ORIG_INSTANCES} ${CF_APP}
|
||||
|
||||
.PHONY: cf-push-delivery
|
||||
cf-push-delivery: ## Deploys a delivery app to Cloud Foundry
|
||||
$(if ${CF_APP},,$(error Must specify CF_APP))
|
||||
cf push ${CF_APP} -f manifest-$(subst notify-,,${CF_APP}).yml
|
||||
|
||||
define cf_deploy_with_docker
|
||||
@docker run -i --rm \
|
||||
--name "${DOCKER_CONTAINER_PREFIX}-${1}" \
|
||||
-v `pwd`:/var/project \
|
||||
-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}" \
|
||||
-e CF_API="${CF_API}" \
|
||||
-e CF_USERNAME="${CF_USERNAME}" \
|
||||
-e CF_PASSWORD="${CF_PASSWORD}" \
|
||||
-e CF_ORG="${CF_ORG}" \
|
||||
-e CF_SPACE="${CF_SPACE}" \
|
||||
-e CF_APP="${CF_APP}" \
|
||||
${DOCKER_BUILDER_IMAGE_NAME} \
|
||||
${2}
|
||||
endef
|
||||
|
||||
.PHONY: cf-deploy-api-with-docker
|
||||
cf-deploy-api-with-docker: prepare-docker-build-image ## Deploys the API to Cloud Foundry from a Docker container
|
||||
$(call cf_deploy_with_docker,cf-deploy-api,make cf-login cf-deploy-api)
|
||||
|
||||
.PHONY: cf-deploy-api-db-migration-with-docker
|
||||
cf-deploy-api-db-migration-with-docker: prepare-docker-build-image ## Deploys the API db migration to Cloud Foundry from a Docker container
|
||||
$(call cf_deploy_with_docker,cf-deploy-api-db-migration,make cf-login cf-deploy-api-db-migration)
|
||||
|
||||
.PHONY: cf-deploy-delivery-with-docker
|
||||
cf-deploy-delivery-with-docker: prepare-docker-build-image ## Deploys a delivery app to Cloud Foundry from a Docker container
|
||||
$(if ${CF_APP},,$(error Must specify CF_APP))
|
||||
$(call cf_deploy_with_docker,cf-deploy-delivery-${CF_APP},make cf-login cf-deploy-delivery)
|
||||
|
||||
Reference in New Issue
Block a user