This repository has been archived by the owner on Jan 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from vulcanize/docker_compose
dockerfiles and docker-compose
- Loading branch information
Showing
10 changed files
with
279 additions
and
26 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters