forked from AlmaLinux/almalinux.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
145 lines (120 loc) · 6.42 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
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
CURRENT_UID ?= $(shell id -u)
CURRENT_GID ?= $(shell id -g)
TARGET_REPO ?= "[email protected]:AlmaLinux/almalinux.org.git"
TARGET_BRANCH ?= "master"
.PHONY: default
default: dev ;
dev: #: Start development environment
cp -n .env.dist .env
LOCAL_UID=${CURRENT_UID} LOCAL_GID=${CURRENT_GID} docker-compose up --abort-on-container-exit
build-dev: #: Build development Docker images
LOCAL_UID=${CURRENT_UID} LOCAL_GID=${CURRENT_GID} docker-compose build web
LOCAL_UID=${CURRENT_UID} LOCAL_GID=${CURRENT_GID} docker-compose build frontend
clean-dev: #: Clean development environment, remove docker images and data
LOCAL_UID=${CURRENT_UID} LOCAL_GID=${CURRENT_GID} docker-compose down --rmi local -v
mypy: #: Run mypy static type checker for Python modules
LOCAL_UID=${CURRENT_UID} LOCAL_GID=${CURRENT_GID} docker-compose run -u ${CURRENT_UID} web pipenv run mypy almalinux www commons
web-shell: #: Enter backend shell within docker, as a regular user, new service instance
LOCAL_UID=${CURRENT_UID} LOCAL_GID=${CURRENT_GID} docker-compose run -u ${CURRENT_UID} web /bin/bash
web-root-shell: #: Enter backend shell within docker, as root, new service instance
LOCAL_UID=${CURRENT_UID} LOCAL_GID=${CURRENT_GID} docker-compose run web /bin/bash
web-attach: #: Attach to backend shell within docker, as a regular user, running instance
docker exec -ti -u ${CURRENT_UID} web /bin/bash
web-root-attach: #: Attach to backend shell within docker, as root, running instance
docker exec -ti web /bin/bash
messages: #: Update message files for all translations in known domains
LOCAL_UID=${CURRENT_UID} LOCAL_GID=${CURRENT_GID} docker-compose run -u ${CURRENT_UID} web pipenv run python3 ./manage.py makemessages -a --domain django
LOCAL_UID=${CURRENT_UID} LOCAL_GID=${CURRENT_GID} docker-compose run -u ${CURRENT_UID} web pipenv run python3 ./manage.py makemessages -a --domain djangojs --ignore "frontend/node_modules/**"
LOCAL_UID=${CURRENT_UID} LOCAL_GID=${CURRENT_GID} docker-compose run -u ${CURRENT_UID} web pipenv run python3 ./manage.py compilemessages
compile-messages: #: Compile messages without source extraction
LOCAL_UID=${CURRENT_UID} LOCAL_GID=${CURRENT_GID} docker-compose run -u ${CURRENT_UID} web pipenv run python3 ./manage.py compilemessages
migrations: #: Update message files for all translations in known domains
LOCAL_UID=${CURRENT_UID} LOCAL_GID=${CURRENT_GID} docker-compose run -u ${CURRENT_UID} web pipenv run python3 ./manage.py makemigrations
frontend-shell: #: Enter frontend shell within docker, as a regular user, new service instance
LOCAL_UID=${CURRENT_UID} LOCAL_GID=${CURRENT_GID} docker-compose run -u ${CURRENT_UID} frontend /bin/bash
frontend-root-shell: #: Enter frontend shell within docker, as root, new service instance
LOCAL_UID=${CURRENT_UID} LOCAL_GID=${CURRENT_GID} docker-compose run frontend /bin/bash
frontend-attach: #: Attach to frontend shell within docker, as a regular user, running instance
docker exec -ti -u ${CURRENT_UID} frontend /bin/bash
frontend-root-attach: #: Attach to frontend shell within docker, as root, running instance
docker exec -ti frontend /bin/bash
assemble: # INTERNAL: assemble deployment asset for deployment
rm -rf tmp/deploy
rm -rf tmp/deploy_out
mkdir -p tmp
mkdir -p tmp/deploy_out
git clone ${TARGET_REPO} tmp/deploy --branch ${TARGET_BRANCH}
# Use local install .venv and node_modules to reuse local install as sort of a cache
cp -R .venv tmp/deploy
cp -R frontend/node_modules tmp/deploy/frontend
# Build dependencies
LOCAL_UID=${CURRENT_UID} LOCAL_GID=${CURRENT_GID} docker-compose run -u ${CURRENT_UID} frontend /bin/bash -c 'cd /app/tmp/deploy/ && make assemble-frontend'
LOCAL_UID=${CURRENT_UID} LOCAL_GID=${CURRENT_GID} docker-compose run -u ${CURRENT_UID} web /bin/bash -c 'cd /app/tmp/deploy/ && make assemble-web'
# Cleanup
rm tmp/deploy/Pipfile
rm tmp/deploy/Pipfile.lock
rm tmp/deploy/.env
rm tmp/deploy/.env.dist
rm -rf tmp/deploy/.git
rm -rf tmp/deploy/.venv
rm -rf tmp/deploy/static
rm -rf tmp/deploy/media
rm -rf tmp/deploy/Dockerfile*
rm -rf tmp/deploy/docker-compose.yml
rm -rf tmp/deploy/.mypy.ini
rm -rf tmp/deploy/.editorconfig
rm -rf tmp/deploy/.gitignore
rm -rf tmp/deploy/README.md
rm -rf tmp/deploy/CONTRIBUTING.md
rm -rf tmp/deploy/screenshot.png
# Build production docker image
docker build --rm -f ./Dockerfile-production -t almalinux.org:latest .
# Exporting image for deployment...
docker save almalinux.org:latest > tmp/deploy_out/almalinux.org.image.tar
# Assembling deployment asset
mv tmp/deploy/public tmp/deploy_out
cp tmp/deploy/docker-compose.production.yml tmp/deploy_out/docker-compose.yml
cd tmp/deploy_out && tar -zcvf ../deployment.tar.gz .
# Cleanup deployment workspace
rm -rf tmp/deploy_out/
rm -rf tmp/deploy/
assemble-frontend: # INTERNAL - package and build frontend
yarn --cwd=/app/tmp/deploy/frontend/ install
yarn --cwd=/app/tmp/deploy/frontend/ build
rm -rf /app/tmp/deploy/frontend
assemble-web: # INTERNAL - package and build web
cp /app/tmp/deploy/.env.dist /app/tmp/deploy/.env
cd /app/tmp/deploy/ && pipenv sync
cd /app/tmp/deploy/ && pipenv clean
cd /app/tmp/deploy/ && pipenv run python3 ./manage.py collectstatic
cd /app/tmp/deploy/ && pipenv run python3 ./manage.py compilemessages
cd /app/tmp/deploy/ && pipenv lock -r > requirements.txt
uwsgi: # INTERNAL - start UWSGI server, within production image
uwsgi \
--chdir=/app/ \
--module=almalinux.wsgi:application \
--master \
--pidfile=/tmp/almalinux.org.pid \
--socket=0.0.0.0:9000 \
--processes=4 \
--enable-threads \
--threads=2 \
--harakiri=20 \
--max-requests=5000 \
--vacuum
runserver: # INTERNAL - start internal development server. This is supposed to be run inside Docker.
@echo 'Delaying start of local development server to allow for dependencies to boot'
@sleep 5
su - web -c 'cd /app && pipenv install --dev'
su - web -c 'cd /app && pipenv run python3 manage.py migrate'
su - web -c 'cd /app && pipenv run python3 manage.py runserver 0.0.0.0:8080'
frontend-runserver: # INTERNAL - start internal frontend development server. This is supposed to be run inside Docker.
su - web -c 'yarn --cwd=/app/frontend/ install'
su - web -c 'yarn --cwd=/app/frontend/ dev-server --host 0.0.0.0 --public http://localhost:8090 --port 8090'
help: #: Show this help
@fgrep -h "#:" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/#://'
all: dev
%:
@echo 'Invalid command'
@make help