Makefile для сборки и тестирования контейнера

Makefile
MAJOR?=0
MINOR?=1
 
VERSION=$(MAJOR).$(MINOR)
 
APP_NAME = "system-toolbox"
 
# Our docker Hub account name
# HUB_NAMESPACE = "<hub_name>"
 
# location of Dockerfiles
DOCKER_FILE_DIR = "dockerfiles"
DOCKERFILE = "${DOCKER_FILE_DIR}/Dockerfile"
 
IMAGE_NAME = "${APP_NAME}"
CUR_DIR = $(shell echo "${PWD}")
 
# For python format checker. Default is 78
PEP8_MAX_LINE_LENGTH = 99
 
# unit testing options
NOSETEST_OPTS = --verbosity=2 --include='.*_test.py' --detailed-errors --where=toolbox
COVERAGE_OPTS = --with-coverage --cover-package=toolbox --cover-html --cover-inclusive --cover-tests --cover-erase \
--cover-html-dir=../test-results/unit-test-code-coverage
 
#################################
# Install targets
#################################
.PHONY: install-dev
install-dev:
	@echo "+ $@"
@pip install -e .
 
.PHONY: pip-freeze
	@echo "+ $@"
	@pip freeze | grep -v system_toolbox > pip-requirements/requirements.txt
 
 
#################################
# Docker targets
#################################
.PHONY: clean-image
clean-image: version-check
	@echo "+ $@"
	@docker rmi ${HUB_NAMESPACE}/${IMAGE_NAME}:latest || true
	@docker rmi ${HUB_NAMESPACE}/${IMAGE_NAME}:${VERSION} || true
 
.PHONY: image
image: version-check
	@echo "+ $@"
	@docker build -t ${HUB_NAMESPACE}/${IMAGE_NAME}:${VERSION} -f ./${DOCKERFILE} .
	@docker tag ${HUB_NAMESPACE}/${IMAGE_NAME}:${VERSION} ${HUB_NAMESPACE}/${IMAGE_NAME}:latest
	@echo 'Done.'
	@docker images --format '{{.Repository}}:{{.Tag}}\t\t Built: {{.CreatedSince}}\t\tSize: {{.Size}}' | grep ${IMAGE_NAME}:${VERSION}
 
.PHONY: push
push: clean-image image
	@echo "+ $@"
	@docker push ${HUB_NAMESPACE}/${IMAGE_NAME}:${VERSION}
	@docker push ${HUB_NAMESPACE}/${IMAGE_NAME}:latest
 
#################################
# test targets
#################################
.PHONY: test-unit
test-unit:
	@echo "+ $@"
	nosetests ${NOSETEST_OPTS}
 
.PHONY: check-fmt
#check-fmt: image
check-fmt:
	@echo "+ $@"
	pycodestyle --filename='*.py' --exclude='*.sh,*.md,*.txt,Makefile,*.swp' --max-line-length=${PEP8_MAX_LINE_LENGTH} *
 
.PHONY: test-static
test-static:
	@echo "+ $@"
	pylint -d duplicate-code test-cases
	pylint toolbox
	pylint integration-tests
 
.PHONY: test-all
test-all: check-fmt test-static test-unit
 
.PHONY: test-container
test-container: image
	@echo "+ $@"
	@docker run --rm --name toolbox-unit-tests ${HUB_NAMESPACE}/${IMAGE_NAME}:latest make test-all
	@docker run --rm --name toolbox-int --volume ${CUR_DIR}/results:/root/logs -e REGISTRY_USERNAME=foo -e REGISTRY_PASSWORD=bar \
		${HUB_NAMESPACE}/${IMAGE_NAME}:latest python ./integration-tests/testbed_validation.py
 
.PHONY: integration-static
integration-static: image
	@echo "+ $@"
	@docker run --rm --name toolbox-int --volume ${CUR_DIR}/results:/root/logs -e REGISTRY_USERNAME=foo -e REGISTRY_PASSWORD=bar \
		${HUB_NAMESPACE}/${IMAGE_NAME}:latest python ./integration-tests/testbed_validation.py
 
.PHONY: integration-testbed-survey
integration-testbed-survey:
	@echo "+ $@"
	@python ./integration-tests/testbed_validation.py --topology-filter=poc_ --sut-filter=${TESTBED_SURVEY_SUT} \
		--create-system ${INTEGRATION_PERSONA} ${DRY_RUN}
 
 
#################################
# Utilities
#################################
 
.PHONY: version-check
version-check:
	@echo "+ $@"
	if [ -z "${VERSION}" ]; then \
		echo "VERSION is not set" ; \
		false ; \
	else \
		echo "VERSION is ${VERSION}"; \
	fi

Источник

Ссылки

Печать/экспорт