Fig.
This commit is contained in:
parent
50c09481ec
commit
16e742fcd7
5 changed files with 59 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
|||
FROM golang:1.3.1
|
||||
FROM golang:1.4.0
|
||||
ADD . /go/src/github.com/thermokarst/bactdb
|
||||
RUN go get -d -v github.com/thermokarst/bactdb/cmd/bactdb
|
||||
RUN go install github.com/thermokarst/bactdb/cmd/bactdb
|
||||
ENTRYPOINT /go/bin/bactdb serve
|
||||
CMD /go/bin/bactdb serve --keys=/bactdb/keys/
|
||||
EXPOSE 8901
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ var connectOnce sync.Once
|
|||
func Connect() {
|
||||
connectOnce.Do(func() {
|
||||
var err error
|
||||
setDBCredentialsFromFig()
|
||||
DB.Dbx, err = sqlx.Open("postgres", "timezone=UTC sslmode=disable")
|
||||
if err != nil {
|
||||
log.Fatal("Error connecting to PostgreSQL database (using PG* environment variables): ", err)
|
||||
|
@ -35,8 +36,6 @@ func Connect() {
|
|||
})
|
||||
}
|
||||
|
||||
var createSQL []string
|
||||
|
||||
// Create the database schema. It calls log.Fatal if it encounters an error.
|
||||
func Create(path string) {
|
||||
migrator, err := gomigrate.NewMigrator(DB.Dbx.DB, gomigrate.Postgres{}, path)
|
||||
|
@ -93,3 +92,12 @@ func transact(dbh modl.SqlExecutor, fn func(fbh modl.SqlExecutor) error) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func setDBCredentialsFromFig() {
|
||||
if figVal := os.Getenv("BACTDB_DB_1_PORT_5432_TCP_ADDR"); figVal != "" {
|
||||
err := os.Setenv("PGHOST", figVal)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
3
docker/postgres/Dockerfile
Normal file
3
docker/postgres/Dockerfile
Normal file
|
@ -0,0 +1,3 @@
|
|||
FROM postgres:9.3
|
||||
ADD dbsetup.sh /docker-entrypoint-initdb.d/
|
||||
|
10
docker/postgres/dbsetup.sh
Normal file
10
docker/postgres/dbsetup.sh
Normal file
|
@ -0,0 +1,10 @@
|
|||
#!/bin/bash
|
||||
|
||||
gosu postgres postgres --single <<- EOSQL
|
||||
CREATE USER "$PGUSER" WITH SUPERUSER PASSWORD '$PGPASSWORD';
|
||||
CREATE DATABASE $PGUSER;
|
||||
CREATE DATABASE $PGDB;
|
||||
EOSQL
|
||||
|
||||
{ echo; echo "host all \"$PGUSER\" 0.0.0.0/0 md5"; } >> "$PGDATA"/pg_hba.conf
|
||||
|
34
fig.yml
Normal file
34
fig.yml
Normal file
|
@ -0,0 +1,34 @@
|
|||
data:
|
||||
build: docker/postgres
|
||||
environment:
|
||||
PGUSER: bactdb_user
|
||||
PGPASSWORD: bactdb_pass
|
||||
PGDB: bactdbtest
|
||||
volumes:
|
||||
- /var/lib/postgresql/data
|
||||
command: true
|
||||
|
||||
db:
|
||||
image: bactdb_data
|
||||
environment:
|
||||
PGUSER: bactdb_user
|
||||
PGPASSWORD: bactdb_pass
|
||||
PGDB: bactdbtest
|
||||
ports:
|
||||
- "5432:5432"
|
||||
volumes_from:
|
||||
- data
|
||||
|
||||
app:
|
||||
build: .
|
||||
environment:
|
||||
PGUSER: bactdb_user
|
||||
PGPASSWORD: bactdb_pass
|
||||
PGDB: bactdbtest
|
||||
ports:
|
||||
- "8901:8901"
|
||||
volumes:
|
||||
- .:/bactdb
|
||||
links:
|
||||
- db
|
||||
|
Reference in a new issue