Skip to content

Commit

Permalink
Merge pull request #23 from MinaFoundation/db-migration-in-docker
Browse files Browse the repository at this point in the history
PM-539 - Add database migration capability to docker image
  • Loading branch information
piotr-iohk authored Nov 17, 2023
2 parents eeed691 + 8667df0 commit ac50838
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
38 changes: 36 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,46 @@ If the `CONFIG_FILE` environment variable is not set, the program will fall back

- Only one of `AwsS3`, `AwsKeyspaces`, or `LocalFileSystem` configurations should be provided. If more than one is provided, the program will terminate with an error.
- Ensure that all necessary environment variables are set. If any required variable is missing, the program will terminate with an error.
- Using `AWSKeyspaces` for the first time requires running database migration script in order to create necessary tables. After `AWSKeyspaces` is properly set on the environment, one can run database migration using the provided script:

### Database Migration

When using `AWSKeyspaces` as storage for the first time one needs to run database migration script in order to create necessary tables. After `AWSKeyspaces` config is properly set on the environment, one can run database migration using the provided script:

```bash
$ nix-shell
[nix-shell]$ make db-migrate-up
# To migrate database up
[nix-shell]$ make db-migrate-up

# To migrate database down
[nix-shell]$ make db-migrate-down
```

Migration is also possible from dockerfile using non-default entrypoint `db_migration` for instance:

```bash
# To migrate database up
docker run \
-e AWS_KEYSPACE=keyspace_name \
-e AWS_REGION=us-west-2 \
-e AWS_ACCESS_KEY_ID=*** \
-e AWS_SECRET_ACCESS_KEY=*** \
-e DELEGATION_WHITELIST_DISABLED=1 \
-e CONFIG_NETWORK_NAME=integration-test \
--entrypoint db_migration \
673156464838.dkr.ecr.us-west-2.amazonaws.com/block-producers-uptime:$TAG up

# To migrate database down
docker run \
-e AWS_KEYSPACE=keyspace_name \
-e AWS_REGION=us-west-2 \
-e AWS_ACCESS_KEY_ID=*** \
-e AWS_SECRET_ACCESS_KEY=*** \
-e DELEGATION_WHITELIST_DISABLED=1 \
-e CONFIG_NETWORK_NAME=integration-test \
--entrypoint db_migration \
673156464838.dkr.ecr.us-west-2.amazonaws.com/block-producers-uptime:$TAG down
```
> **Note:** Docker image already includes cert and has `AWS_SSL_CERTIFICATE_PATH` set up, however it can be overriden by providing this env variable to docker.
Once you have set up your configuration using either a JSON file or environment variables, you can proceed to run the program. The program will automatically load the configuration and initialize based on the provided settings.

Expand Down
2 changes: 2 additions & 0 deletions dockerfiles/Dockerfile-delegation-backend
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ WORKDIR $GOPATH/src/delegation_backend

# Copy everything from the current directory to the PWD (Present Working Directory) inside the container
COPY src src
COPY database /database
COPY result/headers result/headers

# Download all the dependencies
RUN cd src && go get -d -v ./...

COPY result/libmina_signer.so result/libmina_signer.so
ENV LD_LIBRARY_PATH="result:$LD_LIBRARY_PATH"
ENV AWS_SSL_CERTIFICATE_PATH="/database/cert/sf-class2-root.crt"

# Install the package
RUN cd src && go install -v ./...
Expand Down
2 changes: 1 addition & 1 deletion src/integration_tests/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
UPTIME_SERVICE_CONFIG_DIR = TEST_DATA_FOLDER + "/topology/uptime_service_config"
APP_CONFIG_FILE = UPTIME_SERVICE_CONFIG_DIR + "/app_config.json"

TIMEOUT_IN_S = 600
TIMEOUT_IN_S = 900

// AWS Keyspaces
DATABASE_MIGRATION_DIR = "../../database/migrations"
Expand Down
2 changes: 1 addition & 1 deletion test/integration/topology/genesis_ledger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"genesis": {
"k": 20,
"delta": 0,
"slots_per_epoch": 480,
"slots_per_epoch": 240,
"slots_per_sub_window": 2,
"genesis_state_timestamp": "2023-10-16 12:00:03.092497Z"
},
Expand Down

0 comments on commit ac50838

Please sign in to comment.