Update Dockerfile to run migrations
This commit is contained in:
parent
7312b330cd
commit
d0f5110dec
29
Dockerfile
29
Dockerfile
@ -1,3 +1,28 @@
|
||||
FROM timescale/timescaledb:latest-pg14
|
||||
FROM golang:1.16-alpine as builder
|
||||
|
||||
COPY ./schema.sql /docker-entrypoint-initdb.d/init.sql
|
||||
RUN apk --update --no-cache add make git g++ linux-headers
|
||||
|
||||
ADD . /go/src/github.com/vulcanize/ipld-eth-db
|
||||
|
||||
# Build migration tool
|
||||
WORKDIR /go/src/github.com/pressly
|
||||
RUN git clone https://github.com/pressly/goose.git
|
||||
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_sqlite3' -o goose .
|
||||
|
||||
# app container
|
||||
FROM alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=builder /go/src/github.com/vulcanize/ipld-eth-db/scripts/startup_script.sh .
|
||||
|
||||
# copy over files for multi-node setup
|
||||
COPY --from=builder /go/src/github.com/vulcanize/ipld-eth-db/docker-compose.test.yml docker-multi-node/docker-compose.test.yml
|
||||
COPY --from=builder /go/src/github.com/vulcanize/ipld-eth-db/scripts/init-access-node.sh docker-multi-node/scripts/init-access-node.sh
|
||||
COPY --from=builder /go/src/github.com/vulcanize/ipld-eth-db/scripts/init-data-node.sh docker-multi-node/scripts/init-data-node.sh
|
||||
|
||||
COPY --from=builder /go/src/github.com/pressly/goose/cmd/goose/goose goose
|
||||
COPY --from=builder /go/src/github.com/vulcanize/ipld-eth-db/db/migrations migrations/vulcanizedb
|
||||
|
||||
ENTRYPOINT ["/app/startup_script.sh"]
|
||||
|
@ -15,7 +15,7 @@ Schemas and utils for IPLD ETH Postgres database
|
||||
* Spin up an access node and three data nodes using [docker-compose.test.yml](./docker-compose.test.yml):
|
||||
|
||||
```bash
|
||||
docker-compose -f docker-compose.test.yml up timescale-test-db pg_data_node_1 pg_data_node_2 pg_data_node_3
|
||||
docker-compose -f docker-compose.test.yml up
|
||||
```
|
||||
|
||||
Following final output should be seen on all the nodes:
|
||||
|
@ -1,9 +1,9 @@
|
||||
-- +goose NO TRANSACTION
|
||||
-- +goose Up
|
||||
-- this is generated by a script
|
||||
SELECT add_data_node('dn3', host => 'pg_data_node_3', port => 5432, database => 'vulcanize_testing_v4', password => 'password');
|
||||
SELECT add_data_node('dn2', host => 'pg_data_node_2', port => 5432, database => 'vulcanize_testing_v4', password => 'password');
|
||||
SELECT add_data_node('dn1', host => 'pg_data_node_1', port => 5432, database => 'vulcanize_testing_v4', password => 'password');
|
||||
SELECT add_data_node('dn3', host => 'data-node-3', port => 5432, database => 'vulcanize_testing_v4', password => 'password');
|
||||
SELECT add_data_node('dn2', host => 'data-node-2', port => 5432, database => 'vulcanize_testing_v4', password => 'password');
|
||||
SELECT add_data_node('dn1', host => 'data-node-1', port => 5432, database => 'vulcanize_testing_v4', password => 'password');
|
||||
|
||||
CALL distributed_exec($$ CREATE SCHEMA eth $$);
|
||||
|
||||
|
@ -1,26 +1,14 @@
|
||||
version: '3.2'
|
||||
|
||||
services:
|
||||
statediff-migrations:
|
||||
restart: on-failure
|
||||
depends_on:
|
||||
- test-db
|
||||
image: vulcanize/statediff-migrations:v0.9.0
|
||||
|
||||
test-db:
|
||||
restart: always
|
||||
image: postgres:10.12-alpine
|
||||
command: ["postgres", "-c", "log_statement=all"]
|
||||
environment:
|
||||
POSTGRES_USER: "vdbm"
|
||||
POSTGRES_DB: "vulcanize_testing"
|
||||
POSTGRES_PASSWORD: "password"
|
||||
ports:
|
||||
- "127.0.0.1:8066:5432"
|
||||
|
||||
timescale-test-db:
|
||||
restart: always
|
||||
access-node:
|
||||
image: timescale/timescaledb:latest-pg14
|
||||
restart: always
|
||||
container_name: access-node
|
||||
depends_on:
|
||||
- data-node-1
|
||||
- data-node-2
|
||||
- data-node-3
|
||||
command: ["postgres", "-c", "log_statement=all"]
|
||||
environment:
|
||||
POSTGRES_USER: "postgres"
|
||||
@ -31,10 +19,10 @@ services:
|
||||
volumes:
|
||||
- ./scripts/init-access-node.sh:/docker-entrypoint-initdb.d/init-access-node.sh
|
||||
|
||||
pg_data_node_1:
|
||||
data-node-1:
|
||||
image: timescale/timescaledb:latest-pg14
|
||||
container_name: pg_data_node_1
|
||||
restart: unless-stopped
|
||||
container_name: data-node-1
|
||||
command: ["postgres", "-c", "log_statement=all"]
|
||||
environment:
|
||||
POSTGRES_USER: "postgres"
|
||||
@ -45,10 +33,10 @@ services:
|
||||
volumes:
|
||||
- ./scripts/init-data-node.sh:/docker-entrypoint-initdb.d/init-data-node.sh
|
||||
|
||||
pg_data_node_2:
|
||||
data-node-2:
|
||||
image: timescale/timescaledb:latest-pg14
|
||||
container_name: pg_data_node_2
|
||||
restart: unless-stopped
|
||||
container_name: data-node-2
|
||||
command: ["postgres", "-c", "log_statement=all"]
|
||||
environment:
|
||||
POSTGRES_USER: "postgres"
|
||||
@ -59,10 +47,10 @@ services:
|
||||
volumes:
|
||||
- ./scripts/init-data-node.sh:/docker-entrypoint-initdb.d/init-data-node.sh
|
||||
|
||||
pg_data_node_3:
|
||||
data-node-3:
|
||||
image: timescale/timescaledb:latest-pg14
|
||||
container_name: pg_data_node_3
|
||||
restart: unless-stopped
|
||||
container_name: data-node-3
|
||||
command: ["postgres", "-c", "log_statement=all"]
|
||||
environment:
|
||||
POSTGRES_USER: "postgres"
|
||||
|
@ -7,6 +7,7 @@ VDB_PG_CONNECT=postgresql://$DATABASE_USER:$DATABASE_PASSWORD@$DATABASE_HOSTNAME
|
||||
|
||||
# Run the DB migrations
|
||||
echo "Connecting with: $VDB_PG_CONNECT"
|
||||
sleep 15
|
||||
echo "Running database migrations"
|
||||
./goose -dir migrations/vulcanizedb postgres "$VDB_PG_CONNECT" up-to 21
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user