From e6e66d58dd8519161a7a9f2be7792ef76dce0f63 Mon Sep 17 00:00:00 2001 From: Edvard Date: Wed, 30 Jan 2019 13:18:24 +0100 Subject: [PATCH] Add container service files and docker README --- .dockerignore | 2 -- Dockerfile | 10 +++++++- dockerfiles/README.md | 33 +++++++++++++++++++++++++++ dockerfiles/continuousLogSync-service | 6 +++++ dockerfiles/lightSync-service | 6 +++++ dockerfiles/startup_script.sh | 29 +++++++++++++++++++++++ pkg/transformers/frob/converter.go | 3 --- 7 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 dockerfiles/README.md create mode 100755 dockerfiles/continuousLogSync-service create mode 100755 dockerfiles/lightSync-service create mode 100755 dockerfiles/startup_script.sh diff --git a/.dockerignore b/.dockerignore index 47e3a24c..189c28b0 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,7 +3,6 @@ .idea bin .gitignore -environments integration_test LICENSE postgraphile @@ -15,4 +14,3 @@ test_config .travis.yml vulcanizedb.log Dockerfile - diff --git a/Dockerfile b/Dockerfile index ed79055c..056f60db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,8 +14,16 @@ 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/pressly/goose/cmd/goose/goose /app/goose +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"] diff --git a/dockerfiles/README.md b/dockerfiles/README.md new file mode 100644 index 00000000..d5e8fca3 --- /dev/null +++ b/dockerfiles/README.md @@ -0,0 +1,33 @@ +S +`Dockerfile` will build an alpine image containing: +- vDB as a binary with runtime deps statically linked: `/app/vulcanizedb` +- The migration tool goose: `/app/goose` +- Two services for running `lightSync` and `continuousLogSync`, started with the default configuration `environments/staging.toml`. + +By default, vDB is configured towards the Kovan deploy. The configuration values can be overridden using environment variables, using the same hierarchical naming pattern but in CAPS and using underscores. For example, the contract address for the `Pit` can be set with the variable `CONTRACT_ADDRESS_PIT="0x123..."`. + +## To use the container: +1. Setup a postgres database with owner `vulcanize` + * `vulcanize` does not _have_ to be owner, but otherwise permissions for + connection, tables, and sequences need to be added for the `public` and + `maker` schemas manually when the migrations have been run. +2. Set the env variables `DATABASE_NAME`, `DATABASE_HOSTNAME`, + `DATABASE_PORT`, `DATABASE_USER` & `DATABASE_PASSWORD` +3. Run the DB migrations: + * `./goose postgres "postgresql://$(DATABASE_USER):$(DATABASE_PASSWORD)@$(DATABASE_HOSTNAME):$(DATABASE_PORT)/$(DATABASE_NAME)?sslmode=disable" +e` +4. Set `CLIENT_IPCPATH` to a node endpoint +5. Set the contract variables: + * `CONTRACT_ADDRESS_[CONTRACT NAME]=0x123...` + * `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` + +### 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`. + +### Logging +When running, vDB services log to `/vulcanizedb.log`. + diff --git a/dockerfiles/continuousLogSync-service b/dockerfiles/continuousLogSync-service new file mode 100755 index 00000000..9c3adfd5 --- /dev/null +++ b/dockerfiles/continuousLogSync-service @@ -0,0 +1,6 @@ +#!/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 new file mode 100755 index 00000000..a9143de1 --- /dev/null +++ b/dockerfiles/lightSync-service @@ -0,0 +1,6 @@ +#!/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 new file mode 100755 index 00000000..47547d99 --- /dev/null +++ b/dockerfiles/startup_script.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# Runs the migrations and starts the lightSync and continuousLogSync services + +# Exit if the variable tests fail +set -e + +# Check the database variables are set +test $DATABASE_NAME +test $DATABASE_HOSTNAME +test $DATABASE_PORT +test $DATABASE_USER +test $DATABASE_PASSWORD + +# Construct the connection string for postgres +CONNECT_STRING=postgresql://$DATABASE_USER:$DATABASE_PASSWORD@$DATABASE_HOSTNAME:$DATABASE_PORT/$DATABASE_NAME?sslmode=disable +echo "Connecting with: $CONNECT_STRING" + +set +e + +# Run the DB migrations +./goose postgres "$CONNECT_STRING" up +if [ $? -eq 0 ]; then + # Fire up the services + rc-service lightSync start + rc-service continuousLogSync start +else + echo "Could not run migrations. Are the database details correct?" +fi + diff --git a/pkg/transformers/frob/converter.go b/pkg/transformers/frob/converter.go index 267626af..9d031ca9 100644 --- a/pkg/transformers/frob/converter.go +++ b/pkg/transformers/frob/converter.go @@ -19,8 +19,6 @@ package frob import ( "encoding/json" "fmt" - log "github.com/sirupsen/logrus" - "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" @@ -32,7 +30,6 @@ type FrobConverter struct{} func (FrobConverter) ToEntities(contractAbi string, ethLogs []types.Log) ([]interface{}, error) { var entities []interface{} - log.Info("blah") for _, ethLog := range ethLogs { entity := FrobEntity{} address := ethLog.Address