From a8d3c80914177ee41c189af50080fb99f7fd0ee6 Mon Sep 17 00:00:00 2001 From: Giovanni Gargiulo Date: Wed, 7 Feb 2024 12:01:56 +0000 Subject: [PATCH] chore: refactored the docker compose stack (#9) --- .env | 25 ++++++------- api/compose.dockerfile | 16 ++++++++ docker-compose-simple.yml | 16 -------- docker-compose.yml | 77 ++++++++------------------------------- 4 files changed, 42 insertions(+), 92 deletions(-) create mode 100644 api/compose.dockerfile delete mode 100644 docker-compose-simple.yml diff --git a/.env b/.env index 189a5f5..c83b99c 100644 --- a/.env +++ b/.env @@ -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" \ No newline at end of file +API_LOCAL_BIND_PORT='18080' + +# Whether the github scheduled job should run on the api or not +TOKEN_METADATA_SYNC_JOB='true' diff --git a/api/compose.dockerfile b/api/compose.dockerfile new file mode 100644 index 0000000..1dd2ef9 --- /dev/null +++ b/api/compose.dockerfile @@ -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"] diff --git a/docker-compose-simple.yml b/docker-compose-simple.yml deleted file mode 100644 index 2e99f8e..0000000 --- a/docker-compose-simple.yml +++ /dev/null @@ -1,16 +0,0 @@ -version: "3.9" -services: - db: - image: "${DB_IMAGE_NAME}:${DB_IMAGE_TAG}" - ports: - - "${DB_PORT}:${DB_PORT}" - environment: - POSTGRES_PASSWORD: "${DB_USER_SECRET}" - volumes: - - ./database/scripts/bootstrap_db.sql:/docker-entrypoint-initdb.d/bootstrap_db.sql - healthcheck: - test: ["CMD-SHELL", "pg_isready -U ${DB_USER_NAME}"] - interval: 5s - timeout: 5s - retries: 10 - restart: on-failure \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 950b53b..9a91932 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 \ No newline at end of file + db: + condition: service_healthy + restart: always \ No newline at end of file