-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
110 lines (91 loc) · 3.15 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
SHELL := /bin/bash
REPO_NAME := openai-hello-world
ifeq ($(OS),Windows_NT)
PYTHON = python.exe
ACTIVATE_VENV = venv\Scripts\activate
else
PYTHON = python3.11
ACTIVATE_VENV = source venv/bin/activate
endif
PIP = $(PYTHON) -m pip
ifneq ("$(wildcard .env)","")
include .env
else
$(shell echo -e "OPENAI_API_KEY=SET-ME-PLEASE\nENVIRONMENT=dev\nDOCKERHUB_USERNAME=localhost\nDOCKERHUB_ACCESS_TOKEN=SET-ME-PLEASE\n" >> .env)
endif
.PHONY: analyze pre-commit init lint clean test build release
# Default target executed when no arguments are given to make.
all: help
analyze:
cloc . --exclude-ext=svg,json,zip --vcs=git
release:
git commit -m "fix: force a new release" --allow-empty && git push
# -------------------------------------------------------------------------
# Install and run pre-commit hooks
# -------------------------------------------------------------------------
pre-commit:
pre-commit install
pre-commit autoupdate
pre-commit run --all-files
# ---------------------------------------------------------
# create python virtual environments for prod
# ---------------------------------------------------------
init:
make clean
$(PYTHON) -m venv venv && \
$(ACTIVATE_VENV) && \
$(PIP) install --upgrade pip && \
$(PIP) install -r requirements/prod.txt && \
deactivate
# ---------------------------------------------------------
# create python virtual environments for dev
# ---------------------------------------------------------
init-dev:
make init && \
npm install && \
$(ACTIVATE_VENV) && \
$(PIP) install -r requirements/dev.txt && \
deactivate && \
pre-commit install
test:
python -m unittest discover -s app/
lint:
isort .
pre-commit run --all-files
black .
flake8 ./app/
pylint ./app/**/*.py
clean:
rm -rf venv node_modules app/__pycache__ package-lock.json
docker-build:
docker build -t ${DOCKERHUB_USERNAME}/${REPO_NAME} .
docker-push:
source .env && \
docker tag ${DOCKERHUB_USERNAME}/${REPO_NAME} ${DOCKERHUB_USERNAME}/${REPO_NAME}:latest && \
echo "${DOCKERHUB_ACCESS_TOKEN}" | docker login --username=${DOCKERHUB_USERNAME} --password-stdin && \
docker push ${DOCKERHUB_USERNAME}/${REPO_NAME}:latest
docker-run:
source .env && \
docker run -it -e OPENAI_API_KEY=${OPENAI_API_KEY} -e ENVIRONMENT=prod ${DOCKERHUB_USERNAME}/${REPO_NAME}:latest
docker-prune:
@if [ "`docker ps -aq`" ]; then \
docker stop $(docker ps -aq); \
fi
@docker container prune -f
@docker image prune -af
@docker builder prune -af
######################
# HELP
######################
help:
@echo '===================================================================='
@echo 'analyze - generate code analysis report'
@echo 'release - force a new GitHub release'
@echo 'init - create a Python virtual environment and install prod dependencies'
@echo 'init-dev - install dev dependencies'
@echo 'test - run Python unit tests'
@echo 'lint - run Python linting'
@echo 'clean - destroy the Python virtual environment'
@echo 'docker-build - build the Docker image'
@echo 'docker-push - push the Docker image to DockerHub'
@echo 'docker-run - run the Docker image'