SHELL := /bin/bash DOCKER_IMAGE_NAME := registry.ubicast.net/mediaserver/envsetup VENV := /tmp/pyvensetup PIP_BIN = $(shell command -v $(VENV)/bin/pip3 || command -v pip3 || echo pip3) PIP_COMPILE_BIN = $(shell command -v $(VENV)/bin/pip-compile || command -v pip-compile) ANSIBLE_BIN = $(shell command -v ansible || command -v $(VENV)/bin/ansible) ANSIBLE_PLAYBOOK_BIN = $(shell command -v ansible-playbook || command -v $(VENV)/bin/ansible-playbook) ANSIBLE_LINT_BIN = $(shell command -v ansible-lint || command -v $(VENV)/bin/ansible-lint) YAMLLINT_BIN = $(shell command -v yamllint || command -v $(VENV)/bin/yamllint) FLAKE8_BIN = $(shell command -v flake8 || command -v $(VENV)/bin/flake8) # molecule tests flags ifdef debug MOLECULE_FLAGS += --debug endif ifdef keep MOLECULE_TEST_FLAGS += --destroy=never endif .PHONY: all ## TARGET: DESCRIPTION: ARGS all: help .PHONY: venv ## venv: Install python3-venv and create a temporary virtualenv venv: -@command -v apt-get >/dev/null && apt-get update && apt-get install -y python3-venv @command -v $(PIP_BIN) > /dev/null || python3 -m venv $(VENV) ## requirements.txt: Update requirements and their dependencies ## requirements.dev.txt: Update development requirements and their dependencies %.txt: %.in $(PIP_COMPILE_BIN) -U $^ -o $@ chmod 644 $@ .PHONY: install ## install: Install requirements install: venv $(PIP_BIN) install -U pip wheel $(PIP_BIN) install -r requirements.txt .PHONY: install-dev ## install-dev: Install development requirements install-dev: install $(PIP_BIN) install -r requirements.dev.txt ln -sfv .githooks/pre-commit .git/hooks/ .PHONY: lint ## lint: Run linters on the project lint: $(FLAKE8_BIN) . $(YAMLLINT_BIN) . $(ANSIBLE_LINT_BIN) site.yml .PHONY: test ## test: Run development tests on the project : debug=1, keep=1, SKYREACH_SYSTEM_KEY=<xxx> test: ifndef SKYREACH_SYSTEM_KEY $(error SKYREACH_SYSTEM_KEY is undefined) endif molecule $(MOLECULE_FLAGS) test $(MOLECULE_TEST_FLAGS) .PHONY: deploy ## deploy: Run deployment playbooks : i=<inventory-path>, l=<host-or-group>, t=<tag> deploy: ifndef i $(error i is undefined) endif ifndef l $(eval l=all) endif ifndef t $(eval t=all) endif $(ANSIBLE_BIN) -i $(i) -l $(l) -m ping all $(ANSIBLE_PLAYBOOK_BIN) -i $(i) site.yml -e conf_update=true -l $(l) -t $(t) .PHONY: image-validate ## image-validate: Check that Packer image is valid : build=<path-to-packer-file> image-validate: ifndef build $(error build is undefined) endif packer validate $(build) .PHONY: image ## image: Run Packer image build : build=<path-to-packer-file> image: image-validate packer build -on-error=ask -force $(build) .PHONY: docker-build ## docker-build: Run docker image build for CI and devcontainer docker-build: docker-pull docker build -t $(DOCKER_IMAGE_NAME) -f .devcontainer/Dockerfile . docker build -t $(DOCKER_IMAGE_NAME):root -f .devcontainer/Dockerfile.root . .PHONY: docker-rebuild ## docker-rebuild: Force docker image rebuild docker-rebuild: docker build --pull --no-cache -t $(DOCKER_IMAGE_NAME) -f .devcontainer/Dockerfile . docker build --pull --no-cache -t $(DOCKER_IMAGE_NAME):root -f .devcontainer/Dockerfile.root . .PHONY: docker-pull ## docker-pull: Pull Docker image from registry docker-pull: -docker pull $(DOCKER_IMAGE_NAME) -docker pull $(DOCKER_IMAGE_NAME):root .PHONY: docker-push ## docker-push: Push Docker image to registry docker-push: docker push $(DOCKER_IMAGE_NAME) docker push $(DOCKER_IMAGE_NAME):root .PHONY: help ## help: Print this help message help: @echo -e "Usage: \n" @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'