From 9d680db4620f0313cc12c1a2a53e09d016c5dd03 Mon Sep 17 00:00:00 2001 From: RJ Seibert Date: Sun, 24 Sep 2017 01:21:15 -0400 Subject: [PATCH] Use an enviroENV for db host --- .project | 11 +++++++++++ Dockerfile | 4 ++++ config.yaml.sample | 2 +- database/pgsql/pgsql.go | 8 +++++++- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 .project diff --git a/.project b/.project new file mode 100644 index 00000000..48d12ad4 --- /dev/null +++ b/.project @@ -0,0 +1,11 @@ + + + clair + + + + + + + + diff --git a/Dockerfile b/Dockerfile index 151c3deb..a79a462e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,12 +14,16 @@ FROM golang:1.8-alpine +ENV POSTGRESQL_SERVICE_HOST localhost + VOLUME /config EXPOSE 6060 6061 ADD . /go/src/github.com/coreos/clair/ WORKDIR /go/src/github.com/coreos/clair/ +COPY /config.yaml /etc/clair/config.yaml + RUN apk add --no-cache git bzr rpm xz && \ go install -v github.com/coreos/clair/cmd/clair && \ mv /go/bin/clair /clair && \ diff --git a/config.yaml.sample b/config.yaml.sample index 23e85fed..4bf48580 100644 --- a/config.yaml.sample +++ b/config.yaml.sample @@ -20,7 +20,7 @@ clair: options: # PostgreSQL Connection string # https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING - source: host=localhost port=5432 user=postgres sslmode=disable statement_timeout=60000 + source: host=$POSTGRESQL_SERVICE_HOST port=5432 user=postgres sslmode=disable statement_timeout=60000 # Number of elements kept in the cache # Values unlikely to change (e.g. namespaces) are cached in order to save prevent needless roundtrips to the database. diff --git a/database/pgsql/pgsql.go b/database/pgsql/pgsql.go index 335b77c7..1d8a8785 100644 --- a/database/pgsql/pgsql.go +++ b/database/pgsql/pgsql.go @@ -22,6 +22,7 @@ import ( "net/url" "strings" "time" + "os" "gopkg.in/yaml.v2" @@ -202,7 +203,12 @@ func openDatabase(registrableComponentConfig database.RegistrableComponentConfig } // Open database. - pg.DB, err = sql.Open("postgres", pg.config.Source) + host := os.Getenv("POSTGRESQL_SERVICE_HOST") + + modifiedSource := strings.Replace(pg.config.Source, "$POSTGRESQL_SERVICE_HOST", host, -1) + fmt.Println("postgresql hostname replaced: ", modifiedSource) + + pg.DB, err = sql.Open("postgres", modifiedSource) if err != nil { pg.Close() return nil, fmt.Errorf("pgsql: could not open database: %v", err)