Skip to content

Commit

Permalink
feat(master): Add RPC api backend microceservice
Browse files Browse the repository at this point in the history
- Initialize symfony skeleton
- Add needed vendors
- Add docker environment
- Develop microservice core
- Cover source code with unit and functional tests
  • Loading branch information
Artem Onyshchenko committed Apr 24, 2020
0 parents commit ccdc9ac
Show file tree
Hide file tree
Showing 335 changed files with 110,449 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .docker/nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
server {
listen 80;
server_tokens off;
client_max_body_size 8M;
charset utf-8;

root /app/public;
index index.php;

location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php$is_args$args;

}

location ~ \.php$ {
if (!-f $request_filename) { return 404; }

fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;

# Connect to php-fpm via socket
fastcgi_pass php-fpm;

fastcgi_connect_timeout 300s;
fastcgi_read_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_ignore_client_abort on;
fastcgi_pass_header "X-Accel-Expires";



fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTP_REFERER $http_referer;
include fastcgi_params;
}


location = /favicon.ico {
log_not_found off;
access_log off;
}

location = /robots.txt {
add_header Content-Type text/plain;
return 200 'User-agent: *\nDisallow: /\n';
log_not_found off;
access_log off;
}
}

upstream php-fpm {
server php-fpm:9000;
}


72 changes: 72 additions & 0 deletions .docker/php7.4-cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
FROM php:7.4-cli

RUN apt-get clean
RUN apt-get update

# php settings
ADD conf.ini /usr/local/etc/php/conf.d/
RUN chmod +r /usr/local/etc/php/conf.d/conf.ini

# curl for cmd
RUN apt-get install -y curl

# php extensions

# mcrypt
RUN apt-get install -y libmcrypt-dev

# bcmath
RUN docker-php-ext-install bcmath
RUN docker-php-ext-enable bcmath

# sockets
RUN docker-php-ext-install sockets
RUN docker-php-ext-enable sockets

# intl
RUN apt-get install -y libicu-dev
RUN docker-php-ext-install intl
RUN docker-php-ext-enable intl

# opcache
RUN docker-php-ext-install opcache
RUN docker-php-ext-enable opcache

# amqp
RUN apt-get install -y librabbitmq-dev
RUN pecl install amqp
RUN docker-php-ext-enable amqp

# redis
RUN docker-php-ext-enable redis

# zip
RUN apt-get install -y libzip-dev
RUN docker-php-ext-install zip
RUN docker-php-ext-enable zip

# pdo_pgsql
RUN apt-get install -y libpq-dev
RUN docker-php-ext-install pdo_pgsql
RUN docker-php-ext-enable pdo_pgsql

# opcache
RUN docker-php-ext-install opcache
RUN docker-php-ext-enable opcache

# install swoole
#TIP: it always get last stable version of swoole coroutine.
RUN export SWOOLE_VERSION=4.4.17 && cd /tmp && \
curl -o /tmp/swoole.tgz https://pecl.php.net/get/swoole-${SWOOLE_VERSION}.tgz && \
tar zxvf swoole.tgz && \
cd swoole-${SWOOLE_VERSION} && \
phpize && \
./configure \
--enable-coroutine \
--enable-http2 \
--enable-coroutine-postgresql \
--enable-async-redis && \
make && make install && \
docker-php-ext-enable swoole && \
echo "swoole.fast_serialize=On" >> /usr/local/etc/php/conf.d/docker-php-ext-swoole-serialize.ini && \
rm -rf /tmp/*
10 changes: 10 additions & 0 deletions .docker/php7.4-cli/conf.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
date.timezone = UTC
short_open_tag = Off
magic_quotes_gpc = Off
register_globals = Off
session.auto_start = Off
memory_limit = -1
max_execution_time = 300

opcache.preload=/app/preload.php

18 changes: 18 additions & 0 deletions .docker/php7.4-composer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ARG CI_COMMIT_REF_SLUG='master'
ARG CI_SERVICE_NAME

FROM temafey/php7.4-cli

ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_MEMORY_LIMIT -1

#CMD mkdir /.composer_cache
ENV COMPOSER_CACHE_DIR /.composer_cache

RUN apt-get update --fix-missing
RUN apt-get install -y git unzip

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

#boost composer
RUN composer -vvv global require hirak/prestissimo
84 changes: 84 additions & 0 deletions .docker/php7.4-dev-fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
FROM php:7.4-fpm

RUN apt-get update

# php settings
ADD conf.ini /usr/local/etc/php/conf.d/
RUN chmod +r /usr/local/etc/php/conf.d/conf.ini
COPY www.conf /usr/local/etc/php-fpm.d/www.conf

# curl for cmd
RUN apt-get install -y curl

# php extensions

# mcrypt
RUN apt-get install -y libmcrypt-dev
RUN pecl install mcrypt-1.0.3
RUN docker-php-ext-enable mcrypt

# bcmath
RUN docker-php-ext-install bcmath
RUN docker-php-ext-enable bcmath

# sockets
RUN docker-php-ext-install sockets
RUN docker-php-ext-enable sockets

# intl
RUN apt-get install -y libicu-dev
RUN docker-php-ext-install intl
RUN docker-php-ext-enable intl

# opcache
RUN docker-php-ext-install opcache
RUN docker-php-ext-enable opcache

# amqp
RUN apt-get install -y librabbitmq-dev
RUN pecl install amqp
RUN docker-php-ext-enable amqp

# redis
RUN pecl install redis
RUN docker-php-ext-enable redis

# zip
RUN apt-get install -y libzip-dev
RUN docker-php-ext-install zip
RUN docker-php-ext-enable zip

# pdo_pgsql
RUN apt-get install -y libpq-dev
RUN docker-php-ext-install pdo_pgsql
RUN docker-php-ext-enable pdo_pgsql

# opcache
RUN docker-php-ext-install opcache
RUN docker-php-ext-enable opcache

#composer
ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_MEMORY_LIMIT -1

#CMD mkdir /.composer_cache
ENV COMPOSER_CACHE_DIR /.composer_cache

RUN apt-get update --fix-missing
RUN apt-get install -y git unzip

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

#boost composer
RUN composer -vvv global require hirak/prestissimo

#develop layer
RUN apt-get install -y gnupg
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug
RUN pecl install ast
RUN docker-php-ext-enable ast

RUN rm -rf /var/cache/apk/* /var/tmp/* /tmp/*

WORKDIR /app
16 changes: 16 additions & 0 deletions .docker/php7.4-dev-fpm/conf.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
date.timezone = UTC
short_open_tag = Off
magic_quotes_gpc = Off
register_globals = Off
session.auto_start = Off
memory_limit = -1
max_execution_time = 300

opcache.preload=/app/preload.php

xdebug.remote_enable=1
xdebug.remote_connect_back=0
xdebug.remote_port=9000
xdebug.idekey=PHPSTORM
xdebug.remote_host=host.docker.internal

25 changes: 25 additions & 0 deletions .docker/php7.4-dev-fpm/www.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[global]
error_log = /proc/self/fd/2

[www]
listen = 127.0.0.1:9000
user = www-data
group = www-data
pm = dynamic
pm.max_children = 6
pm.start_servers = 3
pm.min_spare_servers = 3
pm.max_spare_servers = 5
pm.max_requests = 500
;pm.status_path = /php/fpm/status
;ping.path = /php/fpm/ping
request_terminate_timeout = 120s
request_slowlog_timeout = 5s
slowlog = /proc/self/fd/2
rlimit_files = 4096
rlimit_core = 0
catch_workers_output = yes
clear_env = no
access.log = /proc/self/fd/1
access.format = "%t \"%m %r%Q%q\" %s %{mili}dms %{kilo}Mkb %C%%"
chdir = /app/public
17 changes: 17 additions & 0 deletions .docker/php7.4-dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ARG CI_COMMIT_REF_SLUG='master'
ARG CI_SERVICE_NAME

FROM temafey/php7.4-composer

RUN apt-get install -y gnupg
#RUN pecl install xdebug
#RUN docker-php-ext-enable xdebug
RUN pecl install ast
RUN docker-php-ext-enable ast

RUN rm -rf /var/cache/apk/* /var/tmp/* /tmp/*

WORKDIR /app



22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8

# 4 space indentation
[*.php]
indent_style = space
indent_size = 4

# Tab indentation (no size specified)
[Makefile]
indent_style = tab

# Matches the exact files either package.json or .travis.yml
[{composer.json,*.yml, *.yaml}]
indent_style = space
indent_size = 2
40 changes: 40 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=
APP_VERSION=0.4.0

###> common variables ###
APP_COMPOSE_PROJECT_NAME=backend-rpc-api
CI_COMMIT_REF_SLUG=master
CI_SERVICE_NAME=backend-rpc-api
###< common variables ###

###> postgresql ###
APISKELETON_POSTGRESQL_HOST=postgres
APISKELETON_POSTGRESQL_PORT=5432
APISKELETON_POSTGRESQL_DB=backend-api-skeleton
POSTGRESQL_DB=backend-api-skeleton
APISKELETON_POSTGRESQL_USER=postgres_user
APISKELETON_POSTGRESQL_PASS=postgres_pass
###< postgresql ###

###> rabbitmq ###
APISKELETON_RABBITMQ_HOST=rabbitmq
APISKELETON_RABBITMQ_USER=rabbit_user
APISKELETON_RABBITMQ_PASS=rabbit_pass
APISKELETON_RABBITMQ_VHOST=/
APISKELETON_RABBITMQ_WEB_PORT=15672
APISKELETON_RABBITMQ_PORT=5672
###< rabbitmq ###

###> sentry dsn ###
APISKELETON_SENTRY_DSN=http://public:[email protected]/1
###< sentry dsn ###

###> redis ###
APISKELETON_REDIS_HOST=redis
APISKELETON_REDIS_PORT=6379
###> redis ###

TRUSTED_PROXIES=127.0.0.1/8
TRUSTED_HOSTS=0.0.0.0,127.0.0.1,localhost
Loading

0 comments on commit ccdc9ac

Please sign in to comment.