Skip to content

Commit

Permalink
add images to dockerhub
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanbarlog committed Dec 9, 2017
1 parent 22aa95d commit 165186e
Show file tree
Hide file tree
Showing 18 changed files with 163 additions and 130 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.idea/
*/.composer
*/volumes/
project/phpunit/
*/env/docker.env
Expand Down
39 changes: 16 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ Following script will:
- fix file permissions

```bash
./ops init {domain name}
./ops init
```

You need to specify `{domain name}` for instance `dev.project`. For further information please read the `init` file

### parameters.yml.dist

Parameters in `parameters.yml.dist` should look like this:
Expand Down Expand Up @@ -68,26 +66,21 @@ You can remove any other code from `app_dev.php` and `app.php` which is related
The project provides `docker-compose` wrapper which can be invoked by `./ops`. Here are commands which can be used:

```bash
./ops init {domain} # initializes the project from scratch
./ops up # brings containers up
./ops stop # stops containers
./ops down # stops and removes containers
./ops bin/console # runs Symfony's bin/console within cli container
./ops composer # runs composer within cli container
./ops npm # runs npm within node container
./ops encore # runs encore within cli container (you need to install encore and set-up your project for proper use with Symfony's webpack first)
./ops check-code # checks your src/ and tests/ with php-cs-fixer and phpmd utilities
./ops test # run tests with phpunit
./ops permissions # fixes permissions in var/ folder
./ops mysql # runs mysql within db container
./ops # wrapper for docker-compose - see docker-compose documentation
```

If you are having problems with permissions after running Symfony commands, please do run following command as root from your local machine (not docker container):

```bash
./ops permission
init - initializes the project from scratch
up - brings containers up
stop - stops containers
down - stops and removes containers
restart - stops, rebuilds and starts specified containers eg. '$0 restart nginx fpm' will restart nginx and fpm
bin/console - runs Symfony's bin/console within cli container
composer - runs composer within cli container
npm - runs npm within node container
encore - runs encore within cli container (you need to install encore and set-up your project for proper use with Symfony's webpack first)
cs - checks your src/ and tests/ with php-cs-fixer and phpmd utilities
test - run tests with phpunit
permissions - fixes permissions in var/ folder
mysql - connects to the database within db container
mysqldump - dumps the database to ./infrastructure/volumes/sqldump
compose - wrapper for docker-compose
```

### Add autocompletion for `ops`
Expand Down
36 changes: 22 additions & 14 deletions infrastructure/bin/fix-permissions
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
#!/usr/bin/env bash

set -e
OWNER=$USER
R=`id -Gn $USER | grep '\bwww-data\b'`

if [ "$EUID" -ne 0 ]; then
echo "Please run as root (sudo)"
exit
if [[ -z $R ]]; then
sudo usermod -a -G www-data $OWNER
fi

if [ "${SUDO_USER}" == "root" ]; then
echo "You need to run as sudo with regular user; not sudo su"
exit
fi
sudo chown -R www-data:www-data project/var
sudo chmod -R 0775 project/var

chown -R 33:33 project/var/cache
chown -R 33:33 project/var/logs
mkdir -p project/vendor
sudo chown -R www-data:www-data project/vendor
sudo chmod -R 0775 project/vendor

# sessions can be stored in database
if [ -d "project/var/sessions" ]; then
chown -R 33:33 project/var/sessions
fi
mkdir -p project/bin
sudo chown -R www-data:www-data project/bin
sudo chmod -R 0775 project/bin

sudo chown -R www-data:www-data project/web
sudo chmod -R 0775 project/web

mkdir -p project/.composer
sudo chown -R www-data:www-data project/.composer
sudo chmod -R 0775 project/.composer

sudo chown -R www-data:www-data project/composer.lock
sudo chmod -R 0775 project/composer.lock
5 changes: 3 additions & 2 deletions infrastructure/bin/init
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ fi
echo -e "\e[30;48;5;82m STARTING DOCKER CONTAINERS \e[0m"
sudo -u ${SUDO_USER} ./ops up

echo -e "\e[30;48;5;82m FIXING PERMISSIONS \e[0m"
sudo -u ${SUDO_USER} ./ops permissions

echo -e "\e[30;48;5;82m INSTALLING COMPOSER \e[0m"
sudo -u ${SUDO_USER} cp project/app/config/parameters.yml.dist project/app/config/parameters.yml
sudo -u ${SUDO_USER} ./ops composer install

echo -e "\e[30;48;5;82m INITIALIZE DATABASE \e[0m"
sudo -u ${SUDO_USER} ./ops bin/console d:d:c --if-not-exists
sudo -u ${SUDO_USER} ./ops bin/console d:s:u --force

./infrastructure/bin/fix-permissions
13 changes: 8 additions & 5 deletions infrastructure/docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
version: '2'
services:
db:
build: docker-images/mysql
image: everlutionsk/mysql:5.7.20
ports:
- "0.0.0.0:${DB_PORT}:3306"
- "0.0.0.0:$DOCKER_DB_PORT:3306"
tty: true
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: ${DB_USER}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_DATABASE: ${DB_NAME}
MYSQL_ROOT_PASSWORD: ${DOCKER_DB_ROOT_PASSWORD}
volumes:
- "./volumes/mysql/:/var/lib/mysql"
- "./volumes/sqldump/:/sqldump"
working_dir: /sqldump
restart: unless-stopped

fpm:
build: docker-images/fpm-dev
image: everlutionsk/fpm-dev:7.1.12

test:
image: everlutionsk/php-test
Expand All @@ -28,4 +31,4 @@ services:
adminer:
image: adminer
ports:
- "8080:8080"
- "$DOCKER_ADMINER_PORT:8080"
20 changes: 10 additions & 10 deletions infrastructure/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
version: '2'
services:
code:
build: docker-images/code
image: everlutionsk/code:latest
volumes:
- "../project:/var/www"

fpm:
build: docker-images/fpm
image: everlutionsk/fpm:7.1.12
working_dir: /var/www
volumes_from:
- code
Expand All @@ -15,7 +15,7 @@ services:
restart: unless-stopped

cli:
build: docker-images/cli
image: everlutionsk/cli:7.1.12
working_dir: /var/www
tty: true
volumes_from:
Expand All @@ -38,23 +38,23 @@ services:
build:
context: docker-images/nginx
args:
ENV: ${APP_ENV}
DOMAIN: ${APP_DOMAIN}
USER: ${BASE_AUTH_USER}
PASSWORD: ${BASE_AUTH_PASSWORD}
ENV: ${DOCKER_INFRASTRUCTURE_ENV}
DOMAIN: ${NGINX_DOMAIN}
USER: ${NGINX_BASE_AUTH_USER}
PASSWORD: ${NGINX_BASE_AUTH_PASSWORD}
working_dir: /var/www
volumes_from:
- code
ports:
- "${APP_PORT}:80"
- "$DOCKER_NGINX_PORT:80"
volumes:
- "./volumes/nginx/:/var/log/nginx"
restart: unless-stopped

es:
build: docker-images/es
image: everlutionsk/es:2.4.5
ports:
- "${ES_PORT}:9200"
- "$DOCKER_ES_PORT:9200"
volumes:
- "./volumes/es/:/usr/share/elasticsearch/data"
- "./volumes/es/logs/:/usr/share/elasticsearch/log"
19 changes: 19 additions & 0 deletions infrastructure/docker-images/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

if [ $# != 2 ]; then
echo "Provide image as first argument and tag as second"
exit
fi

IMAGE=$1
TAG=$2

if [ ! -f ./$IMAGE/Dockerfile ]; then
echo "$IMAGE/Dockerfile does not exists - cannot build"
exit
fi

cd $IMAGE
docker build . -t everlutionsk/$IMAGE
docker tag everlutionsk/$IMAGE everlutionsk/$IMAGE:$TAG
docker push everlutionsk/$IMAGE:$TAG
9 changes: 7 additions & 2 deletions infrastructure/docker-images/cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM php:7.1.9-cli
FROM php:7.1.12-cli

MAINTAINER Ivan Barlog <[email protected]>

RUN apt-get update && apt-get install -y --no-install-recommends \
libmcrypt-dev \
Expand All @@ -8,7 +10,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
git \
zlib1g-dev \
libpcre3-dev \
locales
locales \
vim

RUN docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd
RUN docker-php-ext-configure mysqli --with-mysqli=mysqlnd
Expand All @@ -21,4 +24,6 @@ RUN dpkg-reconfigure -f noninteractive locales
# Add composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

RUN usermod -u 1000 www-data

CMD ["php", "-a"]
4 changes: 3 additions & 1 deletion infrastructure/docker-images/code/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
FROM busybox:1.26.2-uclibc
FROM busybox:1.27.2-uclibc

MAINTAINER Ivan Barlog <[email protected]>

volume /var/www
2 changes: 2 additions & 0 deletions infrastructure/docker-images/es/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
FROM elasticsearch:2.4.5

MAINTAINER Ivan Barlog <[email protected]>

COPY config.yml /usr/share/elasticsearch/config/elasticsearch.yml
22 changes: 2 additions & 20 deletions infrastructure/docker-images/fpm-dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,10 @@
FROM php:7.1.9-fpm
FROM everlutionsk/fpm:7.1.12

RUN apt-get update && apt-get install -y --no-install-recommends \
libmcrypt-dev \
libicu-dev \
libcurl4-openssl-dev \
curl \
git \
libpcre3-dev \
locales

RUN docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd
RUN docker-php-ext-configure mysqli --with-mysqli=mysqlnd
RUN docker-php-ext-install mcrypt pdo_mysql mysqli intl mbstring opcache

# Reconfigure locales
RUN locale-gen en_US en_US.UTF-8 sk_SK sk_SK.UTF-8
RUN dpkg-reconfigure -f noninteractive locales
MAINTAINER Ivan Barlog <[email protected]>

# Configure xdebug
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug
COPY ext-xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

COPY app.ini /usr/local/etc/php/conf.d/app.ini
COPY app.pool.conf /usr/local/etc/php/pool.d/app.pool.conf

CMD ["php-fpm"]
6 changes: 5 additions & 1 deletion infrastructure/docker-images/fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM php:7.1.9-fpm
FROM php:7.1.12-fpm

MAINTAINER Ivan Barlog <[email protected]>

RUN apt-get update && apt-get install -y --no-install-recommends \
libmcrypt-dev \
Expand All @@ -20,4 +22,6 @@ RUN dpkg-reconfigure -f noninteractive locales
COPY app.ini /usr/local/etc/php/conf.d/app.ini
COPY app.pool.conf /usr/local/etc/php/pool.d/app.pool.conf

RUN usermod -u 1000 www-data

CMD ["php-fpm"]
4 changes: 3 additions & 1 deletion infrastructure/docker-images/mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM mysql:5.7
FROM mysql:5.7.20

MAINTAINER Ivan Barlog <[email protected]>

RUN mkdir /sqldump

Expand Down
14 changes: 7 additions & 7 deletions infrastructure/docker-images/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
FROM nginx:1.13.5
FROM nginx:1.13.7

ARG ENV=dev
ARG DOMAIN=dev.symfony
ARG USER=user
ARG PASSWORD=password
MAINTAINER Ivan Barlog <[email protected]>

ARG ENV
ARG DOMAIN
ARG USER
ARG PASSWORD

ENV DOMAIN $DOMAIN
ENV USER $USER
Expand All @@ -29,5 +31,3 @@ RUN sed -i "s/{password}/$PASSWORD/g" /etc/nginx/.htpasswd

# Run nginx in foreground.
CMD ["nginx", "-g", "daemon off;"]


2 changes: 1 addition & 1 deletion infrastructure/docker-images/nginx/prod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ server {

# blacklist urls which shouldn't be visible to normal user
error_page 404 /404.html;
location ~ ^/(api-doc|app_dev\.php|_api|_profiler|app_dev\.php/_profiler|_wdt|app_dev\.php/_wdt) {
location ~ ^/(api-doc|app_dev\.php|config\.php|_api|_profiler|app_dev\.php/_profiler|_wdt|app_dev\.php/_wdt) {
access_log off;
return 404;
}
Expand Down
26 changes: 15 additions & 11 deletions infrastructure/env/docker.env.dist
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# environment - dev|stg|prod
export SYMFONY_APP_ENV=dev
export DOCKER_INFRASTRUCTURE_ENV=dev

# port where the nginx is listening
export SYMFONY_APP_PORT=80

# elasticsearch port
export SYMFONY_ES_PORT=9200

# mysql port (applicable for dev environment)
export SYMFONY_DB_PORT=3306
export DOCKER_NGINX_PORT=80

# domain which will be nginx listen for
export SYMFONY_APP_DOMAIN=dev.symfony
export NGINX_DOMAIN=dev.symfony

# base auth user:password for nginx - by default needed only for stg environment
export SYMFONY_BASE_AUTH_USER=user
export SYMFONY_BASE_AUTH_PASSWORD=password
export NGINX_BASE_AUTH_USER=user
export NGINX_BASE_AUTH_PASSWORD=password

# adminer
export DOCKER_ADMINER_PORT=8080

# mysql
export DOCKER_DB_ROOT_PASSWORD=root
export DOCKER_DB_PORT=3306

# elastic
export DOCKER_ES_PORT=9200
Loading

0 comments on commit 165186e

Please sign in to comment.