-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
129 lines (102 loc) · 3.81 KB
/
Makefile
File metadata and controls
129 lines (102 loc) · 3.81 KB
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
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
PROJECT_DIR := $(dir $(MKFILE_PATH))
# Set additional build args for docker image build using make arguments
IMAGE_NAME := pycon_backend
ifeq (docker-build,$(firstword $(MAKECMDGOALS)))
TAG_NAME := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(TAG_NAME):;@:)
endif
TAG_NAME := $(if $(TAG_NAME),$(TAG_NAME),local)
CONTAINER_NAME = $(IMAGE_NAME)_$(TAG_NAME)_container
ifeq ($(DOCKER_DEBUG),true)
DOCKER_MID_BUILD_OPTIONS = --progress=plain --no-cache
DOCKER_END_BUILD_OPTIONS = 2>&1 | tee docker-build.log
else
DOCKER_MID_BUILD_OPTIONS =
DOCKER_END_BUILD_OPTIONS =
endif
AWS_LAMBDA_READYZ_PAYLOAD = '{\
"resource": "/readyz/",\
"path": "/readyz/",\
"httpMethod": "GET",\
"requestContext": {\
"resourcePath": "/readyz/",\
"httpMethod": "GET",\
"path": "/readyz/"\
},\
"headers": {"accept": "application/json"},\
"multiValueHeaders": {"accept": ["application/json"]},\
"queryStringParameters": null,\
"multiValueQueryStringParameters": null,\
"pathParameters": null,\
"stageVariables": null,\
"body": null,\
"isBase64Encoded": false\
}'
# =============================================================================
# Local development commands
# Setup local environments
local-setup:
@uv sync
# Run local development server
local-api: local-collectstatic
@ENV_PATH=envfile/.env.local uv run python app/manage.py runserver 8000
# Run django collectstatic
local-collectstatic:
@ENV_PATH=envfile/.env.local uv run python app/manage.py collectstatic --noinput
# Run django shell
local-shell:
@ENV_PATH=envfile/.env.local uv run python app/manage.py shell
# Run django makemigrations
local-makemigrations:
@ENV_PATH=envfile/.env.local uv run python app/manage.py makemigrations
# Run django migrate
local-migrate:
@ENV_PATH=envfile/.env.local uv run python app/manage.py migrate
# Devtools
hooks-install: local-setup
uv run pre-commit install
hooks-upgrade:
uv run pre-commit autoupdate
hooks-lint:
uv run pre-commit run --all-files
lint: hooks-lint # alias
# =============================================================================
# Zappa related commands
zappa-export:
uv run zappa save-python-settings-file
# =============================================================================
# Docker related commands
# Docker image build
# Usage: make docker-build <tag-name:=local>
# if you want to build with debug mode, set DOCKER_DEBUG=true
# ex) make docker-build or make docker-build some_TAG_NAME DOCKER_DEBUG=true
docker-build:
@docker build \
-f ./infra/Dockerfile -t $(IMAGE_NAME):$(TAG_NAME) \
--build-arg GIT_HASH=$(shell git rev-parse HEAD) \
--build-arg IMAGE_BUILD_DATETIME=$(shell date +%Y-%m-%d_%H:%M:%S) \
$(DOCKER_MID_BUILD_OPTIONS) $(PROJECT_DIR) $(DOCKER_END_BUILD_OPTIONS)
docker-run: docker-compose-up
@(docker stop $(CONTAINER_NAME) || true && docker rm $(CONTAINER_NAME) || true) > /dev/null 2>&1
@docker run -d --rm \
-p 48000:8080 \
--env-file envfile/.env.local --env-file envfile/.env.docker \
--name $(CONTAINER_NAME) \
$(IMAGE_NAME):$(TAG_NAME)
docker-readyz:
curl -X POST http://localhost:48000/2015-03-31/functions/function/invocations -d $(AWS_LAMBDA_READYZ_PAYLOAD) | jq '.body | fromjson'
docker-test: docker-run docker-readyz
docker-build-and-test: docker-build docker-test
docker-stop:
docker stop $(CONTAINER_NAME) || true
docker-rm: docker-stop
docker rm $(CONTAINER_NAME) || true
# Docker compose setup
# Below commands are for local development only
docker-compose-up:
docker compose --env-file envfile/.env.local -f ./infra/docker-compose.dev.yaml up -d
docker-compose-down:
docker compose --env-file envfile/.env.local -f ./infra/docker-compose.dev.yaml down
docker-compose-rm: docker-compose-down
docker compose --env-file envfile/.env.local -f ./infra/docker-compose.dev.yaml rm