Skip to content

Template docker #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
be226a3
fix: add full stack docker and make file for using in Dockerfile
TheoMeunier May 17, 2023
ede3d9d
feat: add docker compose for dev
TheoMeunier May 17, 2023
7a4c367
fix: clear code
TheoMeunier May 17, 2023
c26c5f5
fix: connection db in prod
TheoMeunier May 19, 2023
36dae39
fix: configuration proxy reverse
TheoMeunier May 19, 2023
613a31d
fix: navigation README.md
TheoMeunier May 19, 2023
b65df41
feat: add documentation for installation with docker
TheoMeunier May 19, 2023
130ac26
feat: task installation with docker
TheoMeunier May 19, 2023
67ae843
fix: clear .env
TheoMeunier May 22, 2023
32e9752
fix: clear conf nginx
TheoMeunier May 22, 2023
ef9ec3a
fix: clear dependencies dockerfile
TheoMeunier May 22, 2023
ec93f23
fix: remove service php and nginx in dev. Add docker-compose.prod.yaml
TheoMeunier May 22, 2023
5191a77
fix: clear .gitignore
TheoMeunier Aug 20, 2023
b0145b7
fix: add versioning file .env
TheoMeunier Aug 20, 2023
f6ee842
fix: deleting makefile for create PR
TheoMeunier Aug 20, 2023
a264bd3
fix: timezone for local.ini
TheoMeunier Aug 20, 2023
bc1209f
dix: delete nodejs in dockerfile
TheoMeunier Aug 20, 2023
1688e43
fix: delete nodejs in dockerfile
TheoMeunier Aug 20, 2023
6b1b537
migration: php8.1 to php8.2
TheoMeunier Aug 20, 2023
c88dd17
fix: cleat conf nginx
TheoMeunier Aug 20, 2023
7f97fd5
fix: using docker for prod and not default
TheoMeunier Aug 20, 2023
1f94792
Merge branch 'bastien70:main' into main
TheoMeunier Dec 30, 2023
8fbb7e1
fix: implementation docker using dbsaber in prod
TheoMeunier Dec 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,26 @@

###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=ed57093ff0c0f5c74d15b176f96d1e66
APP_SLUG=dbsaver
DEFAULT_LOCALE=fr
APP_SECRET=
TRUSTED_PROXIES=172.16.0.0/12,10.0.0.0/8
###< symfony/framework-bundle ###

###> symfony/mailer ###
# MAILER_DSN=null://null
MAILER_DSN=smtp://null:@null
MAILER_SENDER=
###< symfony/mailer ###

###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
#DATABASE_URL="sqlite:///%kernel.project_dir%/var/dbsaver.db"
DATABASE_URL="mysql://root:root@127.0.0.1:3306/dbsaver?serverVersion=5.7"
#DATABASE_URL="postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=13&charset=utf8"
DB_CONNECTION=pdo_mysql
DB_HOST=${APP_SLUG}_database
DB_PORT=3306
DB_DATABASE=dbsaver
DB_USERNAME=dbsaver
DB_PASSWORD=root
DB_ROOT_PASSWORD=root
###< doctrine/doctrine-bundle ###

DEFAULT_LOCALE=en
MAILER_SENDER=
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

###> symfony/framework-bundle ###
/.env.local
/.env.local.php
Expand All @@ -20,6 +19,7 @@
/.php-cs-fixer.cache
###< friendsofphp/php-cs-fixer ###

storage-db
/.task
/public/coverage
/public/files/backups
15 changes: 15 additions & 0 deletions README.md
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a "Docker installation guide" :)

Copy link
Author

@TheoMeunier TheoMeunier May 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect I will make a doc to see explain the installation of docker on debian and ubuntu.
What format did you want the guide in?
in the README.md

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure, I'm talking about the installation via docker of the application and not the installation of Docker in general :) (I think you had understood)

You can put that under "Installation with Task" (or that of the maker).

A very simple trick will do, it's just to signal that they can use Docker. Besides, I'm not a Docker pro. Did you set up something in the docker script to initialize the application for the 1st time, or do you have to run "task install" or "make install" before?

Copy link
Author

@TheoMeunier TheoMeunier May 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do the installation of the project via "make install" or "task install" or via docker commands. So I will add the installation process via docker simply. Do you want me to update also the installation with tack to use docker?

The implementation of docker was created using my template where we can find all the information for the installation, which I could implement in this project ;)

Afterwards I could create a docker image for the whole application if the docker stack will suit you.

https://github.com/TheoMeunier/symfony-template

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you can add it on the Task file too ;)

Wow, a docker image would be awesome!

I let @jmsche for the end of the review :)

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Backups can be saved **locally** or in **S3 cloud** (AWS, Scaleway, ...).
1. [Prerequisites](#prerequisites)
1. [Manual install](#manual-install)
1. [Install using Task](#task-install)
1. [Install using Docker](#docker-install)
1. [Configure the CRON job](#cron)
1. [Use the application](#use-app)
1. [Login](#login)
Expand Down Expand Up @@ -62,6 +63,20 @@ Requires [Symfony CLI](https://symfony.com/download) and [Task](https://taskfile
1. If you want to run Docker containers (currently only for local emails with MailCatcher): `task docker-start` et `task docker-stop` (requires Docker and Docker Compose)
1. To start the server: `task start` (to stop it: `task stop`)

## Install using Docker <a name="docker-install"></a>

Requires [Docker](https://docs.docker.com/) to be installed.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also required Docker compose IIUC?


1. `git clone https://github.com/bastien70/dbsaver.git`
1. `chown 1000:1000 /path/ -R` (Make sure permission are well-defined for 1000:1000)
1. `cd dbsaver`
1. `docker compose -f docker-compose.prod.yaml up -d`
1. `docker compose exec php bash`
1. `composer install` (install dependencies)
1. `php bin/console app:regenerate-app-secret ` (regenerate the secret key allowing to hash databases passwords)'
1. `php bin/console d:m:m -n ` (migrate tables)
1. `php bin/console app:make-user ` (create your account)

## Configure the CRON job <a name="cron"></a>

Configure the CRON task allows you to activate the verification of backups to be made. **Set it up to run every day**.
Expand Down
10 changes: 10 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ tasks:
cmds:
- symfony server:stop

docker-install:
desc: Install project with Docker
cmds:
- cp .env.example .env
- docker compose up -d
- docker compose exec php bash -c "composer install"
- docker compose exec php bash -c "php bin/console app:regenerate-app-secret"
- docker compose exec php bash -c "php bin/console d:m:m -n"
- docker compose exec php bash -c "php bin/console app:make-user"

docker-start:
desc: Start Docker images
cmds:
Expand Down
11 changes: 9 additions & 2 deletions config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
default_connection: default
connections:
default:
driver: '%env(resolve:DB_CONNECTION)%'
host: '%env(resolve:DB_HOST)%'
port: '%env(resolve:DB_PORT)%'
dbname: '%env(resolve:DB_DATABASE)%'
user: '%env(resolve:DB_USERNAME)%'
password: '%env(resolve:DB_PASSWORD)%'
Comment on lines -3 to +11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything could be on the dbal level instead of explicitly defining a default connection.

Also, I'd like to keep the DATABASE_URL environment variable, so every parameter could be resolved in it instead.


# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '15'

profiling_collect_backtrace: '%kernel.debug%'
orm:
auto_generate_proxy_classes: true
enable_lazy_ghost_objects: true
Expand Down
1 change: 1 addition & 0 deletions config/packages/framework.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# see https://symfony.com/doc/current/reference/configuration/framework.html
framework:
secret: '%env(APP_SECRET)%'
trusted_proxies: '%env(TRUSTED_PROXIES)%'
#csrf_protection: true
http_method_override: false
handle_all_throwables: true
Expand Down
57 changes: 57 additions & 0 deletions docker-compose.prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
version: '3.8'

services:
# PHP Service
php:
build:
context: .
dockerfile: docker/php/Dockerfile
container_name: ${APP_SLUG}_php
restart: unless-stopped
environment:
SERVICE_NAME: ${APP_SLUG}_php
SERVICE_TAGS: ${APP_ENV}
working_dir: /var/www
volumes:
- ./:/var/www
- ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app_network

# Nginx Service
nginx:
image: nginx:alpine
container_name: ${APP_SLUG}_nginx
restart: unless-stopped
ports:
- "8888:80"
volumes:
- ./:/var/www
- ./docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
networks:
- app_network

# Mariadb Service
database:
image: mariadb:latest
container_name: ${APP_SLUG}_database
restart: unless-stopped
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_USER: ${DB_USERNAME}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
SERVICE_TAGS: ${APP_ENV}
SERVICE_NAME: ${APP_SLUG}_database
volumes:
- ./storage-db:/var/lib/mysql/
- ./docker/mysql/my.cnf:/etc/mysql/my.cnf
networks:
- app_network

# Docker Networks
networks:
app_network:
driver: bridge
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ services:
- '20-21:20-21/tcp'
- '40000-40009:40000-40009/tcp'
volumes:
db_data:
db_data:
3 changes: 3 additions & 0 deletions docker/mysql/my.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[mysqld]
general_log = 1
general_log_file = /var/lib/mysql/general.log
28 changes: 28 additions & 0 deletions docker/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
server {
listen 80 default;
client_max_body_size 308M;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/public;
index index.php;

location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}

location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
include fastcgi_params;
}

location ~ /\.(?!well-known).* {
deny all;
}
}
46 changes: 46 additions & 0 deletions docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
FROM php:8.2-fpm

# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/

# Set working directory
WORKDIR /var/www

# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
mariadb-client \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
libxslt-dev \
locales \
jpegoptim optipng pngquant gifsicle \
git \
zip

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install extensions
RUN docker-php-ext-install pdo pdo_mysql xsl intl gd
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are xsl & gd really necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, dependencies is realy neccessay for application, else symfony ask install


# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Add user for symfony application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www

# Copy existing application directory contents
COPY . /var/www

# Copy existing application directory permissions
COPY --chown=www:www . /var/www

# Change current user to www
USER www

# Expose port 9000 and start php server
EXPOSE 9000
CMD ["php-fpm"]
10 changes: 10 additions & 0 deletions docker/php/local.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
date.timezone=Europe/Paris
memory_limit=512M
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The app should run with less RAM

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's the memory limit of the application, do you want me to decrease it?

zend_extension=opcache.so

# http://symfony.com/doc/current/performance.html
opcache.interned_strings_buffer = 16
opcache.max_accelerated_files = 20000
opcache.memory_consumption = 256
realpath_cache_size = 4096K
realpath_cache_ttl = 600