Skip to content

Commit

Permalink
add configurator database
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Oct 30, 2024
1 parent ce359b0 commit 1bcfb03
Show file tree
Hide file tree
Showing 18 changed files with 4,037 additions and 1,462 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ MARIADB_PORT=3306
MAILER_DSN=smtp://mailhog:1025
MAIL_FROM=noreply@${PHRASEA_DOMAIN}

# Configurator
CONFIGURATOR_DB_NAME=configurator

# Mailhog
MAILHOG_PORT=8125

Expand Down
6 changes: 5 additions & 1 deletion bin/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function load-env {
rm -f "${tmp}"
}

# execute a shell commmand in a container defined in docker-compose.yml
# execute a shell command in a container defined in docker-compose.yml
function exec_container() {
docker compose exec -T "$1" sh -c "$2"
}
Expand All @@ -48,6 +48,10 @@ function exec_container_as() {
docker compose exec -T "$1" su "$3" sh -c "$2"
}

function run_container_as() {
docker compose run --rm -T "$1" su "$3" sh -c "$2"
}

function create_db() {
exec_container db "psql -U \"${POSTGRES_USER}\" -tc \"SELECT 1 FROM pg_database WHERE datname = '$1'\" | grep -q 1 || psql -U \"${POSTGRES_USER}\" -c \"CREATE DATABASE $1\""
}
15 changes: 8 additions & 7 deletions bin/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ docker compose up -d
# Wait for services to be ready
docker compose run --rm dockerize

# Setup Report
## Create DB
create_db "${REPORT_DB_NAME}"
create_db "${KEYCLOAK_DB_NAME}"
create_db "${KEYCLOAK2_DB_NAME}"

run_container_as configurator "bin/setup.sh" app

# Setup Uploader
## Create rabbitmq vhost
exec_container rabbitmq "rabbitmqctl add_vhost ${UPLOADER_RABBITMQ_VHOST} && rabbitmqctl set_permissions -p ${UPLOADER_RABBITMQ_VHOST} ${RABBITMQ_USER} '.*' '.*' '.*'"
Expand Down Expand Up @@ -72,13 +80,6 @@ COMPOSE_PROFILES="${COMPOSE_PROFILES},setup" docker compose run --rm -T --entryp
## Create Uploader target for client upload
exec_container uploader-api-php "bin/console app:create-target ${DATABOX_UPLOADER_TARGET_SLUG} 'Databox Uploader' http://databox-api/incoming-uploads"

# Setup Report
## Create DB
create_db "${REPORT_DB_NAME}"

create_db "${KEYCLOAK_DB_NAME}"
create_db "${KEYCLOAK2_DB_NAME}"

## Setup indexer
## Create Databox OAuth client for indexer
COMPOSE_PROFILES="${COMPOSE_PROFILES},setup" docker compose run --rm -T --entrypoint "sh -c" minio-mc "\
Expand Down
16 changes: 9 additions & 7 deletions configurator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ ARG BASE_TAG=latest
ARG REGISTRY_NAMESPACE
FROM ${REGISTRY_NAMESPACE}php-fpm-base:${BASE_TAG} AS api-php

WORKDIR /usr/app
WORKDIR /srv/app

ENV APP_ENV=prod
COPY --chown=app:app . .

COPY . .

RUN composer install --prefer-dist --no-dev --no-progress --classmap-authoritative --no-interaction \
RUN mkdir -p var/cache var/logs var/sessions \
&& composer install --prefer-dist --no-dev --no-progress --classmap-authoritative --no-interaction \
&& composer clear-cache \
&& chown -R app: .

ENTRYPOINT ["bin/console"]
ARG SENTRY_RELEASE
ENV SENTRY_RELEASE=${SENTRY_RELEASE}

ENTRYPOINT ["/srv/app/docker/php-entrypoint.sh"]

CMD ["configure"]
CMD ["bin/console", "configure"]
14 changes: 14 additions & 0 deletions configurator/bin/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

set -e

BASEDIR=$(dirname $0)

if [ ! -d "${BASEDIR}/../vendor" ]; then
(cd "${BASEDIR}/.." && composer install)
fi

"${BASEDIR}/console" doctrine:database:create --if-not-exists
"${BASEDIR}/console" doctrine:schema:update -f
"${BASEDIR}/console" doctrine:migrations:sync-metadata-storage
"${BASEDIR}/console" doctrine:migrations:version --add --all -n
4 changes: 3 additions & 1 deletion configurator/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"php": ">=8.3",
"ext-ctype": "*",
"ext-iconv": "*",
"doctrine/doctrine-bundle": "*",
"doctrine/doctrine-bundle": "^2.12",
"doctrine/doctrine-migrations-bundle": "^3.3",
"doctrine/orm": "^3.3",
"symfony/console": "6.3.*",
"symfony/dotenv": "6.3.*",
"symfony/flex": "^2",
Expand Down
Loading

0 comments on commit 1bcfb03

Please sign in to comment.