Skip to content

Commit 72d8b34

Browse files
authored
Merge pull request #11 from hetg/feature/add-docker
add-docker -- added docker and some codefixes for newer version of doctrine
2 parents a03b9d4 + 053afef commit 72d8b34

File tree

15 files changed

+305
-7
lines changed

15 files changed

+305
-7
lines changed

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
.git/
3+
.idea/
4+
vendor/
5+
node_modules/

.env.dist

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ JWT_TOKEN_TTL=3600
2626
###< lexik/jwt-authentication-bundle ###
2727

2828
###> doctrine/doctrine-bundle ###
29-
DATABASE_URL=mysql://username:password@127.0.0.1:3306/db_name?serverVersion=5.7
29+
DB_NAME=db_name
30+
DB_HOST=mysql
31+
DB_PORT=3306
32+
DB_USER=username
33+
DB_PASSWORD=password
34+
DATABASE_URL=mysql://username:password@mysql/db_name?serverVersion=5.7
3035
###< doctrine/doctrine-bundle ###
3136

3237
###> symfony/swiftmailer-bundle ###

README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# JWT + FOS User + FOS REST template
22

3+
**Docker setup**
4+
5+
1. Copy `.env.dist` to `.env` file. Configure your local settings in `.env` file:
6+
```
7+
cp .env.dist .env
8+
```
9+
10+
2. Build containers:
11+
```
12+
docker-compose build
13+
```
14+
15+
3. Start containers:
16+
```
17+
docker-compose up -d
18+
319
**Installation**
420
521
1. Generate the SSH keys:
@@ -9,18 +25,15 @@
925
openssl pkey -in config/jwt/private.pem -out config/jwt/public.pem -pubout
1026
```
1127
12-
2. Copy `.env.dist` to `.env` file. Configure your local settings in `.env` file
13-
14-
3. Install composer packages:
28+
2. Install composer packages:
1529
```
1630
composer install
1731
```
18-
4. Create database and run migrations:
32+
3. Create database and run migrations:
1933
```
20-
bin/console doctrine:database:create
2134
bin/console doctrine:migrations:migrate
2235
```
23-
5. Create admin user
36+
4. Create admin user
2437
```
2538
bin/console doctrine:fixtures:load
2639
```

config/packages/jms_serializer.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ jms_serializer:
1111
default_context:
1212
serialization:
1313
serialize_null: true
14+
groups: ['api']
1415
deserialization:
1516
serialize_null: true
17+
groups: ['api']
1618
# metadata:
1719
# directories:
1820
# FOSUserBundle:

config/services.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ services:
2626
# add more service definitions when explicit configuration is needed
2727
# please note that last definitions always *replace* previous ones
2828

29+
# Fix for Doctrine Common 3.0 to make it work with JWTRefreshTokenBundle
30+
gesdinet.jwtrefreshtoken.refresh_token_manager:
31+
class: App\Doctrine\RefreshTokenManager
32+
public: true
33+
arguments: [ '@gesdinet.jwtrefreshtoken.object_manager', '%gesdinet.jwtrefreshtoken.refresh_token.class%' ]
34+
2935
api_exceptions_subscriber:
3036
class: App\EventListener\ApiExceptionsSubscriber
3137
arguments: []

docker-compose.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
version: '3.7'
2+
services:
3+
mysql:
4+
image: mysql:5.7
5+
container_name: 'template_mysql'
6+
ports:
7+
- '3307:3306'
8+
restart: always
9+
environment:
10+
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
11+
MYSQL_DATABASE: '${DB_NAME}'
12+
networks:
13+
- template_internal
14+
php:
15+
build:
16+
context: .
17+
dockerfile: docker/php-fpm/Dockerfile
18+
args:
19+
XDEBUG_CONFIG: "remote_host=192.168.223.1 remote_enable=1"
20+
PHP_IDE_CONFIG: "serverName=Docker"
21+
container_name: 'template_php'
22+
depends_on:
23+
- mysql
24+
ports:
25+
- '9002:9000'
26+
volumes:
27+
- ./:/var/www/app:cached
28+
- ${PHP_INI_OVERRIDES:-./docker/php-fpm/php-ini-overrides.ini}:/usr/local/etc/php/conf.d/99-overrides.ini
29+
environment:
30+
- APP_ENV
31+
- APP_SECRET
32+
- DB_NAME
33+
- DB_HOST
34+
- DB_PORT
35+
- DB_USER
36+
- DB_PASSWORD
37+
- JWT_SECRET_KEY
38+
- JWT_PUBLIC_KEY
39+
- JWT_PASSPHRASE
40+
- XDEBUG_CONFIG=remote_host=192.168.223.1 remote_enable=1
41+
- PHP_IDE_CONFIG=serverName=Docker
42+
- USER_ID
43+
- GROUP_ID
44+
networks:
45+
- template_internal
46+
nginx:
47+
build: ./docker/nginx
48+
container_name: 'template_nginx'
49+
ports:
50+
- '${DOCKER_COMPOSE_NGINX_PORT:-8000}:80'
51+
volumes:
52+
- ./var/log/nginx:/var/log/nginx:cached
53+
- ./:/var/www/app:cached
54+
networks:
55+
- template_internal
56+
redis:
57+
image: redis:latest
58+
container_name: 'template_redis'
59+
networks:
60+
- template_internal
61+
networks:
62+
template_internal:
63+
driver: bridge
64+
ipam:
65+
driver: default
66+
config:
67+
- subnet: 192.168.223.0/28

docker/nginx/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM nginx:latest
2+
3+
COPY nginx.conf /etc/nginx/nginx.conf
4+
COPY symfony.conf /etc/nginx/conf.d/default.conf

docker/nginx/nginx.conf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
user nginx;
2+
worker_processes 1;
3+
4+
error_log /var/log/nginx/error.log warn;
5+
pid /var/run/nginx.pid;
6+
7+
8+
events {
9+
worker_connections 1024;
10+
}
11+
12+
13+
http {
14+
include /etc/nginx/mime.types;
15+
default_type application/octet-stream;
16+
17+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
18+
'$status $body_bytes_sent "$http_referer" '
19+
'"$http_user_agent" "$http_x_forwarded_for"';
20+
21+
access_log /var/log/nginx/access.log main;
22+
23+
client_max_body_size 100M;
24+
fastcgi_buffers 4 256k;
25+
fastcgi_buffer_size 256k;
26+
27+
sendfile on;
28+
#tcp_nopush on;
29+
30+
keepalive_timeout 65;
31+
32+
#gzip on;
33+
34+
include /etc/nginx/conf.d/*.conf;
35+
}

docker/nginx/symfony.conf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
server {
2+
listen 80;
3+
server_name localhost;
4+
root /var/www/app/public;
5+
6+
location ~ \.yaml {
7+
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
8+
if_modified_since off;
9+
expires off;
10+
etag off;
11+
}
12+
13+
location / {
14+
try_files $uri /index.php$is_args$args;
15+
}
16+
17+
location ~ ^/(.*?)\.php(/|$) {
18+
fastcgi_pass php:9000;
19+
fastcgi_split_path_info ^(.+\.php)(/.*)$;
20+
include fastcgi_params;
21+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
22+
fastcgi_param DOCUMENT_ROOT $realpath_root;
23+
proxy_buffer_size 128k;
24+
proxy_buffers 4 256k;
25+
proxy_busy_buffers_size 256k;
26+
internal;
27+
}
28+
29+
error_log /var/log/nginx/error.log;
30+
access_log /var/log/nginx/access.log;
31+
}

docker/php-fpm/Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM php:7.4-fpm
2+
3+
ENV APP_DIR /var/www/app
4+
5+
RUN apt-get update && apt-get install -y git zip unzip libpq-dev libicu-dev
6+
7+
RUN docker-php-ext-configure intl \
8+
&& docker-php-ext-install \
9+
intl \
10+
pdo pdo_mysql
11+
12+
COPY --from=composer:2.4.4 /usr/bin/composer /usr/bin/composer
13+
14+
COPY ./docker/php-fpm/uploads.ini /usr/local/etc/php/conf.d/uploads.ini
15+
16+
# install xdebug
17+
RUN pecl install xdebug \
18+
&& docker-php-ext-enable xdebug
19+
20+
WORKDIR ${APP_DIR}
21+
22+
COPY ./docker/php-fpm/entrypoint.sh /entrypoint.sh
23+
24+
RUN chown -R www-data:www-data /var/www
25+
26+
RUN sed -i -e 's@zend_extension@;zend_extension@g' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
27+
28+
ENTRYPOINT ["/entrypoint.sh", "docker-php-entrypoint"]
29+
CMD ["php-fpm"]

0 commit comments

Comments
 (0)