Skip to content

Commit

Permalink
Use official images in Docker setup (#1216)
Browse files Browse the repository at this point in the history
  • Loading branch information
leafnode authored and chartjes committed Apr 11, 2019
1 parent d14e376 commit e8cce1b
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 183 deletions.
48 changes: 5 additions & 43 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
FROM zaherg/php-and-nginx:latest
FROM php:7-fpm-alpine

ARG BUILD_DATE
ARG DOCKER_REPO
ARG VCS_REF
ARG IMAGE_NAME
ARG VERSION

LABEL Maintainer="Zaher Ghaibeh <[email protected]>" \
Description="This is the docker image for OpenCFP, a PHP-based conference talk submission system." \
LABEL Description="This is the docker image for OpenCFP, a PHP-based conference talk submission system." \
org.label-schema.name=$IMAGE_NAME \
org.label-schema.description="This is the docker image for OpenCFP, a PHP-based conference talk submission system." \
org.label-schema.build-date=$BUILD_DATE \
Expand All @@ -17,41 +10,10 @@ LABEL Maintainer="Zaher Ghaibeh <[email protected]>" \
org.label-schema.version=$VERSION \
org.label-schema.schema-version="1.0.0"

RUN docker-php-ext-install pdo_mysql

ENV CFP_ENV ${CFP_ENV:-development}
ENV CFP_DB_HOST ${CFP_DB_HOST:-"127.0.0.1"}
ENV CFP_DB_PASS ${CFP_DB_PASS:-root}

COPY ./ /var/www

RUN set -ex \
&& sed -i "s/access_log logs\/access.log main;/access_log \/var\/log\/nginx\/access.cfp.log; error_log \/var\/log\/nginx\/error.cfp.log;/" /etc/nginx/nginx.conf \
&& sed -i "s/\/web\/html/\/var\/www\/web/" /etc/nginx/nginx.conf && \
sed -i "s/localhost/_/" /etc/nginx/nginx.conf && \
sed -i "s/#user nobody;/user www-data;/" /etc/nginx/nginx.conf && \
sed -i "s/#gzip on;/gzip on;/" /etc/nginx/nginx.conf && \
touch /usr/local/etc/php/php.ini && \
echo "cgi.fix_pathinfo=0" >> /usr/local/etc/php/php.ini && \
echo "upload_max_filesize = 120M" >> /usr/local/etc/php/php.ini && \
echo "post_max_size = 120M" >> /usr/local/etc/php/php.ini && \
echo "memory_limit = 512M" >> /usr/local/etc/php/php.ini && \
echo 'variables_order = "EGPCS"' >> /usr/local/etc/php/php.ini && \
sed -i -e "s/;catch_workers_output\s*=\s*yes/catch_workers_output = yes/g" /usr/local/etc/php-fpm.d/www.conf && \
sed -i -e "s/pm.max_children = 5/pm.max_children = 9/g" /usr/local/etc/php-fpm.d/www.conf && \
sed -i -e "s/pm.start_servers = 2/pm.start_servers = 3/g" /usr/local/etc/php-fpm.d/www.conf && \
sed -i -e "s/pm.min_spare_servers = 1/pm.min_spare_servers = 2/g" /usr/local/etc/php-fpm.d/www.conf && \
sed -i -e "s/pm.max_spare_servers = 3/pm.max_spare_servers = 4/g" /usr/local/etc/php-fpm.d/www.conf && \
sed -i -e "s/pm.max_requests = 500/pm.max_requests = 200/g" /usr/local/etc/php-fpm.d/www.conf && \
mkdir -p /var/www/cache && \
mkdir -p /var/www/cache/testing/sessions /var/www/cache/production/sessions /var/www/cache/development/sessions \
/var/www/cache/testing/twig /var/www/cache/production/twig /var/www/cache/development/twig && \
chgrp -R www-data /var/lib/nginx /var/www/web/uploads /var/www/cache /var/www/log && \
chmod -R ug+rwx /var/lib/nginx /var/www/web/uploads /var/www/cache /var/www/log && \
cp /var/www/config/$CFP_ENV.yml.dist /var/www/config/$CFP_ENV.yml && \
rm -fr /var/www/html /var/www/localhost

COPY ./.docker/script/ /var/www/script/

WORKDIR /var/www

RUN composer global require hirak/prestissimo && \
composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
21 changes: 21 additions & 0 deletions .docker/nginx/opencfp.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
server {
index index.php index.html;
server_name opencfp.local;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /srv/application/web;

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

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
26 changes: 0 additions & 26 deletions .docker/script/bootstrap

This file was deleted.

19 changes: 0 additions & 19 deletions .docker/script/setup

This file was deleted.

21 changes: 0 additions & 21 deletions .docker/script/test

This file was deleted.

20 changes: 0 additions & 20 deletions .docker/script/update

This file was deleted.

39 changes: 1 addition & 38 deletions DOCKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,6 @@ development environment, you need to follow the following steps:
- "CFP_DB_PASS=root"
```

* Modify the `app.volumes` section to look like the following:

```
volumes:
- ./:/var/www
- ./config/docker.yml.dist:/var/www/config/development.yml
- ./.docker/script:/var/www/script
```

The most important section is the `app.volumes` section, as it will make sure that we share our code with the docker
container.

The following, will create a shared volume with the container, so any file you create in your code will automatically
copied over to the container.

```
- ./:/var/www
```

Meanwhile, The following will create a copy from our `docker.yml.dist` file and call it `development.yml` file within
the container, you can remove this line and create your own `.yml` file.

```
- ./config/docker.yml.dist:/var/www/config/development.yml
```

The last part, is the important one, as the scripts was written in `bash` mean while the docker image depends on `alpine`
to make sure it has a small size (about **270MB** in total), so we needs to copy over the docker specific files to the
container, and replace the one on the container.

```
- ./.docker/script:/var/www/script
```

This will not overwrite the original `script` files, but will make our liver easier and will make the scripts
compatible with `sh`.

## Run Docker

Now all you have to do is to run the following command:
Expand All @@ -72,4 +35,4 @@ and to stop your containers you can run:
$ docker-compose down
```

_PS_: You can access MySQL in the same way we described in the Docker section.
_PS_: You can access MySQL in the same way we described in the Docker section of README file.
21 changes: 12 additions & 9 deletions docker-compose.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ services:
- "CFP_DB_HOST=database"
- "CFP_DB_PASS=root"
volumes:
- ./config/docker.yml.dist:/var/www/config/production.yml
- ./:/srv/application
- ./config/docker.yml.dist:/srv/application/config/production.yml
working_dir: /srv/application

nginx:
image: nginx:latest
ports:
- "80:80"
networks:
- backend
- "8080:80"
volumes:
- ./:/srv/application
- ./.docker/nginx:/etc/nginx/conf.d
links:
- app

database:
image: mysql:5.7
Expand All @@ -24,13 +32,8 @@ services:
- "MYSQL_ROOT_PASSWORD=root"
ports:
- "3306:3306"
networks:
- backend
volumes:
- database:/var/lib/mysql

networks:
backend:

volumes:
database:
4 changes: 2 additions & 2 deletions script/bootstrap
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/bash
#!/bin/sh

# script/bootstrap: Resolve all dependencies that the application requires to run.

set -e

cd "$(dirname "$0")/.."

if [ "$CFP_ENV" = "" ]; then
if [ "x$CFP_ENV" = "x" ]; then
export CFP_ENV="development"
fi

Expand Down
4 changes: 2 additions & 2 deletions script/setup
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

# script/setup: Set up application for the first time after cloning, or set it
# back to the initial first unused state.
Expand All @@ -9,7 +9,7 @@ cd "$(dirname "$0")/.."

script/bootstrap

if [ "$CFP_ENV" = "" ]; then
if [ "x$CFP_ENV" = "x" ]; then
export CFP_ENV="development"
fi

Expand Down
2 changes: 1 addition & 1 deletion script/test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

# script/test: Run test suite for application. Optionally pass in a path to an
# individual test file to run a single test.
Expand Down
4 changes: 2 additions & 2 deletions script/update
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

# script/update: Update application to run for its current checkout.

Expand All @@ -8,7 +8,7 @@ cd "$(dirname "$0")/.."

script/bootstrap

if [ "$CFP_ENV" = "" ]; then
if [ "x$CFP_ENV" = "x" ]; then
export CFP_ENV="development"
fi

Expand Down

0 comments on commit e8cce1b

Please sign in to comment.