This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
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 #6 from 8thlight/VDB-337-Dockerize-vDB
VDB-337 Dockerize vDB
- Loading branch information
Showing
14 changed files
with
176 additions
and
45 deletions.
There are no files selected for viewing
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,16 @@ | ||
.git | ||
.travis.yml | ||
.idea | ||
bin | ||
.gitignore | ||
integration_test | ||
LICENSE | ||
postgraphile | ||
.private_blockchain_password | ||
README.md | ||
scripts | ||
Supfile | ||
test_config | ||
.travis.yml | ||
vulcanizedb.log | ||
Dockerfile |
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,24 @@ | ||
FROM golang:alpine as builder | ||
RUN apk --update --no-cache add make git g++ | ||
|
||
# Build statically linked vDB binary (wonky path because of Dep) | ||
RUN mkdir -p /go/src/github.com/vulcanize/vulcanizedb | ||
ADD . /go/src/github.com/vulcanize/vulcanizedb | ||
WORKDIR /go/src/github.com/vulcanize/vulcanizedb | ||
RUN GCO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' . | ||
|
||
# Build migration tool | ||
RUN go get -u -d github.com/pressly/goose/cmd/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 | ||
|
||
# Second stage | ||
FROM alpine | ||
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/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 | ||
CMD ["./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
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,32 @@ | ||
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 superuser `vulcanize` | ||
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: | ||
* `./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 m0ar/images:vDB` | ||
|
||
### Logging | ||
When running, vDB services log to `/app/vulcanizedb.log`. | ||
|
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,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 | ||
./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 |
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
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,7 @@ | ||
package-lock.json | ||
yarn.lock | ||
node_modules | ||
Dockerfile | ||
README.md | ||
spec | ||
.dockerignore |
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,9 @@ | ||
FROM mhart/alpine-node:10 | ||
RUN apk --update --no-cache add make g++ python findutils postgresql-dev | ||
|
||
WORKDIR /app | ||
COPY . /app | ||
run yarn install | ||
RUN ["./node_modules/typescript/bin/tsc"] | ||
EXPOSE 3000 | ||
CMD ["node", "/app/build/dist/index.js"] |
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
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