From 3d82a411e0e91afef38ee9739898f23137eacbe8 Mon Sep 17 00:00:00 2001 From: herve0742 Date: Tue, 17 Jan 2023 18:50:27 +0100 Subject: [PATCH] docker: Set up a configuration for development --- compose.yaml | 20 ++++++++++++++++ docker/dev/DockerFile | 19 +++++++++++++++ docker/dev/entrypoint.sh | 20 ++++++++++++++++ docker/dev/env.local | 52 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 compose.yaml create mode 100644 docker/dev/DockerFile create mode 100755 docker/dev/entrypoint.sh create mode 100644 docker/dev/env.local diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..c85ad80 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,20 @@ +services: + date-backend: + build: + dockerfile: ./docker/dev/DockerFile + context: . + volumes: + - './:/var/www/html/date-poll-api' + ports: + - "8000:8000" + + date-db: + image: mysql:5.7 + environment: + - MYSQL_ROOT_PASSWORD=fdsqlrootpassword + - MYSQL_USER=fdsqluser + - MYSQL_PASSWORD=fdsqlpassword + - MYSQL_DATABASE=framadate_api + restart: always + ports: + - "3307:3306" diff --git a/docker/dev/DockerFile b/docker/dev/DockerFile new file mode 100644 index 0000000..c953cb9 --- /dev/null +++ b/docker/dev/DockerFile @@ -0,0 +1,19 @@ +FROM php:8.1.14 + +RUN curl -1sLf 'https://dl.cloudsmith.io/public/symfony/stable/setup.deb.sh' | bash && \ + apt-get -y update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y -qq unzip libicu-dev symfony-cli && \ + php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \ + php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \ + php composer-setup.php --install-dir=/usr/bin --filename="composer" &&\ + php -r "unlink('composer-setup.php');" + +RUN docker-php-ext-install pdo_mysql + +COPY docker/dev/entrypoint.sh /usr/local/bin/entrypoint + +WORKDIR /var/www/html/date-poll-api + +EXPOSE 8000 + +ENTRYPOINT ["entrypoint"] diff --git a/docker/dev/entrypoint.sh b/docker/dev/entrypoint.sh new file mode 100755 index 0000000..049aced --- /dev/null +++ b/docker/dev/entrypoint.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Set configuration +cp docker/dev/env.local ./.env.local + +# composer +composer install + +# Await MySQL Container being ready +until php bin/console doctrine:query:sql "SELECT 1;" ; do + >&2 echo "MySQL is unavailable - sleeping" + sleep 1 +done +# Run Database migrations +php bin/console doctrine:schema:drop --force +php bin/console doctrine:schema:create +php bin/console doctrine:fixtures:load --no-interaction + +# Run server +symfony serve diff --git a/docker/dev/env.local b/docker/dev/env.local new file mode 100644 index 0000000..992e7ff --- /dev/null +++ b/docker/dev/env.local @@ -0,0 +1,52 @@ +# In all environments, the following files are loaded if they exist, +# the latter taking precedence over the former: +# +# * .env contains default values for the environment variables needed by the app +# * .env.local uncommitted file with local overrides +# * .env.$APP_ENV committed environment-specific defaults +# * .env.$APP_ENV.local uncommitted environment-specific overrides +# +# Real environment variables win over .env files. +# +# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES. +# +# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2). +# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration + +###> symfony/framework-bundle ### +APP_ENV=dev +ADMIN_TOKEN=admintok +APP_SECRET=appsecret +# Base website url, should contain https:// and having no trailing slash. example: BASE_URL=https://framadate.org +BASE_URL=http://localhost +WEBSITE_NAME=Framadate_2 +WEBSITE_LOGO=logo.ico +#TRUSTED_PROXIES=127.0.0.1,127.0.0.2 +#TRUSTED_HOSTS='^localhost|example\.com$' +###< symfony/framework-bundle ### + +###> doctrine/doctrine-bundle ### +# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url +# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db" +# For a PostgreSQL database, use: "postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=11" +# IMPORTANT: You MUST also configure your db driver and server_version in config/packages/doctrine.yaml +DATABASE_URL=mysql://fdsqluser:fdsqlpassword@date-db:3306/framadate_api +###< doctrine/doctrine-bundle ### +###> symfony/swiftmailer-bundle ### +# For Gmail as a transport, use: "gmail://username:password@localhost" +# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode=" +# Delivery is disabled by default via "null://localhost" +#MAILER_URL=sendmail://YOUR_WEBSITE +MAILER_URL=null://localhost +# set the support email who will answer users in case of emergency +SUPPORT_EMAIL=support-framadate@YOUR_WEBSITE +SPOOL_PATH=/var/www/html/date-poll-api/var/email/spool +###< symfony/swiftmailer-bundle ### + +###> nelmio/cors-bundle ### +CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$' +###< nelmio/cors-bundle ### + +###> symfony/mailer ### +# MAILER_DSN=smtp://localhost +###< symfony/mailer ###