Skip to content

Commit

Permalink
chore(docker): fix env params for JDBC
Browse files Browse the repository at this point in the history
  • Loading branch information
mborne committed Dec 2, 2024
1 parent 1457dfa commit 3b7c240
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 39 deletions.
23 changes: 2 additions & 21 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -101,27 +101,8 @@ VOLUME /opt/validator-api/var/data

USER www-data

ENV APP_ENV=prod

EXPOSE 8000
CMD ["/opt/validator-api/.docker/application.sh"]

#----------------------------------------------------------------------
# DEV image with xdebug
#----------------------------------------------------------------------
FROM base AS dev

ENV APP_ENV=dev

USER root
# install xdebug extension for php
RUN pear config-set http_proxy ${http_proxy} \
&& pear config-set php_ini $PHP_INI_DIR/php.ini \
&& pecl install xdebug \
&& docker-php-ext-enable xdebug
USER www-data

#----------------------------------------------------------------------
# Production image without xdebug
#----------------------------------------------------------------------
FROM base AS prod

ENV APP_ENV=prod
2 changes: 1 addition & 1 deletion .docker/application.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ backend(){

test(){
export APP_ENV=test
export DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@database:5432/validator_api_test?serverVersion=13&charset=utf8"
export DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@database:5432/validator_api_test?serverVersion=15&charset=utf8"
bin/console --env=test doctrine:database:create --if-not-exists
bin/console --env=test doctrine:schema:update --complete --force
XDEBUG_MODE=coverage vendor/bin/phpunit
Expand Down
5 changes: 3 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ CORS_ALLOW_ORIGIN=*
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://db_user:[email protected]:3306/validator-api?serverVersion=5.7"
DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/validator_api?serverVersion=13&charset=utf8
DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/validator_api?serverVersion=15&charset=utf8
###< doctrine/doctrine-bundle ###

###> league/flysystem
Expand All @@ -55,7 +55,8 @@ S3_BUCKET=dev-ign-mut-validtri
S3_REGION=sbg

### validator-worker/validator-cli postgis
DB_URL=jdbc:postgresql:${PGDATABASE}
# DB_URL=jdbc:postgresql://${PGHOST}:${PGPORT}/${PGDATABASE}?ssl=true&sslmode=require&sslfactory=org.postgresql.ssl.NonValidatingFactory
DB_URL=jdbc:postgresql://localhost:5432/validator_api
DB_USER=${POSTGRES_USER}
DB_PASSWORD=${POSTGRES_PASSWORD}
# must stay empty
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/php-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ jobs:

strategy:
matrix:
php-version: [7.4,8.1]
php-version: [8.3]

runs-on: ubuntu-latest

# see https://docs.github.com/en/actions/using-containerized-services/creating-postgresql-service-containers
services:
postgres:
image: postgres:14
image: postgres:15
env:
POSTGRES_PASSWORD: postgres
options: >-
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/validator_api?serverVersion=14&charset=utf8

- name: Upload coverage results to coveralls.io
if: github.ref == 'refs/heads/master' && matrix.php-version == '8.1'
if: github.ref == 'refs/heads/master' && matrix.php-version == '8.3'
run: |
vendor/bin/php-coveralls --coverage_clover=var/data/output/coverage.xml --json_path=var/data/output/coveralls.json -v
env:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ sonar-scanner
node_modules

/output/
# vscode
*.bkp

###> friendsofphp/php-cs-fixer ###
/.php-cs-fixer.php
Expand Down
23 changes: 15 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ services:
build:
context: .
dockerfile: .docker/Dockerfile
target: dev
args:
- http_proxy
- https_proxy
Expand All @@ -19,9 +18,9 @@ services:
- APP_ENV=${APP_ENV}
- DB_CREATE=1
- DB_UPGRADE=1
- POSTGRES_USER=validator
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@database:5432/validator_api?serverVersion=13&charset=utf8
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@database:5432/validator_api?serverVersion=15&charset=utf8
- S3_ENDPOINT=${S3_ENDPOINT}
- S3_ACCESS_KEY=${S3_ACCESS_KEY}
- S3_SECRET_KEY=${S3_SECRET_KEY}
Expand All @@ -42,14 +41,14 @@ services:
restart: unless-stopped

database:
image: postgres:13
image: postgis/postgis:13-3.5-alpine
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
ports:
- 5432:5432
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
test: ["CMD-SHELL", "pg_isready -U validator"]
interval: 10s
timeout: 5s
retries: 5
Expand All @@ -62,7 +61,7 @@ services:
#-----------------------------------------------------------------------
# Process validations
#-----------------------------------------------------------------------
backend:
worker:
image: ignf/validator-api:master-dev
command: [".docker/application.sh","backend"]
environment:
Expand All @@ -74,7 +73,15 @@ services:
- APP_ENV=${APP_ENV}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@database:5432/validator_api?serverVersion=13&charset=utf8
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@database:5432/validator_api?serverVersion=15&charset=utf8
- S3_ENDPOINT=${S3_ENDPOINT}
- S3_ACCESS_KEY=${S3_ACCESS_KEY}
- S3_SECRET_KEY=${S3_SECRET_KEY}
- S3_BUCKET=${S3_BUCKET}
# validator-cli.jar only
- DB_URL=jdbc:postgresql://database:5432/validator_api
- DB_USER=${POSTGRES_USER}
- DB_PASSWORD=${POSTGRES_PASSWORD}
networks:
- validator
volumes:
Expand All @@ -90,4 +97,4 @@ volumes:
# validations files
api-data:
# postgresql files (docker volume create db-data)
db-data:
db-data:
2 changes: 1 addition & 1 deletion docs/developer-guide/php-classic.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ L'application est consultable à l'adresse http://localhost:8000
Dans `.env.test`, ajoutez la ligne suivante :

```
DATABASE_URL=postgresql://${PGUSER}:${PGPASSWORD}@localhost:5432/validator_api_test?serverVersion=13&charset=utf8
DATABASE_URL=postgresql://${PGUSER}:${PGPASSWORD}@localhost:5432/validator_api_test?serverVersion=15&charset=utf8
```

> [Comment configurer la variable DATABASE_URL (documentation Symfony)](https://symfony.com/doc/4.4/doctrine.html#configuring-the-database)
Expand Down
Binary file modified docs/img/architecture-logique.drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<!-- -->
<!-- DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db" -->
<!-- DATABASE_URL="mysql://db_user:[email protected]:3306/db_name?serverVersion=5.7" -->
<!-- <env name="DATABASE_URL" value="postgresql://db_user:[email protected]:5432/db_name?serverVersion=13&amp;charset=utf8"/> -->
<!-- <env name="DATABASE_URL" value="postgresql://db_user:[email protected]:5432/db_name?serverVersion=15&amp;charset=utf8"/> -->
<!-- ###- doctrine/doctrine-bundle ### -->
<!-- ###+ nelmio/cors-bundle ### -->
<env name="CORS_ALLOW_ORIGIN" value="'^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'"/>
Expand Down
8 changes: 6 additions & 2 deletions src/Validation/ValidatorCLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,13 @@ public function process(Validation $validation)

/* prepare validator-cli.jar command */
$env = $_ENV;
$env['DB_SCHEMA'] = "validation" . $validation->getUid();
$env['GMLAS_CONFIG'] = $this->gmlasConfigPath;

/*
* specify validation schema
* TODO : compute DB_URL=jdbc:postgresql:${PGDATABASE}, DB_USER et DB_PASSWORD according to doctrine?
*/
$env['DB_SCHEMA'] = "validation" . $validation->getUid();

$sourceDataDir = $validationDirectory.'/'.$validation->getDatasetName();
$cmd = ['java'];
$cmd = \array_merge($cmd, explode(' ',$this->validatorJavaOpts));
Expand Down

0 comments on commit 3b7c240

Please sign in to comment.