-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
139 lines (130 loc) · 3.68 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
DOCKER_REPO ?= bryandragon
TOP_DIR := $(shell pwd)
LOGNAME := $(shell logname)
UID := $(shell id -u ${LOGNAME})
GID := $(shell id -g ${LOGNAME})
all: download transform load build
.PHONY: all
clean:
docker rmi $(DOCKER_REPO)/langdb-download &>/dev/null || true
docker rmi $(DOCKER_REPO)/langdb-transform &>/dev/null || true
docker rmi $(DOCKER_REPO)/langdb-load &>/dev/null || true
docker rmi $(DOCKER_REPO)/langdb &>/dev/null || true
rm -rf $(TOP_DIR)/data/*
.PHONY: clean
# Builds the langdb-download Docker image.
build-download:
docker build \
--rm \
-f $(TOP_DIR)/build/Dockerfile-download \
-t $(DOCKER_REPO)/langdb-download \
$(TOP_DIR)
.PHONY: build-download
# Downloads sources.
#
# * data/raw/cldr/common/bcp47/*.xml
# * data/raw/cldr/common/dtd/ldmlBCP47.dtd
# * data/raw/iso15924.txt
# * data/raw/ISO-639-2_utf-8.txt
# * data/raw/iso-639-3-macrolanguages.tab
# * data/raw/iso-639-3_Name_Index.tab
# * data/raw/iso-639-3_Retirements.tab
# * data/raw/iso639-5.tsv
# * data/raw/language-subtag-registry
# * data/raw/language-tag-extensions-registry
download: build-download
docker run \
--rm \
-it \
--user=$(UID):$(GID) \
--volume=$(TOP_DIR)/data:/mnt/data \
$(DOCKER_REPO)/langdb-download
.PHONY: download
# Builds the langdb-transform Docker image.
build-transform:
docker build \
--rm \
-f $(TOP_DIR)/build/Dockerfile-transform \
-t $(DOCKER_REPO)/langdb-transform \
$(TOP_DIR)
.PHONY: build-transform
# Converts raw sources to JSON format.
transform: build-transform
docker run \
--rm \
-it \
--user=$(UID):$(GID) \
--volume=$(TOP_DIR)/data:/mnt/data \
$(DOCKER_REPO)/langdb-transform
.PHONY: transform
# Builds the langdb-load Docker image.
build-load:
docker build \
--rm \
-f $(TOP_DIR)/build/Dockerfile-load \
-t $(DOCKER_REPO)/langdb-load \
$(TOP_DIR)
.PHONY: build-load
# Seeds the database and dumps it to data/sql/langdb.sql. It works as follows:
#
# 1. Starts a temporary postgres container with load/migrations/ and
# data/ mounted as volumes. The database schema is created automatically
# when the container starts.
# 2. Starts the langdb-load container (with data/ mounted as a volume),
# which connects to the the temporary postgres container and populates
# the database.
# 3. Invokes pg_dump in the running temporary postgres container to dump
# the fully-seeded database as a SQL file in the mounted data/ volume.
load: build-load
set -eu ;\
docker network create langdb-load &>/dev/null || true ;\
POSTGRES_CID=$$( \
docker run \
--rm \
-dt \
--network=langdb-load \
--hostname=postgres \
--volume=$(TOP_DIR)/data:/mnt/data \
--volume=$(TOP_DIR)/load/migrations:/docker-entrypoint-initdb.d \
-e POSTGRES_DB=langdb \
-e POSTGRES_USER=langdb \
-e POSTGRES_PASSWORD=langdb \
postgres:13 \
) ;\
sleep 10 ;\
docker run \
--rm \
-it \
--network=langdb-load \
--volume=$(TOP_DIR)/data:/mnt/data \
-e PGHOST=postgres \
-e PGDATABASE=langdb \
-e PGUSER=langdb \
-e PGPASSWORD=langdb \
$(DOCKER_REPO)/langdb-load ;\
mkdir -p $(TOP_DIR)/data/sql ;\
docker exec -it --user=$(UID):$(GID) $$POSTGRES_CID \
pg_dump \
--verbose \
--clean \
--no-comments \
--if-exists \
--column-inserts \
--file=/mnt/data/sql/langdb.sql \
--encoding=utf8 \
--username=langdb \
langdb ;\
docker kill -s SIGTERM $$POSTGRES_CID ;\
sleep 3 ;\
docker network rm langdb-load # &>/dev/null || true
.PHONY: load
# Builds the langdb Docker image, copying data/sql/langdb.sql
# to /docker-entrypoint-initdb.d/ so that it will be applied when the
# container starts.
build:
docker build \
--rm \
-f $(TOP_DIR)/build/Dockerfile \
-t $(DOCKER_REPO)/langdb \
$(TOP_DIR)
.PHONY: build