From 9b986c4c144210025a9d3a67808f52d9aa4db5ee Mon Sep 17 00:00:00 2001 From: Edvard Date: Wed, 6 Feb 2019 16:35:51 +0100 Subject: [PATCH] Nuke OpenRC from docker image, update readme's --- Dockerfile | 7 +------ dockerfiles/README.md | 8 ++++---- dockerfiles/continuousLogSync-service | 6 ------ dockerfiles/lightSync-service | 6 ------ dockerfiles/startup_script.sh | 6 +++--- environments/staging.toml | 4 ---- pkg/datastore/postgres/postgres.go | 2 ++ pkg/transformers/shared/constants/external.go | 17 ----------------- postgraphile/Dockerfile | 2 +- postgraphile/README.md | 2 +- 10 files changed, 12 insertions(+), 48 deletions(-) delete mode 100755 dockerfiles/continuousLogSync-service delete mode 100755 dockerfiles/lightSync-service diff --git a/Dockerfile b/Dockerfile index 056f60db..4c853c43 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,16 +14,11 @@ RUN GCO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflag # Second stage FROM alpine -RUN apk --no-cache --update add openrc -RUN mkdir -p /run/openrc/ && touch /run/openrc/softlevel COPY --from=builder /go/src/github.com/vulcanize/vulcanizedb/vulcanizedb /app/vulcanizedb COPY --from=builder /go/src/github.com/vulcanize/vulcanizedb/environments/staging.toml /app/environments/ -COPY --from=builder /go/src/github.com/vulcanize/vulcanizedb/dockerfiles/lightSync-service /etc/init.d/lightSync -COPY --from=builder /go/src/github.com/vulcanize/vulcanizedb/dockerfiles/continuousLogSync-service /etc/init.d/continuousLogSync COPY --from=builder /go/src/github.com/vulcanize/vulcanizedb/dockerfiles/startup_script.sh /app/ COPY --from=builder /go/src/github.com/vulcanize/vulcanizedb/db/migrations/* /app/ COPY --from=builder /go/src/github.com/pressly/goose/cmd/goose/goose /app/goose WORKDIR /app -RUN rc-status -CMD ["./goose"] +CMD ["./startup_script.sh"] diff --git a/dockerfiles/README.md b/dockerfiles/README.md index ea6e19c9..5bf3c61a 100644 --- a/dockerfiles/README.md +++ b/dockerfiles/README.md @@ -19,14 +19,14 @@ e` * `CONTRACT_ABI_[CONTRACT NAME]="ABI STRING"` * `CONTRACT_DEPLOYMENT-BLOCK_[CONTRACT NAME]=0` (doesn't really matter on a short chain, just avoids long unnecessary searching) 6. Start the `lightSync` and `continuousLogSync` services: - * `rc-service lightSync start` - * `rc-service continuousLogSync start` + * `./vulcanizedb lightSync --config environments/staging.toml` + * `./vulcanizedb continuousLogSync --config environments/staging.toml` ### Automated The steps above have been rolled into a script: `/app/startup_script.sh`, which just assumes the DB env variables have been set, and defaults the rest to Kovan according to `environments/staging.toml`. This can be called with something like: -`docker run -d -e DATABASE_NAME=vulcanize_public -e DATABASE_HOSTNAME=localhost -e DATABASE_PORT=5432 -e DATABASE_USER=vulcanize -e DATABASE_PASSWORD=vulcanize [container name] ./startup_script.sh` +`docker run -d -e DATABASE_NAME=vulcanize_public -e DATABASE_HOSTNAME=localhost -e DATABASE_PORT=5432 -e DATABASE_USER=vulcanize -e DATABASE_PASSWORD=vulcanize m0ar/images:vDB` ### Logging -When running, vDB services log to `/vulcanizedb.log`. +When running, vDB services log to `/app/vulcanizedb.log`. diff --git a/dockerfiles/continuousLogSync-service b/dockerfiles/continuousLogSync-service deleted file mode 100755 index 9c3adfd5..00000000 --- a/dockerfiles/continuousLogSync-service +++ /dev/null @@ -1,6 +0,0 @@ -#!/sbin/openrc-run -command=/app/vulcanizedb -command_args="continuousLogSync --config /app/environments/staging.toml &" -pidfile= -name="continuousLogSync" -description="runs vDB in continuousLogSync mode using staging.toml" diff --git a/dockerfiles/lightSync-service b/dockerfiles/lightSync-service deleted file mode 100755 index a9143de1..00000000 --- a/dockerfiles/lightSync-service +++ /dev/null @@ -1,6 +0,0 @@ -#!/sbin/openrc-run -command=/app/vulcanizedb -command_args="lightSync --config /app/environments/staging.toml &" -pidfile= -name="lightSync" -description="runs vDB in lightSync mode using staging.toml" diff --git a/dockerfiles/startup_script.sh b/dockerfiles/startup_script.sh index 47547d99..8373715a 100755 --- a/dockerfiles/startup_script.sh +++ b/dockerfiles/startup_script.sh @@ -21,9 +21,9 @@ set +e ./goose postgres "$CONNECT_STRING" up if [ $? -eq 0 ]; then # Fire up the services - rc-service lightSync start - rc-service continuousLogSync start + ./vulcanizedb lightSync --config environments/staging.toml & + ./vulcanizedb continuousLogSync --config environments/staging.toml & else echo "Could not run migrations. Are the database details correct?" fi - +wait diff --git a/environments/staging.toml b/environments/staging.toml index 8954a483..ad320f27 100644 --- a/environments/staging.toml +++ b/environments/staging.toml @@ -1,8 +1,4 @@ [database] - name = "vulcanize_public" - hostname = "localhost" - user = "vulcanize" - password = "vulcanize" port = 5432 [client] diff --git a/pkg/datastore/postgres/postgres.go b/pkg/datastore/postgres/postgres.go index 82a1b2ac..dc43e351 100644 --- a/pkg/datastore/postgres/postgres.go +++ b/pkg/datastore/postgres/postgres.go @@ -18,6 +18,7 @@ package postgres import ( "errors" + "github.com/sirupsen/logrus" "github.com/jmoiron/sqlx" _ "github.com/lib/pq" //postgres driver @@ -40,6 +41,7 @@ var ( func NewDB(databaseConfig config.Database, node core.Node) (*DB, error) { connectString := config.DbConnectionString(databaseConfig) + logrus.Info("Using connection string: ", connectString) db, err := sqlx.Connect("postgres", connectString) if err != nil { return &DB{}, ErrDBConnectionFailed diff --git a/pkg/transformers/shared/constants/external.go b/pkg/transformers/shared/constants/external.go index d18270be..5b14d435 100644 --- a/pkg/transformers/shared/constants/external.go +++ b/pkg/transformers/shared/constants/external.go @@ -6,23 +6,7 @@ import ( "github.com/spf13/viper" ) -var initialized = false - -func initConfig() { - if initialized { - return - } - - if err := viper.ReadInConfig(); err == nil { - fmt.Printf("Using config file: %s\n\n", viper.ConfigFileUsed()) - } else { - panic(fmt.Sprintf("Could not find environment file: %v", err)) - } - initialized = true -} - func getEnvironmentString(key string) string { - initConfig() value := viper.GetString(key) if value == "" { panic(fmt.Sprintf("No environment configuration variable set for key: \"%v\"", key)) @@ -32,7 +16,6 @@ func getEnvironmentString(key string) string { // Returns an int from the environment, defaulting to 0 if it does not exist func getEnvironmentInt64(key string) int64 { - initConfig() value := viper.GetInt64(key) if value == -1 { return 0 diff --git a/postgraphile/Dockerfile b/postgraphile/Dockerfile index 4a98c0e3..f2785e36 100644 --- a/postgraphile/Dockerfile +++ b/postgraphile/Dockerfile @@ -6,4 +6,4 @@ COPY . /app run yarn install RUN ["./node_modules/typescript/bin/tsc"] EXPOSE 3000 -CMD ["node", "/app/build/dist/src/index.js"] +CMD ["node", "/app/build/dist/index.js"] diff --git a/postgraphile/README.md b/postgraphile/README.md index 048a1f7a..0bd5958c 100644 --- a/postgraphile/README.md +++ b/postgraphile/README.md @@ -10,7 +10,7 @@ Build the docker image in this directory. Start the `GraphiQL` frontend by: `DATABASE_NAME`, `DATABASE_USER`, `DATABASE_PASSWORD` (and optionally `DATABASE_PORT` if running on non-standard port). * The specified user needs to be `superuser` on the vulcanizeDB database -* Run the container (ex. `docker run -e DATABASE_HOST=localhost -e DATABASE_NAME=vulcanize_public -e DATABASE_USER=vulcanize -e DATABASE_PASSWORD=vulcanize -d postgraphile:latest`) +* Run the container (ex. `docker run -e DATABASE_HOST=localhost -e DATABASE_NAME=vulcanize_public -e DATABASE_USER=vulcanize -e DATABASE_PASSWORD=vulcanize -d m0ar/images:postgraphile-alpine`) * GraphiQL is available at `:3000/graphiql`