Newer
Older
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
SHELL := /bin/bash
DOCKER_IMAGE_NAME := registry.ubicast.net/mediaserver/envsetup
ifdef debug
MOLECULE_FLAGS += --debug
endif
ifdef keep
MOLECULE_TEST_FLAGS += --destroy=never
endif
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)
.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
$(PIP_BIN) install -r requirements.dev.txt
.PHONY: lint
## lint: Run linters on the project
lint:
$(FLAKE8_BIN) .
$(YAMLLINT_BIN) .
.PHONY: test
## test: Run development tests on the project : debug=1, keep=1
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
.PHONY: image
## image: Run Packer image build : build=<path-to-packer-file>
image: image-validate
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
.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/^/ /'