Skip to content

Commit c5218d0

Browse files
committed
make: add postgres target
1 parent c74fd2a commit c5218d0

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,30 @@ ifndef KITE_TRANSPORT
1818
KITE_TRANSPORT=WebSocket
1919
endif
2020

21+
ifndef POSTGRES_HOST
22+
ifdef DOCKER_HOST
23+
POSTGRES_HOST=$(shell echo $(DOCKER_HOST) | cut -d: -f2 | cut -c 3-)
24+
else
25+
POSTGRES_HOST==127.0.0.1
26+
endif
27+
endif
2128

2229
all: test
2330

31+
postgres:
32+
docker stop postgres && docker rm postgres || true
33+
docker run -d -v $(PWD)/postgres.d:/docker-entrypoint-initdb.d --name postgres -p 5432:5432 -P postgres:9.3
34+
while ! docker logs postgres 2>&1 | grep 'ready for start up' >/dev/null; do sleep 1; done
35+
psql -h $(POSTGRES_HOST) postgres -f kontrol/001-schema.sql -U postgres
36+
psql -h $(POSTGRES_HOST) -c 'CREATE DATABASE kontrol owner kontrol;' -U postgres
37+
psql -h $(POSTGRES_HOST) kontrol -f kontrol/002-table.sql -U postgres
38+
psql -h $(POSTGRES_HOST) kontrol -f kontrol/003-migration-001-add-kite-key-table.sql -U postgres
39+
psql -h $(POSTGRES_HOST) kontrol -f kontrol/003-migration-002-add-key-indexes.sql -U postgres
40+
echo "export KONTROL_POSTGRES_HOST=$(POSTGRES_HOST) KONTROL_STORAGE=postgres KONTROL_POSTGRES_USERNAME=kontrolapplication KONTROL_POSTGRES_DBNAME=kontrol KONTROL_POSTGRES_PASSWORD=somerandompassword"
41+
42+
postgres-logs:
43+
docker exec -ti postgres /bin/bash -c 'tail -f /var/lib/postgresql/data/pg_log/*.log'
44+
2445
format:
2546
@echo "$(OK_COLOR)==> Formatting the code $(NO_COLOR)"
2647
@gofmt -s -w *.go

postgres.d/001-postgres.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
cat >> /var/lib/postgresql/data/postgresql.conf <<EOF
6+
log_destination = 'stderr'
7+
logging_collector = on
8+
log_directory = 'pg_log'
9+
log_statement = 'all'
10+
EOF
11+
12+
mkdir -p /var/lib/postgresql/data/pg_log
13+
chown -R postgres:postgres /var/lib/postgresql/data/pg_log

0 commit comments

Comments
 (0)