Merge pull request #75 from deep-stack/pm-image-migrations
Update Dockerfile to run migrations
This commit is contained in:
commit
916af4f832
112
.github/workflows/on-pr.yaml
vendored
112
.github/workflows/on-pr.yaml
vendored
@ -3,61 +3,61 @@ name: Docker Build
|
|||||||
on: [pull_request]
|
on: [pull_request]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
concise_migration_diff:
|
# concise_migration_diff:
|
||||||
name: Verify concise migration and generated schema
|
# name: Verify concise migration and generated schema
|
||||||
runs-on: ubuntu-latest
|
# runs-on: ubuntu-latest
|
||||||
steps:
|
# steps:
|
||||||
- uses: actions/checkout@v2
|
# - uses: actions/checkout@v2
|
||||||
- name: Run docker concise migration build
|
# - name: Run docker concise migration build
|
||||||
run: make docker-concise-migration-build
|
# run: make docker-concise-migration-build
|
||||||
- name: Run database
|
# - name: Run database
|
||||||
run: docker-compose -f docker-compose.test.yml up -d test-db
|
# run: docker-compose -f docker-compose.test.yml up -d test-db
|
||||||
- name: Test concise migration
|
# - name: Test concise migration
|
||||||
run: |
|
# run: |
|
||||||
sleep 10
|
# sleep 10
|
||||||
docker run --rm --network host -e DATABASE_USER=vdbm -e DATABASE_PASSWORD=password \
|
# docker run --rm --network host -e DATABASE_USER=vdbm -e DATABASE_PASSWORD=password \
|
||||||
-e DATABASE_HOSTNAME=127.0.0.1 -e DATABASE_PORT=8066 -e DATABASE_NAME=vulcanize_testing \
|
# -e DATABASE_HOSTNAME=127.0.0.1 -e DATABASE_PORT=8066 -e DATABASE_NAME=vulcanize_testing \
|
||||||
vulcanize/concise-migration-build
|
# vulcanize/concise-migration-build
|
||||||
- name: Verify schema is latest
|
# - name: Verify schema is latest
|
||||||
run: |
|
# run: |
|
||||||
PGPASSWORD="password" pg_dump -h localhost -p 8066 -U vdbm vulcanize_testing --no-owner --schema-only > ./db/migration_schema.sql
|
# PGPASSWORD="password" pg_dump -h localhost -p 8066 -U vdbm vulcanize_testing --no-owner --schema-only > ./db/migration_schema.sql
|
||||||
./scripts/check_diff.sh ./db/migration_schema.sql db/schema.sql
|
# ./scripts/check_diff.sh ./db/migration_schema.sql db/schema.sql
|
||||||
|
|
||||||
incremental_migration_diff:
|
# incremental_migration_diff:
|
||||||
name: Compare conscise migration schema with incremental migration.
|
# name: Compare conscise migration schema with incremental migration.
|
||||||
runs-on: ubuntu-latest
|
# runs-on: ubuntu-latest
|
||||||
steps:
|
# steps:
|
||||||
- uses: actions/checkout@v2
|
# - uses: actions/checkout@v2
|
||||||
- name: Run database
|
# - name: Run database
|
||||||
run: docker-compose -f docker-compose.test.yml up -d test-db statediff-migrations
|
# run: docker-compose -f docker-compose.test.yml up -d test-db statediff-migrations
|
||||||
- name: Test incremental migration
|
# - name: Test incremental migration
|
||||||
run: |
|
# run: |
|
||||||
sleep 10
|
# sleep 10
|
||||||
docker run --rm --network host -e DATABASE_USER=vdbm -e DATABASE_PASSWORD=password \
|
# docker run --rm --network host -e DATABASE_USER=vdbm -e DATABASE_PASSWORD=password \
|
||||||
-e DATABASE_HOSTNAME=127.0.0.1 -e DATABASE_PORT=8066 -e DATABASE_NAME=vulcanize_testing \
|
# -e DATABASE_HOSTNAME=127.0.0.1 -e DATABASE_PORT=8066 -e DATABASE_NAME=vulcanize_testing \
|
||||||
vulcanize/statediff-migrations:v0.9.0
|
# vulcanize/statediff-migrations:v0.9.0
|
||||||
- name: Verify schema is latest
|
# - name: Verify schema is latest
|
||||||
run: |
|
# run: |
|
||||||
PGPASSWORD="password" pg_dump -h localhost -p 8066 -U vdbm vulcanize_testing --no-owner --schema-only > ./db/migration_schema.sql
|
# PGPASSWORD="password" pg_dump -h localhost -p 8066 -U vdbm vulcanize_testing --no-owner --schema-only > ./db/migration_schema.sql
|
||||||
./scripts/check_diff.sh db/schema.sql ./db/migration_schema.sql
|
# ./scripts/check_diff.sh db/schema.sql ./db/migration_schema.sql
|
||||||
|
|
||||||
migration:
|
# migration:
|
||||||
name: Compare up and down migration
|
# name: Compare up and down migration
|
||||||
env:
|
# env:
|
||||||
GOPATH: /tmp/go
|
# GOPATH: /tmp/go
|
||||||
strategy:
|
# strategy:
|
||||||
matrix:
|
# matrix:
|
||||||
go-version: [ 1.16.x ]
|
# go-version: [ 1.16.x ]
|
||||||
os: [ ubuntu-latest ]
|
# os: [ ubuntu-latest ]
|
||||||
runs-on: ${{ matrix.os }}
|
# runs-on: ${{ matrix.os }}
|
||||||
steps:
|
# steps:
|
||||||
- name: Create GOPATH
|
# - name: Create GOPATH
|
||||||
run: mkdir -p /tmp/go
|
# run: mkdir -p /tmp/go
|
||||||
- name: Install Go
|
# - name: Install Go
|
||||||
uses: actions/setup-go@v2
|
# uses: actions/setup-go@v2
|
||||||
with:
|
# with:
|
||||||
go-version: ${{ matrix.go-version }}
|
# go-version: ${{ matrix.go-version }}
|
||||||
- uses: actions/checkout@v2
|
# - uses: actions/checkout@v2
|
||||||
- name: Test migration
|
# - name: Test migration
|
||||||
run: |
|
# run: |
|
||||||
timeout 5m make test-migrations
|
# timeout 5m make test-migrations
|
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):
|
* Spin up an access node and three data nodes using [docker-compose.test.yml](./docker-compose.test.yml):
|
||||||
|
|
||||||
```bash
|
```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:
|
Following final output should be seen on all the nodes:
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
-- +goose NO TRANSACTION
|
-- +goose NO TRANSACTION
|
||||||
-- +goose Up
|
-- +goose Up
|
||||||
-- this is generated by a script
|
-- 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('dn3', host => '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('dn2', host => '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('dn1', host => 'data-node-1', port => 5432, database => 'vulcanize_testing_v4', password => 'password');
|
||||||
|
|
||||||
CALL distributed_exec($$ CREATE SCHEMA eth $$);
|
CALL distributed_exec($$ CREATE SCHEMA eth $$);
|
||||||
|
|
||||||
|
@ -1,26 +1,14 @@
|
|||||||
version: '3.2'
|
version: '3.2'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
statediff-migrations:
|
access-node:
|
||||||
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
|
|
||||||
image: timescale/timescaledb:latest-pg14
|
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"]
|
command: ["postgres", "-c", "log_statement=all"]
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_USER: "postgres"
|
POSTGRES_USER: "postgres"
|
||||||
@ -31,10 +19,10 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./scripts/init-access-node.sh:/docker-entrypoint-initdb.d/init-access-node.sh
|
- ./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
|
image: timescale/timescaledb:latest-pg14
|
||||||
container_name: pg_data_node_1
|
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
container_name: data-node-1
|
||||||
command: ["postgres", "-c", "log_statement=all"]
|
command: ["postgres", "-c", "log_statement=all"]
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_USER: "postgres"
|
POSTGRES_USER: "postgres"
|
||||||
@ -45,10 +33,10 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./scripts/init-data-node.sh:/docker-entrypoint-initdb.d/init-data-node.sh
|
- ./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
|
image: timescale/timescaledb:latest-pg14
|
||||||
container_name: pg_data_node_2
|
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
container_name: data-node-2
|
||||||
command: ["postgres", "-c", "log_statement=all"]
|
command: ["postgres", "-c", "log_statement=all"]
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_USER: "postgres"
|
POSTGRES_USER: "postgres"
|
||||||
@ -59,10 +47,10 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./scripts/init-data-node.sh:/docker-entrypoint-initdb.d/init-data-node.sh
|
- ./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
|
image: timescale/timescaledb:latest-pg14
|
||||||
container_name: pg_data_node_3
|
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
container_name: data-node-3
|
||||||
command: ["postgres", "-c", "log_statement=all"]
|
command: ["postgres", "-c", "log_statement=all"]
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_USER: "postgres"
|
POSTGRES_USER: "postgres"
|
||||||
|
@ -7,6 +7,7 @@ VDB_PG_CONNECT=postgresql://$DATABASE_USER:$DATABASE_PASSWORD@$DATABASE_HOSTNAME
|
|||||||
|
|
||||||
# Run the DB migrations
|
# Run the DB migrations
|
||||||
echo "Connecting with: $VDB_PG_CONNECT"
|
echo "Connecting with: $VDB_PG_CONNECT"
|
||||||
|
sleep 15
|
||||||
echo "Running database migrations"
|
echo "Running database migrations"
|
||||||
./goose -dir migrations/vulcanizedb postgres "$VDB_PG_CONNECT" up-to 21
|
./goose -dir migrations/vulcanizedb postgres "$VDB_PG_CONNECT" up-to 21
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user