forked from WordPress/openverse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjustfile
137 lines (106 loc) · 3.58 KB
/
justfile
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
81
82
83
84
85
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
set dotenv-load := false
COLOR := "\\033[0;34m"
NO_COLOR := "\\033[0m"
# Show all available recipes
@_default:
printf "\n{{ COLOR }}# API (path: \`api/\`)\n"
printf "===================={{ NO_COLOR }}\n"
just --list --unsorted
###########
# Version #
###########
export API_PY_VERSION := `grep 'python_version' Pipfile | awk -F' = ' '{print $2}' | sed 's/"//g'`
# Print the Python version specified in the `Pipfile`
@py-version:
echo $API_PY_VERSION
###########
# Install #
###########
# Install dependencies
install *args="--dev":
pipenv install {{ args }}
######
# Up #
######
# Bring up services specific to the API profile
up *flags:
env COMPOSE_PROFILES="api" just ../up {{ flags }}
# Wait for all profile services to be up
wait-up: up
just ../ingestion_server/wait # API profile includes ingestion server
just wait # API waits for ES in entrypoint
# Load sample data into API via ingestion server
init: wait-up
cd .. && ./load_sample_data.sh
recreate:
just ../down -v
just up "--force-recreate --build"
just init
##########
# Health #
##########
# Check the health of the service
@health host="localhost:50280":
-curl -s -o /dev/null -w '%{http_code}' 'http://{{ host }}/healthcheck/'
# Wait for the service to be healthy
@wait host="localhost:50280":
# The just command on the second line is executed in the context of the
# parent directory and so must be prefixed with `api/`.
just ../_loop \
'"$(just api/health {{ host }})" != "200"' \
"Waiting for the API to be healthy..."
########
# cURL #
########
# Make a cURL GET request to service at the given path
_curl-get path origin="http://localhost:50280":
curl "{{ origin }}/v1/{{ path }}"
# Make a test cURL GET request to the API
stats media="images" origin="http://localhost:50280":
just _curl-get "{{ media }}/stats/" {{ origin }}
# Launch a `pgcli` shell in the web container
pgcli db_user_pass="deploy" db_name="openledger": up
env DC_USER="opener" just ../_pgcli web {{ db_user_pass }} {{ db_name }} db
#########################
# Django administration #
#########################
# Run Django administrative commands locally
dj-local +args="":
pipenv run python manage.py {{ args }}
# Run Django administrative commands inside the Docker container
dj +args="": wait-up
env DC_USER="{{ env_var_or_default("DC_USER", "opener") }}" just ../exec web python manage.py {{ args }}
# Get IPython shell inside the Docker container
ipython:
just dj shell
# Get DB shell inside the Docker container
dbshell:
just dj dbshell
#########
# Tests #
#########
# Run API tests inside the Docker container
test *args: wait-up
env DC_USER="opener" just ../exec web pytest {{ args }}
# Run API tests locally
test-local *args:
pipenv run pytest {{ args }}
# Run smoke test for the API docs
doc-test: wait-up
curl \
-H 'Accept: application/vnd.oai.openapi+json' \
--fail \
'http://localhost:50280/v1/schema/' > openapi.json
#########
# NGINX #
#########
# Build and run the NGINX image locally
nginx upstream_url='api.openverse.engineering':
# upstream_url can also be set to 172.17.0.1:50280 for local testing
docker build --target nginx . -t openverse-api_nginx:latest
@echo "--> NGINX server will be run at http://localhost:9090, upstream at {{ upstream_url }}"
@echo "--> Try a static URL like http://localhost:9090/static/admin/css/base.css to test"
docker run --rm -p 9090:8080 -it \
-e DJANGO_NGINX_UPSTREAM_URL="{{ upstream_url }}" \
-e DJANGO_NGINX_GIT_REVISION="$(git rev-parse HEAD)" \
openverse-api_nginx:latest