Skip to content

Just type "docker-compose up" to install a Flex project (major refactoring) #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docker/nginx/.dockerignore → .dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
**/*.log
**/*.md
**/._*
**/.DS_Store
**/.gitignore
**/.gitattributes
**/Thumbs.db
.dockerignore
Dockerfile
docker-compose.yml
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
* text=auto
*.sh text eol=lf
docker/apache/start_safe_perms text eol=lf
30 changes: 13 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ RUN set -xe \
zlib-dev \
&& docker-php-ext-install \
intl \
pdo_mysql \
zip \
&& pecl install \
apcu-${APCU_VERSION} \
&& docker-php-ext-enable --ini-name 20-apcu.ini apcu \
&& docker-php-ext-enable --ini-name 05-opcache.ini opcache \
&& apk del .build-deps

###> recipes ###
###< recipes ###

COPY docker/app/php.ini /usr/local/etc/php/php.ini

COPY docker/app/install-composer.sh /usr/local/bin/docker-app-install-composer
RUN chmod +x /usr/local/bin/docker-app-install-composer

RUN set -xe \
&& apk add --no-cache --virtual .fetch-deps openssl \
&& docker-app-install-composer \
&& mv composer.phar /usr/local/bin/composer \
&& apk del .fetch-deps
&& mv composer.phar /usr/local/bin/composer

# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER 1
Expand All @@ -42,24 +42,20 @@ RUN composer global require "hirak/prestissimo:^0.3" --prefer-dist --no-progress

WORKDIR /srv/app

COPY composer.* ./
COPY . .
# Cleanup unneeded files
RUN rm -Rf docker/

# Download the Symfony skeleton
ENV SKELETON_COMPOSER_JSON https://raw.githubusercontent.com/symfony/skeleton/v3.3.2/composer.json
RUN [ -f composer.json ] || php -r "copy('$SKELETON_COMPOSER_JSON', 'composer.json');"

RUN mkdir -p \
var/cache \
var/logs \
var/sessions \
&& composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress --no-suggest \
RUN mkdir -p var/cache var/logs var/sessions \
&& composer install --prefer-dist --no-dev --no-progress --no-suggest --optimize-autoloader --classmap-authoritative --no-interaction \
&& composer clear-cache \
# Permissions hack because setfacl does not work on Mac and Windows
&& chown -R www-data var

COPY etc etc/
COPY src src/
COPY var var/
COPY web web/

RUN composer dump-autoload --optimize --classmap-authoritative --no-dev

COPY docker/app/docker-entrypoint.sh /usr/local/bin/docker-app-entrypoint
RUN chmod +x /usr/local/bin/docker-app-entrypoint

Expand Down
4 changes: 4 additions & 0 deletions Dockerfile.nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM nginx:1.13-alpine

COPY docker/nginx/conf.d /etc/nginx/conf.d/
COPY public /srv/app/public/
49 changes: 0 additions & 49 deletions composer.json

This file was deleted.

37 changes: 5 additions & 32 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,9 @@ services:
app:
build:
context: .
dockerfile: ./Dockerfile
#depends_on:
# - db
env_file:
- .env
volumes:
# Comment out the next line in production
- ./:/srv/app/:rw
# This is for assets:install
- ./web/:/srv/app/web/:rw
- ./:/srv/app:rw
# If you develop on Linux, comment out the following volumes to just use bind-mounted project directory from host
- /srv/app/var/
- /srv/app/var/cache/
Expand All @@ -23,31 +16,11 @@ services:

nginx:
build:
context: ./docker/nginx
dockerfile: ./Dockerfile
context: .
dockerfile: ./Dockerfile.nginx
volumes:
# Comment out the next line in production
- ./docker/nginx/conf.d:/etc/nginx/conf.d:ro
- ./web:/srv/app/web:ro
- ./public:/srv/app/public:ro
ports:
- "80:80"

# Uncomment the following lines to add a MySQL container
#db:
# build:
# context: ./docker/db
# dockerfile: ./Dockerfile
# environment:
# - MYSQL_DATABASE=app
# # You should definitely change the password in production
# - MYSQL_PASSWORD=symfony
# - MYSQL_RANDOM_ROOT_PASSWORD=true
# - MYSQL_USER=symfony
# volumes:
# - db-data:/var/lib/mysql:rw
# # You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
# # - ./docker/db/data:/var/lib/mysql:rw

volumes:
app-web: {}
#db-data: {}
- '80:80'
11 changes: 6 additions & 5 deletions docker/app/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ if [ "${1#-}" != "$1" ]; then
fi

if [ "$1" = 'php-fpm' ] || [ "$1" = 'bin/console' ]; then
if [ "$APP_ENV" = 'prod' ]; then
composer install --prefer-dist --no-dev --no-progress --no-suggest --optimize-autoloader --classmap-authoritative --no-interaction
else
composer install --prefer-dist --no-progress --no-suggest --no-interaction
fi
# The first time volumes are mounted, dependencies need to be reinstalled
if [ ! -f composer.json ]; then
rm -Rf vendor/*
php -r "copy('$SKELETON_COMPOSER_JSON', 'composer.json');"
composer install --prefer-dist --no-progress --no-suggest --no-interaction
fi

# Permissions hack because setfacl does not work on Mac and Windows
chown -R www-data var
Expand Down
2 changes: 1 addition & 1 deletion docker/app/install-composer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Origin: https://github.com/composer/composer/blob/master/doc/faqs/how-to-install-composer-programmatically.md
# Licence: MIT

EXPECTED_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must repeat this again. I don't see the point of us deviating from the official sample script here. The .fetch-deps do not end up in any of the image layers, so it has zero impact except for a very slightly longer build (does not make any practical difference).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we have already been through this before... laughs

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It reduces the complexity of the build process and the maintenance. As pointed out by Jordi, there is no point using the old method when using PHP 7+. And we're using PHP 7+.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It reduces the complexity of the build process and the maintenance.

Not really. wget is already provided by BusyBox. Installing openssl is required for HTTPS support. And that's it. I don't see where the complexity lies.

As pointed out by Jordi, there is no point using the old method when using PHP 7+. And we're using PHP 7+.

Agreed 100%. But we don't really gain anything by changing it. It only creates another maintenance issue, if anything. (Instead of just copy-and-paste from the official sample script, now we have our own modifications. 😆)

EXPECTED_SIGNATURE=$(php -r "echo trim(file_get_contents('https://composer.github.io/installer.sig'));")
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")

Expand Down
10 changes: 0 additions & 10 deletions docker/db/.dockerignore

This file was deleted.

1 change: 0 additions & 1 deletion docker/db/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions docker/db/Dockerfile

This file was deleted.

30 changes: 0 additions & 30 deletions docker/db/docker-healthcheck.sh

This file was deleted.

3 changes: 0 additions & 3 deletions docker/nginx/Dockerfile

This file was deleted.

11 changes: 7 additions & 4 deletions docker/nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
server {
root /srv/app/web;
resolver 127.0.0.11;
root /srv/app/public;

location / {
# try to serve file directly, fallback to app.php
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
#resolver 127.0.0.11;
#set $upstream_host app;
#fastcgi_pass $upstream_host:9000;
# Uncomment the previous lines and comment the next one to enable dynamic resolution (incompatible compatible with Kubernetes)
fastcgi_pass app:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
Expand All @@ -20,7 +23,7 @@ server {
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/app.php/some-path
# http://domain.tld/index.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
Expand Down
Empty file added public/.gitignore
Empty file.