Use an enviroENV for db host

This commit is contained in:
RJ Seibert 2017-09-24 01:21:15 -04:00
parent 148b3e075d
commit 9d680db462
4 changed files with 23 additions and 2 deletions

11
.project Normal file
View 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>

View File

@ -14,12 +14,16 @@
FROM golang:1.8-alpine FROM golang:1.8-alpine
ENV POSTGRESQL_SERVICE_HOST localhost
VOLUME /config VOLUME /config
EXPOSE 6060 6061 EXPOSE 6060 6061
ADD . /go/src/github.com/coreos/clair/ ADD . /go/src/github.com/coreos/clair/
WORKDIR /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 && \ RUN apk add --no-cache git bzr rpm xz && \
go install -v github.com/coreos/clair/cmd/clair && \ go install -v github.com/coreos/clair/cmd/clair && \
mv /go/bin/clair /clair && \ mv /go/bin/clair /clair && \

View File

@ -20,7 +20,7 @@ clair:
options: options:
# PostgreSQL Connection string # PostgreSQL Connection string
# https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING # 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 # 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. # Values unlikely to change (e.g. namespaces) are cached in order to save prevent needless roundtrips to the database.

View File

@ -22,6 +22,7 @@ import (
"net/url" "net/url"
"strings" "strings"
"time" "time"
"os"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
@ -202,7 +203,12 @@ func openDatabase(registrableComponentConfig database.RegistrableComponentConfig
} }
// Open database. // 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 { if err != nil {
pg.Close() pg.Close()
return nil, fmt.Errorf("pgsql: could not open database: %v", err) return nil, fmt.Errorf("pgsql: could not open database: %v", err)