Makefile 5.57 KB
Newer Older
1

2
3
4
5
6
7
8
9
10
11
12
13
14
###################  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
Carina Antunes's avatar
Carina Antunes committed
15
16
# make test                   # runs tests
# make lint                   # runs linting tools
17
18

SERVICE_NAME :=  cern-search-api
19
WORKER_NAME :=  worker
Carina Antunes's avatar
Carina Antunes committed
20
API_TOKEN := .api_token
21
22
23
24
25
26
27
28
MODE?=full
TEST_MODE=test

ifeq ($(MODE),$(TEST_MODE))
DOCKER_FILE := docker-compose.test.yml
else
DOCKER_FILE := docker-compose.full.yml
endif
29
30

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

Carina Antunes's avatar
Carina Antunes committed
34
35
36
37
38

es:
	docker-compose -f docker-compose.es.yml up -d --remove-orphans
.PHONY: es

Carina Antunes's avatar
Carina Antunes committed
39
rebuild-env:
Carina Antunes's avatar
Carina Antunes committed
40
	docker-compose -f $(DOCKER_FILE) build --no-cache --parallel
41
.PHONY: rebuild-env
Carina Antunes's avatar
Carina Antunes committed
42

43
44
45
46
47
48
49
50
51
es-setup:
	curl -XPUT "http://localhost:9200/_settings" -H 'Content-Type: application/json' -d' \
	{\
        "index": {\
            "search.slowlog.level": "trace",\
            "search.slowlog.threshold.query.trace": "0ms"\
	    }\
	}'
.PHONY: es-setup
52
53
54
55
56
57

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

populate-instance:
Carina Antunes's avatar
Carina Antunes committed
58
	docker-compose -f $(DOCKER_FILE) exec -T $(SERVICE_NAME) /bin/bash -c \
59
		"sh /opt/invenio/src/scripts/populate-instance.sh"
60
.PHONY: populate-instance
61
62

load-fixtures:
Carina Antunes's avatar
Carina Antunes committed
63
	docker-compose -f $(DOCKER_FILE) exec -T $(SERVICE_NAME) /bin/bash -c \
64
65
66
67
68
69
70
71
		"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

72
73
stop-env:
	docker-compose -f $(DOCKER_FILE) down --volumes
74
.PHONY: stop-env
75

Carina Antunes's avatar
Carina Antunes committed
76
reload-env: destroy-env generate-certificates rebuild-env populate-instance es-setup load-fixtures shell-env
77
78
79
80
81
82
.PHONY: reload-env

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

83
84
shell-worker:
	docker-compose -f $(DOCKER_FILE) exec $(WORKER_NAME) /bin/bash
85
.PHONY: shell-worker
86

Carina Antunes's avatar
Carina Antunes committed
87
88
89
env-staging: generate-certificates build-env populate-instance es-setup shell-env
.PHONY: env-staging

90
env: generate-certificates build-env populate-instance es-setup load-fixtures shell-env
91
92
93
94
95
96
.PHONY: env

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

97
pytest:
Carina Antunes's avatar
Carina Antunes committed
98
	docker-compose -f $(DOCKER_FILE) exec -T $(SERVICE_NAME) /bin/bash -c \
99
	"pytest tests -vv;"
100
.PHONY: pytest
101

102
103
104
105
ci-test: build-env pytest
.PHONY: ci-test

test: stop-env build-env pytest
106
.PHONY: test
107

Carina Antunes's avatar
Carina Antunes committed
108
lint:
Carina Antunes's avatar
Carina Antunes committed
109
	pre-commit run --all-files --show-diff-on-failure
Carina Antunes's avatar
Carina Antunes committed
110
111
.PHONY: lint

Carina Antunes's avatar
Carina Antunes committed
112

113
###################  Local development helpful directives  ####################
Carina Antunes's avatar
Carina Antunes committed
114
###################           (poetry + docker)            ####################
115
116
117
#
# Usage:
# make logs                     # displays log outputs from running services
Carina Antunes's avatar
Carina Antunes committed
118
# make build-local-env          # build poetry env, create and start containers
119
120
121
122
# 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
Carina Antunes's avatar
Carina Antunes committed
123
124
125
# make shell-local-env          # start bash inside poetry
# make destroy-local-env        # stop and remove containers, networks, images, and volume and poetry env
# make reload-local-env         # restart containers, networks, images, and volume and poetry env
126
# make load-fixtures-local      # loads fixtures
Carina Antunes's avatar
Carina Antunes committed
127
128
# make local-test               # runs tests
# make local-lint               # runs linting tools
129

Carina Antunes's avatar
Carina Antunes committed
130
POETRY_DOTENV := .poetry.env
131
PYTHON_VERSION_FILE := .python-version
Carina Antunes's avatar
Carina Antunes committed
132
PYTHON_VERSION := $(cat $(PYTHON_VERSION_FILE) | xargs)
133
134
PIPENV_DOCKER_FILE := docker-compose.yml

Carina Antunes's avatar
Carina Antunes committed
135
136
137
138
local-env-logs:
	docker-compose -f $(PIPENV_DOCKER_FILE) logs -f
.PHONY: local-env-logs

139
140
141
142
143
144
check-requirements-local:
	PYTHON_VERSION=$(PYTHON_VERSION) sh scripts/pipenv/requirements.sh
.PHONY: check-requirements-local

build-local-env: check-requirements-local
	docker-compose -f $(PIPENV_DOCKER_FILE) up -d --build --remove-orphans
Carina Antunes's avatar
Carina Antunes committed
145
	sh with_env.sh $(POETRY_DOTENV) poetry run sh scripts/pipenv/bootstrap
146
147
148
.PHONY: build-local-env

populate-instance-local:
Carina Antunes's avatar
Carina Antunes committed
149
	sh with_env.sh $(POETRY_DOTENV) poetry run sh scripts/pipenv/populate-instance.sh
150
151
152
.PHONY: populate-instance-local

load-fixtures-local:
Carina Antunes's avatar
Carina Antunes committed
153
	sh with_env.sh $(POETRY_DOTENV) poetry run sh scripts/create-test-user.sh
154
155
156
.PHONY: load-fixtures-local

serve-api-local:
Carina Antunes's avatar
Carina Antunes committed
157
	sh with_env.sh $(POETRY_DOTENV) poetry run sh scripts/pipenv/server
158
159
160
161
162
163
.PHONY: serve-api-local

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

shell-local-env:
Carina Antunes's avatar
Carina Antunes committed
164
	sh with_env.sh $(POETRY_DOTENV) poetry shell
165
166
167
168
169
170
171
172
173
.PHONY: shell-local-env

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

reload-local-env: destroy-local-env local-env
.PHONY: reload-local-env
Carina Antunes's avatar
Carina Antunes committed
174
175

local-test:
176
	@echo running tests...;
Carina Antunes's avatar
Carina Antunes committed
177
	sh with_env.sh $(POETRY_DOTENV) poetry run pytest tests -v;
178
.PHONY: local-test
Carina Antunes's avatar
Carina Antunes committed
179
180

local-lint:
Carina Antunes's avatar
Carina Antunes committed
181
	poetry run pre-commit run --all-files --show-diff-on-failure;
182
.PHONY: local-lint