BUILD_NUMBER ?= 1 BASE_AWS_PROFILE = gdb-infra-dev BASE_AWS_ACCOUNT_ID = 483193324480 BASE_AWS_REGION = us-east-1 BASE_ECR_REGISTRY = $(BASE_AWS_ACCOUNT_ID).dkr.ecr.$(BASE_AWS_REGION).amazonaws.com AWS_PROFILE ?= gdb-apollo-dev AWS_ACCOUNT_ID ?= 725764004555 AWS_REGION ?= us-east-1 ECR_REGISTRY ?= $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com ECR_REPOSITORY_NAME ?= $(PROJECT_GROUP)/$(PROJECT) ECR_REGISTRY_URI ?= $(ECR_REGISTRY)/$(ECR_REPOSITORY_NAME) REVISION ?= $(shell git rev-parse --short=8 HEAD) BUILDTIME ?= $(shell date -u +"%Y%m%d%H%M%S") VERSION ?= build-$(BUILDTIME).$(REVISION) SEMVER ?= $(shell cat VERSION ) .DEFAULT_GOAL := help ## - ## help - this message .PHONY: help help: Makefile @echo "Application: ${APP}\n" @echo "Run command:\n make \n" @grep -E -h '^## .*' $(MAKEFILE_LIST) | sed -n 's/^##//p' | column -t -s '-' | sed -e 's/^/ /' ## - ## Docker commands ## docker/login/base - login to AWS ECR registry using docker, aws configuration need to be set first .PHONY:docker/login/base docker/login/base: @aws ecr get-login \ --profile ${BASE_AWS_PROFILE} \ --no-include-email \ --region ${BASE_AWS_REGION} | awk '{print $$6}' | \ docker login -u AWS --password-stdin https://$(BASE_ECR_REGISTRY) || aws ecr get-login-password \ --profile ${BASE_AWS_PROFILE} \ --region ${BASE_AWS_REGION} | \ docker login --username AWS --password-stdin https://$(BASE_ECR_REGISTRY) ## docker/login - login to AWS ECR registry using docker, aws configuration need to be set first .PHONY:docker/login docker/login: @aws ecr get-login \ --profile ${AWS_PROFILE} \ --no-include-email \ --region ${AWS_REGION} | awk '{print $$6}' | \ docker login -u AWS --password-stdin https://$(ECR_REGISTRY) || aws ecr get-login-password \ --profile ${AWS_PROFILE} \ --region ${AWS_REGION} | \ docker login --username AWS --password-stdin https://$(ECR_REGISTRY) ## docker/base/image/pull - pull base image from ECR docker/base/image/pull: docker/login/base docker pull $(BASE_ECR_REGISTRY)/python:3.8-alpine3.13-runner docker pull $(BASE_ECR_REGISTRY)/python:3.8-alpine3.13-builder ## docker/image/build - build docker image .PHONY: docker/image/build docker/image/build: docker/login/base @echo "Building docker image" docker build \ --build-arg VERSION=$(VERSION) \ --build-arg REVISION=$(REVISION) \ --build-arg BUILDTIME=$(BUILDTIME) \ -t $(ECR_REGISTRY_URI):$(VERSION) \ -t $(ECR_REGISTRY_URI):$(REVISION) . ## docker/run - run docker container .PHONY: docker/run docker/run: docker/image/build @echo "Run container" docker run \ --interactive \ --tty \ --rm \ --env-file .env \ $(ECR_REGISTRY_URI):$(REVISION)