Skip to content

Instantly share code, notes, and snippets.

@sveneisenschmidt
Last active February 20, 2023 12:59
Show Gist options
  • Star 26 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save sveneisenschmidt/35e9c45e15c0f8d395e17a996415a669 to your computer and use it in GitHub Desktop.
Save sveneisenschmidt/35e9c45e15c0f8d395e17a996415a669 to your computer and use it in GitHub Desktop.
{
"require": {
"php": ">=5.5",
"ext-intl" : "*",
"silex/silex": "~1.2",
"twig/twig": "~1.15",
"symfony/twig-bridge": "~2.5",
"symfony/security": "~2.5",
"symfony/yaml": ">=2.5,<2.7",
"symfony/form": "~2.5",
"symfony/validator": "~2.5",
"symfony/config": "~2.5",
"symfony/security-csrf": "~2.5",
"symfony/locale": "~2.5",
"symfony/doctrine-bridge": "~2.5",
"symfony/translation": "~2.5",
"igorw/config-service-provider": "~1.2",
"incenteev/composer-parameter-handler": "~2.0",
"dflydev/doctrine-orm-service-provider": "~1.0",
"drewm/mailchimp-api": "~1.0",
"swiftmailer/swiftmailer": "~4.1",
"monolog/monolog": "~1.12",
"salva/jshrink-bundle": "^1.1",
"asm89/twig-cache-extension": "~1.0",
"silex/web-profiler": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"nelmio/alice": "~2.0",
"guzzle/guzzle": "~3.9",
"fabpot/goutte": "~1.0",
"behat/behat": "~2.4",
"behat/mink": "~1.4",
"behat/mink-extension": "*",
"behat/mink-goutte-driver": "*",
"behat/mink-selenium2-driver": "~1.2"
}
}
# Website Development Environment
version: '2'
services:
# Application Server: Website
php:
build:
context: ./
dockerfile: Dockerfile-php
command: "php -S 0.0.0.0:80 -t web web/index.php"
ports:
- "8091:80"
volumes_from:
- sync
working_dir: /var/www
links:
- db:db
- sync:sync
environment:
APPLICATION_ENV: dev
stdin_open: true
tty: true
# Web Development Tools
tools:
build:
context: ./
dockerfile: Dockerfile-tools
volumes_from:
- sync
working_dir: /src
links:
- db:db
- sync:sync
stdin_open: true
tty: true
# Database
db:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: xyz
# Synchronization
sync:
build:
context: ./
dockerfile: Dockerfile-sync
command: "lsyncd -delay 1 -nodaemon -rsync /src /var/www"
volumes:
- /var/www
- "./:/src"
working_dir: /src
stdin_open: true
tty: true
FROM ubuntu:16.04
RUN PACKAGES="\
php-cli \
php-mysql \
php-intl \
php-xml \
php-curl \
php-dom \
" && \
apt-get update && \
apt-get install -y $PACKAGES && \
apt-get autoremove --purge -y && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
FROM ubuntu:16.04
RUN PACKAGES="\
rsync \
lsyncd \
" && \
apt-get update && \
apt-get install -y $PACKAGES && \
apt-get autoremove --purge -y && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
FROM ubuntu:16.04
RUN PACKAGES="\
nodejs \
nodejs-legacy \
npm \
php-cli \
php-mysql \
php-intl \
php-xml \
php-curl \
php-dom \
wget \
zip \
unzip \
git \
libfreetype6 \
libfontconfig \
" && \
apt-get update && \
apt-get install -y $PACKAGES && \
apt-get autoremove --purge -y && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN cd /tmp && \
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php composer-setup.php --install-dir=/usr/bin --filename=composer && \
php -r "unlink('composer-setup.php');" && \
rm -rf /tmp/*
@SpiralOutDotEu
Copy link

Amazing what you have done with sync!
Amazing speed increase!
Thank you for sharing!

@SpiralOutDotEu
Copy link

It seems that this methods has some problems if you are working the shared folder with git.
The delay in transfer makes some trouble when you switch between brunches.
Have you noticed similar behavior?

@sveneisenschmidt
Copy link
Author

sveneisenschmidt commented Nov 25, 2016

@SpiralOutDotEu Unfortunately yes but I have a different solution now (which leads to loading times under 100ms):

docker-compose.yml

version: "2"
services:
    # Web Server
    web:
        build:
          context: .
          dockerfile: docker/Dockerfile-web
        command: "php bin/console server:run 0.0.0.0:80"
        ports:
            - "9406:80"
        volumes:
            - ./:/data
            - app-var-cache:/data/var/cache
            - app-var-sessions:/data/var/sessions
            - app-var-logs:/data/var/logs
            - app-vendor:/data/vendor
            - app-node_modules:/data/node_modules
        links:
            - db
        working_dir: "/data"
        environment:
            APPLICATION_ENV: dev

    # Command Line Tools
    cli:
        build:
            context: .
            dockerfile: docker/Dockerfile-cli
        volumes:
            - ./:/data
            - app-var-cache:/data/var/cache
            - app-var-sessions:/data/var/sessions
            - app-var-logs:/data/var/logs
            - app-vendor:/data/vendor
            - app-node_modules:/data/node_modules
        links:
            - db
        working_dir: "/data"

    # Database
    db:
        image: mysql:5.7
        environment:
            MYSQL_ROOT_PASSWORD: root
            MYSQL_DATABASE: dev
        ports:
            - "4407:3306"

volumes:
    app-var-cache:
    app-var-sessions:
    app-var-logs:
    app-vendor:
    app-node_modules:

I re-mount the heavy folders to docker volumes and rsync them manually into a .data folder so my IDE can index my files.

Makefile

install-dependencies:
	# Create cache, session and logs directories
	@$(MKDIR) -p vendor var/logs var/cache var/sessions || true
	# Install php dependencies
	@$(COMPOSE) run --rm cli bash -c 'composer install'
	# Install node dependencies
	@$(COMPOSE) run --rm cli bash -c 'yarn'
	@$(COMPOSE) run --rm cli bash -c 'npm rebuild node-sass'

sync-dependencies:
    # Create .data directory
	@$(MKDIR) -p .data || true
    # vendor
	@$(COMPOSE) run --rm cli bash -c 'rsync -rtuz --delete-delay --progress --exclude="bin/" vendor/ .data/vendor'
    # node_modules
	@$(COMPOSE) run --rm cli bash -c 'rsync -rtuz --delete-delay --progress --exclude=".bin/" --exclude=".cache/" node_modules/ .data/node_modules'

install: install-dependencies sync-dependencies
	@$(COMPOSE) run --rm cli bash -c 'rm  -rf var/cache/*'

@bocharsky-bw
Copy link

bocharsky-bw commented Dec 14, 2016

Hey guys,

As I think there's a tool that provides a similar behavior in a bit standardized way: http://docker-sync.io/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment