Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #7 from vulcanize/docker_compose
Browse files Browse the repository at this point in the history
dockerfiles and docker-compose
  • Loading branch information
i-norden authored Aug 14, 2020
2 parents 98d5615 + 3c7de44 commit f544c70
Show file tree
Hide file tree
Showing 10 changed files with 279 additions and 26 deletions.
24 changes: 0 additions & 24 deletions Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func initFuncs(cmd *cobra.Command, args []string) {
}

func setViperConfigs() {
ipc = viper.GetString("client.ipcpath")
ipc = viper.GetString("client.rpcPath")
databaseConfig = hc.Database{
Name: viper.GetString("database.name"),
Hostname: viper.GetString("database.hostname"),
Expand Down
40 changes: 40 additions & 0 deletions dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM golang:1.13-alpine as builder

RUN apk --update --no-cache add make git g++ linux-headers

# Get and build eth-contract-watcher
ADD . /go/src/github.com/vulcanize/eth-contract-watcher
WORKDIR /go/src/github.com/vulcanize/eth-contract-watcher
RUN GO111MODULE=on GCO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o eth-contract-watcher .

# Build migration tool
WORKDIR /
RUN git clone https://github.com/pressly/goose.git /go/src/github.com/pressly/goose/
WORKDIR /go/src/github.com/pressly/goose/cmd/goose
RUN GCO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -tags='no_mysql no_sqlite' -o goose .

WORKDIR /go/src/github.com/vulcanize/eth-contract-watcher

# app container
FROM alpine

ARG USER
ARG CONFIG_FILE

RUN adduser -Du 5000 $USER
WORKDIR /app
RUN chown $USER /app
USER $USER

# chown first so dir is writable
# note: using $USER is merged, but not in the stable release yet
COPY --chown=5000:5000 --from=builder /go/src/github.com/vulcanize/eth-contract-watcher/$CONFIG_FILE config.toml
COPY --chown=5000:5000 --from=builder /go/src/github.com/vulcanize/eth-contract-watcher/dockerfiles/startup_script.sh .

# keep binaries immutable
COPY --from=builder /go/src/github.com/vulcanize/eth-contract-watcher/eth-contract-watcher eth-contract-watcher
COPY --from=builder /go/src/github.com/pressly/goose/cmd/goose/goose goose
COPY --from=builder /go/src/github.com/vulcanize/eth-contract-watcher/db/migrations migrations/vulcanizedb
COPY --from=builder /go/src/github.com/vulcanize/eth-contract-watcher/environments environments

ENTRYPOINT ["/app/startup_script.sh"]
101 changes: 101 additions & 0 deletions dockerfiles/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
version: '3.2'

services:
geth:
image: ethereum/client-go:v1.9.11
expose:
- "8545"
- "8546"
ports:
- "127.0.0.1:8545:8545"
- "127.0.0.1:8546:8546"
command: ["--syncmode", "full",
"--cache", "4096",
"--cache.database", "50",
"--cache.gc", "50",
"--rpc",
"--rpcapi", "eth,net"]

contact-watcher-db:
restart: always
image: postgres:10.12-alpine
environment:
- POSTGRES_USER=vdbm
- POSTGRES_DB=vulcanize_public
- POSTGRES_PASSWORD=password
volumes:
- vulcanizedb_db_data:/var/lib/postgresql/data
expose:
- "5432"
ports:
- "127.0.0.1:8079:5432"

eth-header-sync:
depends_on:
- contact-watcher-db
build:
context: ./../
cache_from:
- alpine:latest
- golang:1.13
dockerfile: ./dockerfiles/header_sync/Dockerfile
args:
USER: "vdm"
CONFIG_FILE: ./environments/example.toml
volumes:
- ./geth.ipc:/geth.ipc
environment:
- STARTING_BLOCK_NUMBER=3327410
- VDB_COMMAND=sync
- DATABASE_NAME=vulcanize_public
- DATABASE_HOSTNAME=contact-watcher-db
- DATABASE_PORT=5432
- DATABASE_USER=vdbm
- DATABASE_PASSWORD=password

eth-contract-watcher:
depends_on:
- contact-watcher-db
build:
context: ./../
cache_from:
- alpine:latest
- golang:1.13
dockerfile: ./dockerfiles/Dockerfile
args:
USER: "vdm"
CONFIG_FILE: ./environments/example.toml
volumes:
- ./geth.ipc:/geth.ipc
environment:
- VDB_COMMAND=watch
- DATABASE_NAME=vulcanize_public
- DATABASE_HOSTNAME=contact-watcher-db
- DATABASE_PORT=5432
- DATABASE_USER=vdbm
- DATABASE_PASSWORD=password

contract-watcher-graphql:
restart: always
depends_on:
- contact-watcher-db
build:
context: ./../
cache_from:
- node:alpine
dockerfile: ./dockerfiles/postgraphile/Dockerfile
expose:
- "5000"
ports:
- "127.0.0.1:5000:5000"
command: ["--plugins", "@graphile/pg-pubsub",
"--subscriptions",
"--simple-subscriptions",
"--connection", "postgres://vdbm:password@contact-watcher-db:5432/vulcanize_public",
"--port", "5000",
"-n", "0.0.0.0",
"--schema", "public,eth",
"--append-plugins", "postgraphile-plugin-connection-filter"]

volumes:
vulcanizedb_db_data:
Empty file added dockerfiles/geth.ipc
Empty file.
43 changes: 43 additions & 0 deletions dockerfiles/header_sync/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FROM golang:1.13-alpine as builder

RUN apk --update --no-cache add make git g++ linux-headers

# Add this repo for the startup_script
ADD . /go/src/github.com/vulcanize/eth-contract-watcher

# Get and build eth-header-sync
RUN git clone https://github.com/vulcanize/eth-header-sync.git /go/src/github.com/vulcanize/eth-header-sync
WORKDIR /go/src/github.com/vulcanize/eth-header-sync
RUN GO111MODULE=on GCO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o eth-header-sync .

# Build migration tool
WORKDIR /
RUN git clone https://github.com/pressly/goose.git /go/src/github.com/pressly/goose/
WORKDIR /go/src/github.com/pressly/goose/cmd/goose
RUN GCO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -tags='no_mysql no_sqlite' -o goose .

WORKDIR /go/src/github.com/vulcanize/eth-header-sync

# app container
FROM alpine

ARG USER
ARG CONFIG_FILE

RUN adduser -Du 5000 $USER
WORKDIR /app
RUN chown $USER /app
USER $USER

# chown first so dir is writable
# note: using $USER is merged, but not in the stable release yet
COPY --chown=5000:5000 --from=builder /go/src/github.com/vulcanize/eth-contract-watcher/$CONFIG_FILE config.toml
COPY --chown=5000:5000 --from=builder /go/src/github.com/vulcanize/eth-contract-watcher/dockerfiles/header_sync/startup_script.sh .

# keep binaries immutable
COPY --from=builder /go/src/github.com/vulcanize/eth-header-sync/eth-header-sync eth-header-sync
COPY --from=builder /go/src/github.com/pressly/goose/cmd/goose/goose goose
COPY --from=builder /go/src/github.com/vulcanize/eth-header-sync/db/migrations migrations/vulcanizedb
COPY --from=builder /go/src/github.com/vulcanize/eth-header-sync/environments environments

ENTRYPOINT ["/app/startup_script.sh"]
42 changes: 42 additions & 0 deletions dockerfiles/header_sync/startup_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh
# Runs the db migrations and starts the watcher services

# Exit if the variable tests fail
set -e
set +x

# Check the database variables are set
test $DATABASE_HOSTNAME
test $DATABASE_NAME
test $DATABASE_PORT
test $DATABASE_USER
test $DATABASE_PASSWORD
test $VDB_COMMAND
test $STARTING_BLOCK_NUMBER
set +e

# Construct the connection string for postgres
VDB_PG_CONNECT=postgresql://$DATABASE_USER:$DATABASE_PASSWORD@$DATABASE_HOSTNAME:$DATABASE_PORT/$DATABASE_NAME?sslmode=disable

# Run the DB migrations
echo "Connecting with: $VDB_PG_CONNECT"
echo "Running database migrations"
./goose -dir migrations/vulcanizedb postgres "$VDB_PG_CONNECT" up


# If the db migrations ran without err
if [[ $? -eq 0 ]]; then
echo "Running the VulcanizeDB process"
./eth-header-sync ${VDB_COMMAND} --config=config.toml --starting-block-number=${STARTING_BLOCK_NUMBER}
else
echo "Could not run migrations. Are the database details correct?"
exit 1
fi

# If VulcanizeDB process was successful
if [ $? -eq 0 ]; then
echo "VulcanizeDB process ran successfully"
else
echo "Could not start VulcanizeDB process. Is the config file correct?"
exit 1
fi
8 changes: 8 additions & 0 deletions dockerfiles/postgraphile/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM node:alpine

RUN npm install -g postgraphile
RUN npm install -g postgraphile-plugin-connection-filter
RUN npm install -g @graphile/pg-pubsub

EXPOSE 5000
ENTRYPOINT ["postgraphile"]
41 changes: 41 additions & 0 deletions dockerfiles/startup_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/sh
# Runs the db migrations and starts the watcher services

# Exit if the variable tests fail
set -e
set +x

# Check the database variables are set
test $DATABASE_HOSTNAME
test $DATABASE_NAME
test $DATABASE_PORT
test $DATABASE_USER
test $DATABASE_PASSWORD
test $VDB_COMMAND
set +e

# Construct the connection string for postgres
VDB_PG_CONNECT=postgresql://$DATABASE_USER:$DATABASE_PASSWORD@$DATABASE_HOSTNAME:$DATABASE_PORT/$DATABASE_NAME?sslmode=disable

# Run the DB migrations
echo "Connecting with: $VDB_PG_CONNECT"
echo "Running database migrations"
./goose -dir migrations/vulcanizedb postgres "$VDB_PG_CONNECT" up


# If the db migrations ran without err
if [[ $? -eq 0 ]]; then
echo "Running the VulcanizeDB process"
./eth-contract-watcher ${VDB_COMMAND} --config=config.toml
else
echo "Could not run migrations. Are the database details correct?"
exit 1
fi

# If VulcanizeDB process was successful
if [ $? -eq 0 ]; then
echo "VulcanizeDB process ran successfully"
else
echo "Could not start VulcanizeDB process. Is the config file correct?"
exit 1
fi
4 changes: 3 additions & 1 deletion environments/example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
name = "vulcanize_public"
hostname = "localhost"
port = 5432
user = "vdbm"
password = "password"

[client]
rpcPath = ""
rpcPath = "/geth.ipc"

[contract]
network = ""
Expand Down

0 comments on commit f544c70

Please sign in to comment.