Makefile 4.09 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
###################  Docker development helpful directives  ####################
#
# Usage:
# make logs                   # displays log outputs from running services
# make build-env              # build environment, create and start containers
# make env                    # build environment, load fixtures and enters shell
# make destroy-env            # stop and remove containers, networks, images, and volume
# make reload-env             # restart containers, networks, images, and volume
# make shell-env              # start bash inside service
# make root-shell-env         # start bash inside service as root
# make load-fixtures          # loads fixtures
# make populate-instance      # create database, tables and indeces
# make generate-certificates  # generate nginx certificates
# make test                   # run test

SERVICE_NAME :=  cern-search-api
DOCKER_FILE := docker-compose.full.yml

build-env:
	docker-compose -f $(DOCKER_FILE) up -d --build --remove-orphans
.PHONY: env

logs:
	docker-compose -f $(DOCKER_FILE) logs -f
.PHONY: logs

populate-instance:
	docker-compose -f $(DOCKER_FILE) exec $(SERVICE_NAME) /bin/bash -c \
		"sh /opt/invenio/src/scripts/populate-instance.sh"
.PHONY: load-fixtures

load-fixtures:
	docker-compose -f $(DOCKER_FILE) exec $(SERVICE_NAME) /bin/bash -c \
		"sh /opt/invenio/src/scripts/create-test-user.sh"
.PHONY: load-fixtures

destroy-env:
	docker-compose -f $(DOCKER_FILE) down --volumes
	docker-compose -f $(DOCKER_FILE) rm -f
.PHONY: destroy-env

reload-env: destroy-env env
.PHONY: reload-env

shell-env:
	docker-compose -f $(DOCKER_FILE) exec $(SERVICE_NAME) /bin/bash
.PHONY: shell-env

root-shell-env:
	docker-compose -f $(DOCKER_FILE) exec -u root $(SERVICE_NAME) /bin/bash
.PHONY: root-shell-env

env: generate-certificates build-env populate-instance load-fixtures shell-env
.PHONY: env

generate-certificates:
	sh scripts/gen-cert.sh
.PHONY: generate-certificates

test:
	make pytest
.PHONY: test

###################  Local development helpful directives  ####################
###################           (pipenv + docker)            ####################
#
# Usage:
# make logs                     # displays log outputs from running services
# make build-local-env          # build pipenv, create and start containers
# make check-requirements-local # check requirements
# make local-env                # build virtual environment, load fixtures and starts api
# make populate-instance-local  # create database, tables and indices
# make serve-api-local          # start serving api
# make shell-local-env          # start bash inside pipenv
# make destroy-local-env        # stop and remove containers, networks, images, and volume and pipenv
# make reload-local-env         # restart containers, networks, images, and volume and pipenv
# make load-fixtures-local      # loads fixtures

PIPENV_DOTENV := .pipenv.env
PYTHON_VERSION_FILE := .python-version
Pablo Panero's avatar
Pablo Panero committed
81
PYTHON_VERSION := $(cat $(PYTHON_VERSION_FILE))
82
83
84
PIPENV_DOCKER_FILE := docker-compose.yml

check-requirements-local:
85
	PYTHON_VERSION=$(PYTHON_VERSION) /bin/bash scripts/pipenv/requirements.sh
86
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
117
118
119
.PHONY: check-requirements-local

build-local-env: check-requirements-local
	docker-compose -f $(PIPENV_DOCKER_FILE) up -d --build --remove-orphans
	PIPENV_DOTENV_LOCATION=$(PIPENV_DOTENV) pipenv run sh scripts/pipenv/bootstrap
.PHONY: build-local-env

populate-instance-local:
	PIPENV_DOTENV_LOCATION=$(PIPENV_DOTENV) pipenv run sh scripts/populate-instance.sh
.PHONY: populate-instance-local

load-fixtures-local:
	PIPENV_DOTENV_LOCATION=$(PIPENV_DOTENV) pipenv run sh scripts/create-test-user.sh
.PHONY: load-fixtures-local

serve-api-local:
	PIPENV_DOTENV_LOCATION=$(PIPENV_DOTENV) pipenv run sh scripts/pipenv/server
.PHONY: serve-api-local

local-env: build-local-env populate-instance-local serve-api-local
.PHONY: local-env

shell-local-env:
	PIPENV_DOTENV_LOCATION=$(PIPENV_DOTENV) pipenv shell
.PHONY: shell-local-env

destroy-local-env:
	docker-compose -f $(PIPENV_DOCKER_FILE) down --volumes
	docker-compose -f $(PIPENV_DOCKER_FILE) rm -f
	pipenv --rm
.PHONY: destroy-local-env

reload-local-env: destroy-local-env local-env
.PHONY: reload-local-env