This repository has been archived by the owner on Jul 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker.mk
65 lines (51 loc) · 1.45 KB
/
docker.mk
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
MYSQL := mysql:5.7
POSTGRES := postgres:11
PASSWORD ?= "Passw0rd"
all: pull
pull:
$(MAKE) -f docker.mk -j 2 pull-mysql pull-postgres
pull-mysql:
docker pull $(MYSQL)
pull-postgres:
docker pull $(POSTGRES)
start:
$(MAKE) -f docker.mk -j 2 mysql.cid postgres.cid
mysql.cid:
docker run --rm -d \
--cidfile $@ \
--name migerl-mysql \
-e MYSQL_ALLOW_EMPTY_PASSWORD=1 \
-e MYSQL_ROOT_PASSWORD="" \
-p 3306:3306 \
$(MYSQL)
postgres.cid:
docker run --rm -d \
--cidfile $@ \
--name migerl-postgres \
-e POSTGRES_PASSWORD=$(PASSWORD) \
-p 5432:5432 \
$(POSTGRES)
stop:
$(MAKE) -f docker.mk -j 2 stop-mysql stop-postgres
stop-%:
[ -f $*.cid ] && docker stop $$(cat $*.cid) || true
rm -f $*.cid
create-db: create-mysql create-postgres
create-mysql:
RET=""; TRIES=30; \
until [ "$$RET" != "" ] || [ $$TRIES -eq 0 ]; do \
sleep 1; \
RET=$$(echo "select 'ok'" | mysql -h127.0.0.1 -uroot); \
TRIES=$$(($$TRIES - 1)); \
done || true;
echo "create database if not exists migerl_test default charset=utf8;" \
| mysql -h127.0.0.1 -uroot
create-postgres:
RET=""; TRIES=30; \
until [ "$$RET" != "" ] || [ $$TRIES -eq 0 ]; do \
sleep 1; \
RET=$$(PGPASSWORD=$(PASSWORD) psql -c "select 1;" -U postgres -h 127.0.0.1 -p 5432); \
TRIES=$$(($$TRIES - 1)); \
done || true;
PGPASSWORD=$(PASSWORD) psql -c "create database migerl_test;" -U postgres -h 127.0.0.1 -p 5432
.PHONY: all pull pull-* start stop stop-* create-db create-mysql create-postgres