From 4f72c5b135d8842ae32ed318344ffc0486c02508 Mon Sep 17 00:00:00 2001 From: Sieciech Date: Fri, 23 Jul 2021 15:26:47 +0200 Subject: [PATCH 1/2] docker --- docker/.gitignore | 4 +++ docker/Dockerfile | 49 ++++++++++++++++++++++++++++++++++ docker/cache/.gitkeep | 0 docker/cache/apt/.gitkeep | 0 docker/cache/postgres/.gitkeep | 0 docker/docker-compose.yml | 20 ++++++++++++++ docker/logs/.gitkeep | 0 docker/nginx/app.conf | 27 +++++++++++++++++++ docker/nginx/php80.conf | 14 ++++++++++ docker/postgres/init-data.sql | 4 +++ docker/startup.sh | 39 +++++++++++++++++++++++++++ src/backend/.env.beta | 3 +++ src/backend/.env.dev | 3 +++ src/backend/.env.prod | 3 +++ src/frontend/angular.json | 2 +- 15 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 docker/.gitignore create mode 100644 docker/Dockerfile create mode 100644 docker/cache/.gitkeep create mode 100644 docker/cache/apt/.gitkeep create mode 100644 docker/cache/postgres/.gitkeep create mode 100644 docker/docker-compose.yml create mode 100644 docker/logs/.gitkeep create mode 100644 docker/nginx/app.conf create mode 100644 docker/nginx/php80.conf create mode 100644 docker/postgres/init-data.sql create mode 100644 docker/startup.sh create mode 100644 src/backend/.env.beta create mode 100644 src/backend/.env.dev create mode 100644 src/backend/.env.prod diff --git a/docker/.gitignore b/docker/.gitignore new file mode 100644 index 0000000..fe869a5 --- /dev/null +++ b/docker/.gitignore @@ -0,0 +1,4 @@ +logs/* +!logs/.gitkeep +cache/*/* +!cache/*/.gitkeep diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..9542b72 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,49 @@ +FROM debian:10 + +RUN apt update \ + && echo "Binary::apt::APT::Keep-Downloaded-Packages \"true\";" | tee /etc/apt/apt.conf.d/01keep-debs \ + && apt install -y wget lsb-release ca-certificates apt-transport-https software-properties-common gnupg2 gcc g++ make \ + && echo "configure repos" \ + && echo "deb https://packages.sury.org/php/ buster main" | tee /etc/apt/sources.list.d/php.list \ + && echo "deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main" | tee /etc/apt/sources.list.d/postgresql.list \ + && echo "deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/buster pgadmin4 main" | tee /etc/apt/sources.list.d/pgdg.list \ + && echo "download keys" \ + && (wget -qO - https://packages.sury.org/php/apt.gpg | apt-key add - ) \ + && (wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - ) \ + && (wget -qO - https://www.pgadmin.org/static/packages_pgadmin_org.pub | apt-key add - ) \ + && echo "install nodejs" \ + && wget -qO - https://deb.nodesource.com/setup_16.x | bash - \ + && echo "update repos" \ + && apt update \ + && echo "install software" \ + && apt install -y aptitude nano openssh-server unzip \ + && apt install -y postgresql pgadmin4 \ + && apt install -y php8.0 php8.0-ctype php8.0-iconv php8.0-simplexml php8.0-tokenizer php8.0-fpm php8.0-pdo php8.0-pdo-pgsql php8.0-pgsql php8.0-mbstring php8.0-zip \ + && apt install -y nginx \ + && apt install -y nodejs \ + && echo "configure tools" \ + && echo "# angular" \ + && npm install -g @angular/cli \ + && echo "# composer" \ + && php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \ + && php composer-setup.php --install-dir=/usr/local/bin/ --filename=composer \ + && php -r "unlink('composer-setup.php');" \ + && echo "# nginx" \ + && ln -s /web/config/nginx/app.conf /etc/nginx/conf.d/app.conf \ + && ln -s /web/config/nginx/php80.conf /etc/nginx/php80.conf \ + && echo "# postgresql" \ + && echo "postgres:WeryStronkPaz2" | chpasswd \ + && echo "# pgadmin4" \ + && bash -c 'PGADMIN_SETUP_EMAIL="michal@fufle.net" PGADMIN_SETUP_PASSWORD="password" /usr/pgadmin4/bin/setup-web.sh --yes' \ + && echo "" > /etc/nginx/sites-enabled/default \ + && echo "!!! DONE !!!" + +VOLUME /web/backend/vendor +VOLUME /web/backend/var +VOLUME /web/frontend/node_modules + +EXPOSE 7700 + +STOPSIGNAL SIGQUIT + +CMD ["bash", "/web/config/startup.sh"] diff --git a/docker/cache/.gitkeep b/docker/cache/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docker/cache/apt/.gitkeep b/docker/cache/apt/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docker/cache/postgres/.gitkeep b/docker/cache/postgres/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..0eb2c84 --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,20 @@ +version: "3.9" +services: + cureapp: + build: . + ports: + - target: 7700 + published: 7700 + volumes: + - .:/web/config + - ../src/backend:/web/backend:cached + - ../src/frontend:/web/frontend:cached + - ./logs:/var/log + - vendor:/web/backend/vendor + - var:/web/backend/var + - nodemodules:/web/frontend/node_modules +volumes: + nodemodules: + vendor: + var: + nodemodules: \ No newline at end of file diff --git a/docker/logs/.gitkeep b/docker/logs/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docker/nginx/app.conf b/docker/nginx/app.conf new file mode 100644 index 0000000..b585ffc --- /dev/null +++ b/docker/nginx/app.conf @@ -0,0 +1,27 @@ +server { + server_name localhost; + listen 7700; + root /web/backend/public; + index index.htm index.html index.php; + location / { + proxy_bind 127.0.0.1; + proxy_pass http://localhost:4200; + } + location /api/ { + try_files $uri $uri/ /index.php/$uri?$query_string; + } + location /coverage/ { + alias /web/coverage/html-coverage/; + index index.html; + } + location /pgadmin4/ { + include proxy_params; + proxy_bind 127.0.0.1; + proxy_pass http://localhost:80; + proxy_set_header X-Script-Name /pgadmin4; + } + proxy_intercept_errors on; + fastcgi_intercept_errors on; + fastcgi_hide_header X-Powered-By; + include "php80.conf"; +} diff --git a/docker/nginx/php80.conf b/docker/nginx/php80.conf new file mode 100644 index 0000000..d08c54d --- /dev/null +++ b/docker/nginx/php80.conf @@ -0,0 +1,14 @@ +index index.php index.html index.htm; +include snippets/fastcgi-php.conf; +location ~ [^/]\.php(/|$) { + fastcgi_split_path_info ^(.+?\.php)(/.*)$; + if (!-f $document_root$fastcgi_script_name) { + return 404; + } + fastcgi_param HTTP_PROXY ""; + fastcgi_pass unix:/run/php/php8.0-fpm.sock; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + fastcgi_buffering off; +} \ No newline at end of file diff --git a/docker/postgres/init-data.sql b/docker/postgres/init-data.sql new file mode 100644 index 0000000..04899c1 --- /dev/null +++ b/docker/postgres/init-data.sql @@ -0,0 +1,4 @@ +ALTER USER postgres WITH PASSWORD 'WeryStronkPaz2'; +CREATE USER curenet WITH PASSWORD 'WeryStronkPaz2'; +CREATE DATABASE curenet; +GRANT ALL PRIVILEGES ON DATABASE curenet to curenet; \ No newline at end of file diff --git a/docker/startup.sh b/docker/startup.sh new file mode 100644 index 0000000..c072698 --- /dev/null +++ b/docker/startup.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +echo Configure logs + mkdir -p /var/log/{apache2,nginx,pgadmin,postgresql} + chmod root:postgres /var/log/postgresql -R + +echo Configure volumes + [ -e /web/frontend/node_modules ] || ln -s /web/node /web/frontend/node_modules + [ -e /web/backend/var ] || ln -s /web/var /web/backend/var + [ -e /web/backend/vendor ] || ln -s /web/vendor /web/backend/vendor + +echo Starting php-fpm server + service php8.0-fpm start + +echo Starting nginx server + service nginx start + +echo Starting apache2 server for pgAdmin4 + service apache2 start + +echo Starting postgresql database + service postgresql start + +echo Starting ssh server + service ssh start + +echo Configure database + su postgres -c psql postgres < /web/config/postgres/init-data.sql + +echo Configure symfony + cd /web/backend + composer install + +echo Configure angular + cd /web/frontend + npm i + +echo Starting angular + ng serve diff --git a/src/backend/.env.beta b/src/backend/.env.beta new file mode 100644 index 0000000..0a48360 --- /dev/null +++ b/src/backend/.env.beta @@ -0,0 +1,3 @@ +APP_ENV=dev +APP_SECRET=0fc8d6b67b9f1100b3eb3e3c80d36fda +DATABASE_URL="postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=13&charset=utf8" diff --git a/src/backend/.env.dev b/src/backend/.env.dev new file mode 100644 index 0000000..2502619 --- /dev/null +++ b/src/backend/.env.dev @@ -0,0 +1,3 @@ +APP_ENV=dev +APP_SECRET=0fc8d6b67b9f1100b3eb3e3c80d36fda +DATABASE_URL="postgresql://curenet:WeryStronkPaz2@127.0.0.1:5432/curenet?serverVersion=13&charset=utf8" diff --git a/src/backend/.env.prod b/src/backend/.env.prod new file mode 100644 index 0000000..0a48360 --- /dev/null +++ b/src/backend/.env.prod @@ -0,0 +1,3 @@ +APP_ENV=dev +APP_SECRET=0fc8d6b67b9f1100b3eb3e3c80d36fda +DATABASE_URL="postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=13&charset=utf8" diff --git a/src/frontend/angular.json b/src/frontend/angular.json index 1f311f0..08083a6 100644 --- a/src/frontend/angular.json +++ b/src/frontend/angular.json @@ -38,7 +38,7 @@ "build": { "builder": "@angular-devkit/build-angular:browser", "options": { - "outputPath": "dist/frontend", + "outputPath": "dist", "index": "src/index.html", "main": "src/main.ts", "polyfills": "src/polyfills.ts", -- 2.39.5 From 9442839cc47da6eaf95a3fb7d83181a837571661 Mon Sep 17 00:00:00 2001 From: Sieciech Date: Fri, 23 Jul 2021 18:08:09 +0200 Subject: [PATCH 2/2] docker configuration --- .vscode/launch.json | 35 +++++++++++++++++++++++++++++++++++ docker/Dockerfile | 9 +++++---- docker/docker-compose.yml | 8 +++++--- docker/php8.0/xdebug-cli.ini | 12 ++++++++++++ docker/php8.0/xdebug-fpm.ini | 12 ++++++++++++ docker/run | 1 + docker/startup.sh | 29 +++++++++++++++++------------ 7 files changed, 87 insertions(+), 19 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 docker/php8.0/xdebug-cli.ini create mode 100644 docker/php8.0/xdebug-fpm.ini create mode 100644 docker/run diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..1b2778f --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,35 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "PHP 8.0", + "type": "php", + "request": "launch", + "pathMappings": { + "/web/backend": "${workspaceFolder}\\src\\backend" + }, + "skipFiles": [ + "${workspaceFolder}/src/backend/vendor/**" + ], + "port": 7780, + "hostname": "127.0.0.1", + "xdebugSettings": { + "max_children": 100, + } + }, + { + "name": "PHP 8.0 with vendor", + "type": "php", + "request": "launch", + "pathMappings": { + "/web/backend": "${workspaceFolder}\\src\\backend" + }, + "port": 7780, + "hostname": "127.0.0.1", + "xdebugSettings": { + "max_children": 100, + } + } + + ] +} \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile index 9542b72..3f01d67 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -16,9 +16,9 @@ RUN apt update \ && echo "update repos" \ && apt update \ && echo "install software" \ - && apt install -y aptitude nano openssh-server unzip \ + && apt install -y aptitude unzip \ && apt install -y postgresql pgadmin4 \ - && apt install -y php8.0 php8.0-ctype php8.0-iconv php8.0-simplexml php8.0-tokenizer php8.0-fpm php8.0-pdo php8.0-pdo-pgsql php8.0-pgsql php8.0-mbstring php8.0-zip \ + && apt install -y php8.0 php8.0-ctype php8.0-iconv php8.0-simplexml php8.0-tokenizer php8.0-fpm php8.0-pdo php8.0-pdo-pgsql php8.0-pgsql php8.0-mbstring php8.0-zip php8.0-xdebug \ && apt install -y nginx \ && apt install -y nodejs \ && echo "configure tools" \ @@ -34,15 +34,16 @@ RUN apt update \ && echo "# postgresql" \ && echo "postgres:WeryStronkPaz2" | chpasswd \ && echo "# pgadmin4" \ - && bash -c 'PGADMIN_SETUP_EMAIL="michal@fufle.net" PGADMIN_SETUP_PASSWORD="password" /usr/pgadmin4/bin/setup-web.sh --yes' \ + && bash -c 'PGADMIN_SETUP_EMAIL="admin@pgadmin.localhost" PGADMIN_SETUP_PASSWORD="WeryStronkPaz2" /usr/pgadmin4/bin/setup-web.sh --yes' \ && echo "" > /etc/nginx/sites-enabled/default \ && echo "!!! DONE !!!" +RUN apt install -y nano openssh-server telnet VOLUME /web/backend/vendor VOLUME /web/backend/var VOLUME /web/frontend/node_modules -EXPOSE 7700 +EXPOSE 7700 7780 7781 STOPSIGNAL SIGQUIT diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 0eb2c84..4678e24 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,10 +1,12 @@ version: "3.9" services: - cureapp: + app: build: . ports: - - target: 7700 - published: 7700 + - 7700:7700 + expose: + - 7780:7780 + - 7781:7781 volumes: - .:/web/config - ../src/backend:/web/backend:cached diff --git a/docker/php8.0/xdebug-cli.ini b/docker/php8.0/xdebug-cli.ini new file mode 100644 index 0000000..80b4894 --- /dev/null +++ b/docker/php8.0/xdebug-cli.ini @@ -0,0 +1,12 @@ +zend_extension=xdebug.so + +[xdebug] +xdebug.mode=coverage +xdebug.start_with_request=yes +xdebug.client_host=host.docker.internal +xdebug.client_port=7781 + +xdebug.show_exception_trace = 1 +xdebug.show_error_trace = 1 + +xdebug.log_level = 0 \ No newline at end of file diff --git a/docker/php8.0/xdebug-fpm.ini b/docker/php8.0/xdebug-fpm.ini new file mode 100644 index 0000000..8d3cc4c --- /dev/null +++ b/docker/php8.0/xdebug-fpm.ini @@ -0,0 +1,12 @@ +zend_extension=xdebug.so + +[xdebug] +xdebug.mode=debug +xdebug.start_with_request=yes +xdebug.client_host=host.docker.internal +xdebug.client_port=7780 + +xdebug.show_exception_trace = 1 +xdebug.show_error_trace = 1 + +xdebug.log_level = 0 \ No newline at end of file diff --git a/docker/run b/docker/run new file mode 100644 index 0000000..d326db1 --- /dev/null +++ b/docker/run @@ -0,0 +1 @@ +docker compose -p curenet up \ No newline at end of file diff --git a/docker/startup.sh b/docker/startup.sh index c072698..8335257 100644 --- a/docker/startup.sh +++ b/docker/startup.sh @@ -1,39 +1,44 @@ #!/bin/bash -echo Configure logs +echo "> Configure logs" mkdir -p /var/log/{apache2,nginx,pgadmin,postgresql} - chmod root:postgres /var/log/postgresql -R + chown postgres:adm /var/log/postgresql -R + chown root:postgres /var/log/postgresql -echo Configure volumes +echo "> Configure volumes" [ -e /web/frontend/node_modules ] || ln -s /web/node /web/frontend/node_modules [ -e /web/backend/var ] || ln -s /web/var /web/backend/var [ -e /web/backend/vendor ] || ln -s /web/vendor /web/backend/vendor -echo Starting php-fpm server +echo "> Starting php8.0-fpm server" + [ -e /etc/php/8.0/fpm/conf.d/20-xdebug.ini ] && rm /etc/php/8.0/fpm/conf.d/20-xdebug.ini || echo OK + [ -e /etc/php/8.0/cli/conf.d/20-xdebug.ini ] && rm /etc/php/8.0/cli/conf.d/20-xdebug.ini || echo OK + cp /web/config/php8.0/xdebug-fpm.ini /etc/php/8.0/fpm/conf.d/20-xdebug.ini + cp /web/config/php8.0/xdebug-cli.ini /etc/php/8.0/cli/conf.d/20-xdebug.ini service php8.0-fpm start -echo Starting nginx server +echo "> Starting nginx server" service nginx start -echo Starting apache2 server for pgAdmin4 +echo "> Starting apache2 server for pgAdmin4" service apache2 start -echo Starting postgresql database +echo "> Starting postgresql database" service postgresql start -echo Starting ssh server +echo "> Starting ssh server" service ssh start -echo Configure database +echo "> Configure database" su postgres -c psql postgres < /web/config/postgres/init-data.sql -echo Configure symfony +echo "> Configure symfony" cd /web/backend composer install -echo Configure angular +echo "> Configure angular" cd /web/frontend npm i -echo Starting angular +echo "> Starting angular" ng serve -- 2.39.5