forked from kreneskyp/ix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·190 lines (142 loc) · 4.47 KB
/
Makefile
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
DOCKER_COMPOSE=docker-compose.yml
DOCKERFILE=Dockerfile
DOCKER_REGISTRY=ghcr.io
DOCKER_REPOSITORY=${DOCKER_REGISTRY}/ix/sandbox
HASH_FILES=requirements*.txt package.json Dockerfile
IMAGE_TAG=$(shell cat $(HASH_FILES) | md5sum | cut -d ' ' -f 1)
IMAGE_URL=$(DOCKER_REPOSITORY):$(IMAGE_TAG)
IMAGE_SENTINEL=.sentinel/image
DOCKER_COMPOSE_RUN=docker-compose run --rm web
DOCKER_COMPOSE_RUN_WITH_PORT=docker-compose run -p 8000:8000 --rm web
# set to skip build, primarily used by github workflows to skip builds when image is cached
NO_IMAGE_BUILD?=0
.PHONY: image-tag
image-tag:
@echo ${IMAGE_TAG}
.PHONY: image-url
image-url:
@echo ${IMAGE_URL}
# build existence check
.sentinel:
mkdir -p .sentinel
# inner build target for image
${IMAGE_SENTINEL}: .sentinel $(HASH_FILES)
ifneq (${NO_IMAGE_BUILD}, 1)
echo building ${IMAGE_URL}
docker build -t ${IMAGE_URL} -f $(DOCKERFILE) .
docker tag ${IMAGE_URL} ${DOCKER_REPOSITORY}:latest
touch $@
endif
# setup target for docker-compose, add deps here to apply to all compose sessions
.PHONY: compose
compose: image
# =========================================================
# Build
# =========================================================
# dev setup - runs all initial setup steps in one go
.PHONY: dev_setup
dev_setup: image frontend migrate dev_fixtures
# build image
.PHONY: image
image: ${IMAGE_SENTINEL}
# full frontend build
.PHONY: frontend
frontend: compose npm_install graphene_to_graphql compile_relay webpack
# install npm packages
.PHONY: npm_install
npm_install: compose package.json
docker-compose run --rm web npm install
# compile javascript
.PHONY: webpack
webpack: compose
${DOCKER_COMPOSE_RUN} webpack --progress
# compile javascript in watcher mode
.PHONY: webpack-watch
webpack-watch: compose
${DOCKER_COMPOSE_RUN} webpack --progress --watch
# compile graphene graphql classes into schema.graphql for javascript
.PHONY: graphene_to_graphql
graphene_to_graphql: compose
${DOCKER_COMPOSE_RUN} ./manage.py graphql_schema --out ./frontend/schema.graphql
# compile javascript
.PHONY: compile_relay
compile_relay: compose
${DOCKER_COMPOSE_RUN} npm run relay
# =========================================================
# Run
# =========================================================
# run backend and frontend. This starts uvicorn for asgi+websockers
# and nginx to serve static files
.PHONY: server
server: compose
docker-compose up web nginx
# run django debug server, backup in case nginx ever breaks
.PHONY: runserver
runserver: compose
${DOCKER_COMPOSE_RUN_WITH_PORT} ./manage.py runserver 0.0.0.0:8000
# run worker
.PHONY: worker
worker: compose
${DOCKER_COMPOSE_RUN} celery.sh
# =========================================================
# Shells
# =========================================================
.PHONY: bash
bash: compose
${DOCKER_COMPOSE_RUN} /bin/bash
.PHONY: shell
shell: compose
${DOCKER_COMPOSE_RUN} ./manage.py shell_plus
# =========================================================
# Dev tools
# =========================================================
# shortcut to run django migrations
.PHONY: migrate
migrate: compose
${DOCKER_COMPOSE_RUN} ./manage.py migrate
# shortcut to generate django migrations
.PHONY: migrations
migrations: compose
${DOCKER_COMPOSE_RUN} ./manage.py makemigrations
# load initial data needed for dev environment
.PHONY: dev_fixtures
dev_fixtures: compose
${DOCKER_COMPOSE_RUN} ./manage.py loaddata fake_user
# use management commands for now since fixtures didn't load correctly
${DOCKER_COMPOSE_RUN} ./manage.py create_moderator_v1
${DOCKER_COMPOSE_RUN} ./manage.py create_coder_v1
${DOCKER_COMPOSE_RUN} ./manage.py create_planner_v3
${DOCKER_COMPOSE_RUN} ./manage.py create_dad_jokes_v1
# =========================================================
# Testing
# =========================================================
.PHONY: test
test: compose pytest
.PHONY: lint
test: compose flake8 black-check
.PHONY: format
format: black isort
.PHONY: black
black: compose
${DOCKER_COMPOSE_RUN} black .
.PHONY: black-check
black-check: compose
${DOCKER_COMPOSE_RUN} black --check .
.PHONY: flake8
flake8: compose
${DOCKER_COMPOSE_RUN} flake8 .
.PHONY: isort
isort: compose
${DOCKER_COMPOSE_RUN} isort .
.PHONY: pytest
pytest: compose
${DOCKER_COMPOSE_RUN} pytest
.PHONY: pyright
pyright: compose
${DOCKER_COMPOSE_RUN} pyright
# =========================================================
# Cleanup
# =========================================================
.PHONY: clean
clean:
rm -rf .sentinel