-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
160 lines (125 loc) · 5.3 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
DOCKER_COMPOSE = docker compose --env-file .env --env-file .env.local
DOCKER_REGISTRY = ghcr.io
# Assign PWD explicitly, as PWD is user home when called via ansible make module
PWD := $(abspath $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST))))))
# Read environment variable files, in case they exist
-include .env .env.local
# Default target when running `make`
.PHONY: all
all: docker-up
# SFTP server config
etc/sftp/users.conf:
mkdir -p etc/sftp
touch etc/sftp/users.conf
etc/sftp/ssh_host_ed25519_key:
mkdir -p etc/sftp
ssh-keygen -f etc/sftp/ssh_host_ed25519_key -t ed25519 -N '' -C 'MobiData BW SFTP server' -q
etc/sftp/ssh_host_rsa_key:
mkdir -p etc/sftp
ssh-keygen -f etc/sftp/ssh_host_rsa_key -t rsa -b 4096 -N '' -C 'MobiData BW SFTP server' -q
.PHONY: init
init: etc/sftp/users.conf etc/sftp/ssh_host_ed25519_key etc/sftp/ssh_host_rsa_key
mkdir -p var/gtfs
touch -a var/gtfs/pgbouncer-dsn.txt
mkdir -p var/geoserver/datadir
touch -a var/geoserver/datadir/global.xml
mkdir -p var/geoserver/gwc_cache_dir
mkdir -p var/geoserver/logs
mkdir -p var/goaccess/data
mkdir -p var/goaccess/report
mkdir -p var/ocpdb/logs
mkdir -p var/ocpdb/temp
mkdir -p var/park-api/logs
mkdir -p var/park-api/temp
mkdir -p var/gbfs/temp
mkdir -p var/www/datasets/traffic/incidents-bw
# Container management
# --------------------
# Login to Docker registry
.PHONY: docker-login
docker-login:
docker login $(DOCKER_REGISTRY)
# Builds and starts all docker containers. Supports starting by SERVICE (e.g. `make docker-up SERVICE=redis`)
.PHONY: docker-up
docker-up: init
$(DOCKER_COMPOSE) up --wait-timeout 120 $(SERVICE)
# Start containers in background (or recreate containers while they are running attached to another terminal). Supports starting or
# restarting by SERVICE (e.g. `make docker-up-detached SERVICE=redis`)
.PHONY: docker-up-detached
docker-up-detached: init
$(DOCKER_COMPOSE) up --detach --wait --wait-timeout 120 $(SERVICE)
# Reload geoserver config. Might fail with service "geoserver"
# is not running if geoserver has not yet been started. This can be ignored
$(DOCKER_COMPOSE) exec geoserver /usr/local/bin/geoserver-rest-reload.sh || true
.PHONY: docker-down
docker-down:
$(DOCKER_COMPOSE) down --remove-orphans --timeout 60 $(SERVICE)
.PHONY: docker-kill
docker-kill:
$(DOCKER_COMPOSE) kill --remove-orphans $(SERVICE)
# Restart all containers (default) or only the containers specified by SERVICE (e.g. `make docker-restart SERVICE=redis`)
.PHONY: docker-restart
docker-restart: init
$(DOCKER_COMPOSE) restart $(SERVICE)
# Pull all images or only the containers specified by SERVICE (e.g. `make docker-pull SERVICE=redis`)
.PHONY: docker-pull
docker-pull:
$(DOCKER_COMPOSE) --profile import-new-gtfs,import-logs pull $(SERVICE)
# Tear down all containers and delete all volumes
.PHONY: docker-purge
docker-purge:
$(DOCKER_COMPOSE) down --remove-orphans --volumes
# Prints the entire Compose config, with environment variables filled in.
# Optionally, a SERVICE can be specified to restrict the config.
.PHONY: docker-config
docker-config:
$(DOCKER_COMPOSE) config $(SERVICE)
# Lists all docker containers. Supports filtering by SERVICE (e.g. `make docker-ps SERVICE=lamassu`).
.PHONY: docker-ps
docker-ps:
$(DOCKER_COMPOSE) ps $(SERVICE)
.PHONY: docker-container-ip
docker-container-ip:
@docker inspect "$$($(DOCKER_COMPOSE) ps $(SERVICE) --format '{{print .Name}}')" | jq -rc '.[0].NetworkSettings.Networks.ipl_ipl.IPAddress'
# Geoserver management
# --------------------
.PHONY: reload-geoserver
reload-geoserver:
$(DOCKER_COMPOSE) exec geoserver /usr/local/bin/geoserver-rest-reload.sh
# Syncs Geoserver's var workspace dir to etc, excluding the overwritten datastore.xml
.PHONY: prepare-geoserver-workspace-for-commit
prepare-geoserver-workspace-for-commit:
rsync -av --exclude='*/datastore.xml' var/geoserver/datadir/workspaces etc/geoserver
rsync -av var/geoserver/datadir/gwc etc/geoserver
rsync -av var/geoserver/datadir/gwc-layers etc/geoserver
# GTFS data management
# --------------------
.PHONY: import-new-gtfs
import-new-gtfs: init
$(DOCKER_COMPOSE) build gtfs-importer
$(DOCKER_COMPOSE) --profile import-new-gtfs run --rm gtfs-importer
# make sure pgbouncer is running
$(DOCKER_COMPOSE) --profile import-new-gtfs up --detach --wait --wait-timeout 30 pgbouncer
$(DOCKER_COMPOSE) --profile import-new-gtfs exec pgbouncer /reload-pgbouncer-databases.sh
.PHONY: gtfs-db-psql
gtfs-db-psql:
$(DOCKER_COMPOSE) exec -e PGDATABASE gtfs-db /bin/sh -c 'export PGUSER="$$POSTGRES_USER" PGPASSWORD="$$POSTGRES_PASSWORD"; env PGDATABASE="$$(psql gtfs_importer -b -t --csv -c "SELECT db_name FROM latest_import" | xargs)" psql'
.PHONY: gtfs-db-latest-import
gtfs-db-latest-import:
$(DOCKER_COMPOSE) exec gtfs-db /bin/sh -c 'env PGUSER="$$POSTGRES_USER" PGPASSWORD="$$POSTGRES_PASSWORD" PGDATABASE=gtfs_importer psql -b -t --csv -c "SELECT db_name FROM latest_import"'
# OCPDB management
# ------------------
.PHONY: ocpdb-upgrade
ocpdb-upgrade:
$(DOCKER_COMPOSE) exec ocpdb-flask /bin/sh -c 'flask db upgrade'
.PHONY: ocpdb-shell
ocpdb-shell:
$(DOCKER_COMPOSE) exec ocpdb-flask /bin/sh
# ParkAPI management
# ------------------
.PHONY: park-api-upgrade
park-api-upgrade:
$(DOCKER_COMPOSE) exec park-flask /bin/sh -c 'flask db upgrade'
.PHONY: park-api-shell
park-api-shell:
$(DOCKER_COMPOSE) exec park-api-flask /bin/bash