Skip to content

Commit

Permalink
Add docker files
Browse files Browse the repository at this point in the history
  • Loading branch information
kadet1090 committed Feb 13, 2021
1 parent 7c2941b commit 2c072b7
Show file tree
Hide file tree
Showing 14 changed files with 320 additions and 61 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/public/build/images/glyphicons-*

*.Dockerfile
docker-compose.*
Makefile

###> symfony/framework-bundle ###
/.env.local
Expand Down
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.PHONY: all rr fpm builtin apache

%.Dockerfile:
docker build -f $@ -t symfony-demo:$(basename $@) .

rr.Dockerfile: base.Dockerfile
fpm.Dockerfile: base.Dockerfile
builtin.Dockerfile: base.Dockerfile
apache.Dockerfile: base.Dockerfile

rr: rr.Dockerfile
fpm: fpm.Dockerfile
builtin: builtin.Dockerfile
apache: apache.Dockerfile

all: rr fpm builtin
24 changes: 24 additions & 0 deletions apache.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM php:7.4-apache

RUN apt-get update && apt-get -y install libicu-dev libzip-dev && \
docker-php-ext-install bcmath intl opcache zip sockets;

ENV APP_ENV=prod
ENV DATABASE_URL="sqlite:////var/db/app.db"
ENV MAILER_DSN="smtp://localhost:25"
ENV PATH=$PATH:/var/www/bin

WORKDIR /var/www

COPY --from=symfony-demo:base /var/www .
COPY --from=symfony-demo:base /var/db /var/db

# Timezone
RUN ln -snf /usr/share/zoneinfo/Europe/Warsaw /etc/localtime && \
echo "date.timezone = Europe/Warsaw" >> /usr/local/etc/php/conf.d/datetime.ini;

RUN a2enmod rewrite
COPY ./docker/apache.conf /etc/apache2/sites-available/000-default.conf
RUN chown -R www-data:www-data /var/www

CMD ["./bin/docker-init.sh", "apache2-foreground"]
27 changes: 27 additions & 0 deletions base.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM node:latest as assets
WORKDIR /var/www

COPY ./assets/ ./assets/
COPY ./package.json webpack.config.js yarn.lock ./
RUN yarn install && yarn run build

FROM php:7.4-alpine

ENV APP_ENV=prod
ENV DATABASE_URL="sqlite:////var/db/app.db"
ENV MAILER_DSN="smtp://localhost:25"

WORKDIR /var/www

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY . .
COPY --from=assets /var/www/public public

RUN composer install --prefer-dist --no-progress --no-interaction --ignore-platform-reqs && \
composer dump-autoload --optimize && \
php bin/console cache:warmup

RUN mkdir /var/db && \
./bin/console doctrine:schema:create && \
./bin/console doctrine:schema:update --force && \
yes | APP_ENV=dev ./bin/console doctrine:fixtures:load
30 changes: 6 additions & 24 deletions builtin.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,18 @@
FROM node:latest as assets
WORKDIR /var/www

COPY . .
RUN yarn install && yarn run build

FROM php:7.4-alpine

RUN apk add --no-cache autoconf openssl-dev g++ make pcre-dev icu-dev zlib-dev libzip-dev git && \
docker-php-ext-install bcmath intl opcache zip sockets && \
apk del --purge autoconf g++ make;

ENV APP_ENV=prod
ENV DATABASE_URL="sqlite:////var/db/app.db"
ENV MAILER_DSN="smtp://localhost:25"
ENV PATH=$PATH:/var/www/bin

WORKDIR /var/www

RUN mkdir /var/db

RUN apk add --no-cache autoconf openssl-dev g++ make pcre-dev icu-dev zlib-dev libzip-dev git && \
docker-php-ext-install bcmath intl opcache zip sockets && \
apk del --purge autoconf g++ make;

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY . .
COPY --from=assets /var/www/public public

RUN composer install --prefer-dist --no-progress --no-interaction && \
composer dump-autoload --optimize && \
composer check-platform-reqs && \
php bin/console cache:warmup

RUN ./bin/console doctrine:schema:create && \
./bin/console doctrine:schema:update --force && \
yes | APP_ENV=dev ./bin/console doctrine:fixtures:load
COPY --from=symfony-demo:base /var/www .
COPY --from=symfony-demo:base /var/db /var/db

# Timezone
RUN ln -snf /usr/share/zoneinfo/Europe/Warsaw /etc/localtime && \
Expand Down
35 changes: 33 additions & 2 deletions docker-compose.locust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,42 @@ services:
ports:
- "8080:8089"
volumes:
- ./locust:/mnt/locust
- ./:/mnt/locust
command: -f /mnt/locust/locustfile.py --master -H http://master:8089

worker:
image: locustio/locust
volumes:
- ./locust:/mnt/locust
- ./:/mnt/locust
command: -f /mnt/locust/locustfile.py --worker --master-host master
depends_on:
- master

frontend-rr:
image: symfony-demo:rr
ports:
- 8081:8080

frontend-builtin:
image: symfony-demo:builtin
ports:
- 8082:8080

frontend-fpm:
image: nginx:latest
volumes:
- ./public:/var/www/public
- ./docker/symfony-demo.conf:/etc/nginx/conf.d/default.conf
- ./docker/upstream.conf:/etc/nginx/conf.d/upstream.conf
ports:
- 8083:8080
depends_on:
- fpm

fpm:
image: symfony-demo:fpm

frontend-apache:
image: symfony-demo:apache
ports:
- 8084:80
10 changes: 10 additions & 0 deletions docker/apache.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/public

<Directory /var/www>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
8 changes: 8 additions & 0 deletions docker/php-fpm.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[www]
listen = 0.0.0.0:9000

pm = dynamic
pm.max_children = 32
pm.start_servers = 8
pm.min_spare_servers = 4
pm.max_spare_servers = 8
27 changes: 27 additions & 0 deletions docker/symfony-demo.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
server {
listen 8080;
root /var/www/public;

location / {
try_files $uri /index.php$is_args$args;
}

location ~ ^/.+\.php(/|$) {
fastcgi_buffer_size 256k;
fastcgi_buffers 64 256k;
fastcgi_pass php-upstream;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}

location ~ \.php$ {
return 404;
}

error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
}

1 change: 1 addition & 0 deletions docker/upstream.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
upstream php-upstream { server fpm:9000; }
20 changes: 9 additions & 11 deletions fpm.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
FROM php:7.4-fpm-alpine

ENV APP_ENV=prod
ENV DATABASE_URL="sqlite:////var/db/app.db"
ENV PATH=$PATH:/usr/src/app/bin

RUN apk add --no-cache autoconf openssl-dev g++ make pcre-dev icu-dev zlib-dev libzip-dev git && \
docker-php-ext-install bcmath intl opcache zip sockets && \
apk del --purge autoconf g++ make;

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY . .
ENV APP_ENV=prod
ENV DATABASE_URL="sqlite:////var/db/app.db"
ENV MAILER_DSN="smtp://localhost:25"
ENV PATH=$PATH:/var/www/bin

WORKDIR /var/www

RUN composer install --no-dev --no-scripts --no-plugins --prefer-dist --no-progress --no-interaction && \
composer dump-autoload --optimize && \
composer check-platform-reqs && \
php bin/console cache:warmup
COPY --from=symfony-demo:base /var/www .
COPY --from=symfony-demo:base /var/db /var/db

# Timezone
RUN ln -snf /usr/share/zoneinfo/Europe/Warsaw /etc/localtime && \
echo "date.timezone = Europe/Warsaw" >> /usr/local/etc/php/conf.d/datetime.ini;

WORKDIR /var/www
ADD ./docker/php-fpm.conf /usr/local/etc/php-fpm.d/symfony.conf

CMD ["./bin/docker-init.sh", "php-fpm"]
43 changes: 43 additions & 0 deletions locustfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import time
from locust import HttpUser, task, between
from random import randint, choice, seed

seed(3721)

class BlogUser(HttpUser):
wait_time = between(1, 2.5)

def on_start(self):
self.max_pages = 3
self.tags = [ tag['name'] for tag in self.client.get("/en/api/tags").json() ]
self.queries = ["Lorem ipsum", "vitae velit", "Ubi est", "dolor"]

@task(5)
def browse_tag(self):
tag = choice(self.tags)
self.client.get(f"/en/blog?tag={tag}")

posts = self.client.get(f"/en/api/posts?tag={tag}").json()
self.browse_posts(posts, 3)

@task(10)
def browse_task(self):
page = randint(1, self.max_pages)

self.client.get(f"/en/blog/page/{page}")
posts = self.client.get(f"/en/api/posts?page={page}").json()
self.browse_posts(posts, 4)

@task(2)
def search_task(self):
query = choice(self.queries)
posts = self.client.get(f"/en/api/search?q={query}").json()
self.browse_posts(posts, 2)

def browse_posts(self, posts, count):
if len(posts) == 0:
return

for _ in range(count):
post = choice(posts)
self.client.get(post['url'])
31 changes: 7 additions & 24 deletions rr.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,41 +1,24 @@
FROM node:latest as assets
WORKDIR /var/www

COPY . .
RUN yarn install && yarn run build

FROM php:7.4-alpine

RUN apk add --no-cache autoconf openssl-dev g++ make pcre-dev icu-dev zlib-dev libzip-dev git && \
docker-php-ext-install bcmath intl opcache zip sockets && \
apk del --purge autoconf g++ make;

ENV APP_ENV=prod
ENV DATABASE_URL="sqlite:////var/db/app.db"
ENV MAILER_DSN="smtp://localhost:25"
ENV PATH=$PATH:/var/www/bin

WORKDIR /var/www

RUN mkdir /var/db

RUN apk add --no-cache autoconf openssl-dev g++ make pcre-dev icu-dev zlib-dev libzip-dev git && \
docker-php-ext-install bcmath intl opcache zip sockets && \
apk del --purge autoconf g++ make;

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY . .
COPY --from=assets /var/www/public public

RUN composer install --prefer-dist --no-progress --no-interaction && \
composer dump-autoload --optimize && \
composer check-platform-reqs && \
php bin/console cache:warmup

RUN ./bin/console doctrine:schema:create && \
./bin/console doctrine:schema:update --force && \
yes | APP_ENV=dev ./bin/console doctrine:fixtures:load
COPY --from=symfony-demo:base /var/www .
COPY --from=symfony-demo:base /var/db /var/db

# Timezone
RUN ln -snf /usr/share/zoneinfo/Europe/Warsaw /etc/localtime && \
echo "date.timezone = Europe/Warsaw" >> /usr/local/etc/php/conf.d/datetime.ini;

# Get rr binary
RUN ./vendor/bin/rr get-binary --location /usr/local/bin

EXPOSE 8080
Expand Down
Loading

0 comments on commit 2c072b7

Please sign in to comment.