Use an enviroENV for db host
This commit is contained in:
parent
148b3e075d
commit
9d680db462
11
.project
Normal file
11
.project
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>clair</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -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 && \
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user