Skip to content

Commit

Permalink
chore: refactored the docker compose stack (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
nemo83 authored Feb 7, 2024
1 parent 161d4e6 commit a8d3c80
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 92 deletions.
25 changes: 11 additions & 14 deletions .env
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
DB_USER_SECRET="metadata1337_"
SERVICE_USER_NAME="metadataservice"
SERVICE_USER_SECRET="metadata1337_"
METADATA_DB_NAME="cf_metadata"
DB_IMAGE_NAME="postgres"
DB_IMAGE_TAG="latest"
# DB Details
POSTGRES_PASSWORD="metadata1337_"
DB_USERNAME="cardano"
DB_PASSWORD="metadata1337_"
DB_NAME="cf_token_metadata_registry"
DB_HOST='db'
DB_PORT='5432'

# API Details
API_EXPOSED_PORT='8080'
API_LOCAL_BIND_PORT='8081'
DB_DRIVER_CLASS_NAME="org.postgresql.Driver"
TOKEN_REGISTRY_REPOSITORY_URL="https://github.com/cardano-foundation/cardano-token-registry.git"
TOKEN_REGISTRY_BRANCH_NAME="master"
MAPPINGS_FOLDER="mappings"
TESTNET_TOKEN_REGISTRY_REPOSITORY_URL="https://github.com/input-output-hk/metadata-registry-testnet.git"
TESTNET_TOKEN_REGISTRY_BRANCH_NAME="master"
TESTNET_MAPPINGS_FOLDER="registry"
API_LOCAL_BIND_PORT='18080'

# Whether the github scheduled job should run on the api or not
TOKEN_METADATA_SYNC_JOB='true'
16 changes: 16 additions & 0 deletions api/compose.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Dockerfile used in compose to build and run project.
FROM openjdk:18-jdk-slim as builder

RUN apt update && apt install -y maven && apt clean

ADD . /app
WORKDIR /app
RUN mvn clean package

FROM openjdk:18-jdk-slim

RUN apt update && apt install -y git && apt clean

COPY --from=builder /app/api/target/*.jar /app/app.jar
WORKDIR /app
ENTRYPOINT ["java", "-jar", "app.jar"]
16 changes: 0 additions & 16 deletions docker-compose-simple.yml

This file was deleted.

77 changes: 15 additions & 62 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,78 +1,31 @@
version: "3.9"
services:
db:
image: "${DB_IMAGE_NAME}:${DB_IMAGE_TAG}"
image: postgres:15
ports:
- "${DB_PORT}:${DB_PORT}"
environment:
POSTGRES_USER: "${DB_USER_NAME}"
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
volumes:
- ./database/scripts/bootstrap_db.sql:/docker-entrypoint-initdb.d/bootstrap_db.sql
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USER_NAME}"]
test: ["CMD-SHELL", "pg_isready -U ${DB_USERNAME}"]
interval: 5s
timeout: 5s
retries: 10
restart: on-failure
bootstrap-db:
build: ./database
environment:
DBA_USER_NAME: "${DB_USER_NAME}"
SERVICE_USER_SECRET: "${SERVICE_USER_SECRET}"
SERVICE_USER_NAME: "${SERVICE_USER_NAME}"
DB_HOST: "${DB_HOST}"
DB_PORT: ${DB_PORT}
METADATA_DB_NAME: ${METADATA_DB_NAME}
TOKEN_REGISTRY_REPOSITORY_URL: "https://github.com/cardano-foundation/cardano-token-registry.git"
MAPPINGS_FOLDER: "mappings"
depends_on:
db:
condition: service_healthy
sync-db-once:
build:
context: ./gitsync
dockerfile: Dockerfile.sync-once
environment:
DB_URL: "db:${DB_PORT}/${METADATA_DB_NAME}"
DB_USER_NAME: "${DB_USER_NAME}"
TOKEN_REGISTRY_REPOSITORY_URL: "${TOKEN_REGISTRY_REPOSITORY_URL}"
TOKEN_REGISTRY_BRANCH_NAME: "${TOKEN_REGISTRY_BRANCH_NAME}"
MAPPINGS_FOLDER: "${MAPPINGS_FOLDER}"
TESTNET_TOKEN_REGISTRY_REPOSITORY_URL: "${TESTNET_TOKEN_REGISTRY_REPOSITORY_URL}"
TESTNET_TOKEN_REGISTRY_BRANCH_NAME: "${TESTNET_TOKEN_REGISTRY_BRANCH_NAME}"
TESTNET_MAPPINGS_FOLDER: "${TESTNET_MAPPINGS_FOLDER}"
depends_on:
bootstrap-db:
condition: service_completed_successfully
sync-db-cron:
build:
context: ./gitsync
dockerfile: Dockerfile.sync-cron
args:
DB_URL: "db:${DB_PORT}/${METADATA_DB_NAME}"
DB_USER_NAME: "${DB_USER_NAME}"
TOKEN_REGISTRY_REPOSITORY_URL: "${TOKEN_REGISTRY_REPOSITORY_URL}"
TOKEN_REGISTRY_BRANCH_NAME: "${TOKEN_REGISTRY_BRANCH_NAME}"
MAPPINGS_FOLDER: "${MAPPINGS_FOLDER}"
TESTNET_TOKEN_REGISTRY_REPOSITORY_URL: "${TESTNET_TOKEN_REGISTRY_REPOSITORY_URL}"
TESTNET_TOKEN_REGISTRY_BRANCH_NAME: "${TESTNET_TOKEN_REGISTRY_BRANCH_NAME}"
TESTNET_MAPPINGS_FOLDER: "${TESTNET_MAPPINGS_FOLDER}"
depends_on:
sync-db-once:
condition: service_completed_successfully
api:
build: ./api
platform: linux/arm64
build:
context: .
dockerfile: api/compose.dockerfile
ports:
- "${API_LOCAL_BIND_PORT}:${API_EXPOSED_PORT}"
environment:
DB_URL: "jdbc:postgresql://db:${DB_PORT}/${METADATA_DB_NAME}"
DB_USER: "${SERVICE_USER_NAME}"
DB_SECRET: "${SERVICE_USER_SECRET}"
DB_DRIVER_CLASS_NAME: "${DB_DRIVER_CLASS_NAME}"
DB_URL: "jdbc:postgresql://db:${DB_PORT}/${DB_NAME}"
DB_USERNAME: "${DB_USERNAME}"
DB_PASSWORD: "${DB_PASSWORD}"
TOKEN_METADATA_SYNC_JOB: "${TOKEN_METADATA_SYNC_JOB}"
depends_on:
bootstrap-db:
condition: service_completed_successfully
restart: always

networks:
default:
name: offchain-registry
db:
condition: service_healthy
restart: always

0 comments on commit a8d3c80

Please sign in to comment.