Skip to content
This repository was archived by the owner on Jul 25, 2023. It is now read-only.

Commit 5e55413

Browse files
committed
Add Magento 2 services
1 parent 191456e commit 5e55413

17 files changed

+567
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/composer.env
2+
/magento

7.0-cli/Dockerfile

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#
2+
# Command line, PHP 7.0, Magento 2 compatible container.
3+
#
4+
# Credit to Mark Shust <[email protected]> for the basis of this
5+
# Dockerfile in the https://github.com/mageinferno/docker-magento2-php project.
6+
#
7+
8+
FROM php:7.0-cli
9+
10+
MAINTAINER Nick Jones <[email protected]>
11+
12+
# Install dependencies
13+
RUN apt-get update \
14+
&& apt-get install -y \
15+
cron \
16+
libfreetype6-dev \
17+
libicu-dev \
18+
libjpeg62-turbo-dev \
19+
libmcrypt-dev \
20+
libpng12-dev \
21+
libxslt1-dev
22+
23+
# Configure the gd library
24+
RUN docker-php-ext-configure \
25+
gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
26+
27+
# Install required PHP extensions
28+
RUN docker-php-ext-install \
29+
gd \
30+
intl \
31+
mbstring \
32+
mcrypt \
33+
pdo_mysql \
34+
xsl \
35+
zip
36+
37+
# Get composer installed to /usr/local/bin/composer
38+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
39+
40+
VOLUME /root/.composer/cache
41+
42+
ADD bin/* /usr/local/bin/
43+
ADD etc/php.ini /usr/local/etc/php/conf.d/zz-magento.ini
44+
45+
ENV PHP_MEMORY_LIMIT 2G
46+
ENV MAGENTO_ROOT /magento
47+
ENV COMPOSER_GITHUB_TOKEN ""
48+
ENV COMPOSER_MAGENTO_USERNAME ""
49+
ENV COMPOSER_MAGENTO_PASSWORD ""
50+
ENV DEBUG false
51+
ENV IS_OSX false
52+
53+
ENTRYPOINT ["/usr/local/bin/docker-environment"]
54+
55+
CMD ["bash"]

7.0-cli/bin/docker-environment

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
[ "$DEBUG" = "true" ] && set -x
4+
5+
# If we're using OSX then we need to mess with the permissions
6+
if [[ "$IS_OSX" = "true" ]]; then
7+
echo "OSX flag is set, changing www-data uid/gid"
8+
9+
usermod -u 501 www-data
10+
groupmod -g 9920 dialout # Move dialout from 20 to make room for www-data
11+
groupmod -g 20 www-data
12+
fi
13+
14+
# Ensure our Magento directory exists
15+
mkdir -p $MAGENTO_ROOT
16+
chown www-data:www-data $MAGENTO_ROOT
17+
18+
# Configure PHP
19+
[ ! -z "${PHP_MEMORY_LIMIT}" ] && sed -i "s/!PHP_MEMORY_LIMIT!/${PHP_MEMORY_LIMIT}/" /usr/local/etc/php/conf.d/zz-magento.ini
20+
21+
# Configure composer
22+
[ ! -z "${COMPOSER_GITHUB_TOKEN}" ] && \
23+
composer config --global github-oauth.github.com $COMPOSER_GITHUB_TOKEN
24+
25+
[ ! -z "${COMPOSER_MAGENTO_USERNAME}" ] && \
26+
composer config --global http-basic.repo.magento.com \
27+
$COMPOSER_MAGENTO_USERNAME $COMPOSER_MAGENTO_PASSWORD
28+
29+
exec "$@"

7.0-cli/bin/magento-command

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
[ "$DEBUG" = "true" ] && set -x
4+
5+
MAGENTO_COMMAND="$MAGENTO_ROOT/bin/magento"
6+
7+
chmod +x $MAGENTO_COMMAND
8+
su -c "$MAGENTO_COMMAND $*" -s /bin/bash www-data

7.0-cli/bin/magento-installer

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
[ "$DEBUG" = "true" ] && set -x
4+
5+
# Get composer auth information into an environment variable to avoid "you need
6+
# to be using an interactive terminal to authenticate".
7+
COMPOSER_AUTH=`cat /root/.composer/auth.json`
8+
9+
composer --version
10+
11+
echo "Creating Magento ($M2SETUP_VERSION) project from composer"
12+
13+
composer create-project \
14+
--repository-url=https://repo.magento.com/ \
15+
magento/project-community-edition=$M2SETUP_VERSION \
16+
--no-interaction \
17+
$MAGENTO_ROOT
18+
19+
echo "Install Magento"
20+
21+
php /magento/bin/magento setup:install \
22+
--db-host=$M2SETUP_DB_HOST \
23+
--db-name=$M2SETUP_DB_NAME \
24+
--db-user=$M2SETUP_DB_USER \
25+
--db-password=$M2SETUP_DB_PASSWORD \
26+
--base-url=$M2SETUP_BASE_URL \
27+
--admin-firstname=$M2SETUP_ADMIN_FIRSTNAME \
28+
--admin-lastname=$M2SETUP_ADMIN_LASTNAME \
29+
--admin-email=$M2SETUP_ADMIN_EMAIL \
30+
--admin-user=$M2SETUP_ADMIN_USER \
31+
--admin-password=$M2SETUP_ADMIN_PASSWORD
32+
33+
php /magento/bin/magento index:reindex
34+
php /magento/bin/magento setup:static-content:deploy
35+
36+
echo "Fixing file permissions.."
37+
38+
sed -i 's/0770/0775/g' $MAGENTO_ROOT/vendor/magento/framework/Filesystem/DriverInterface.php
39+
sed -i 's/0660/0664/g' $MAGENTO_ROOT/vendor/magento/framework/Filesystem/DriverInterface.php
40+
41+
find $MAGENTO_ROOT/pub -type f -exec chmod 664 {} \;
42+
find $MAGENTO_ROOT/pub -type d -exec chmod 775 {} \;
43+
find $MAGENTO_ROOT/var/generation -type d -exec chmod g+s {} \;
44+
45+
chown -R www-data:www-data $MAGENTO_ROOT
46+
47+
echo "Installation complete"

7.0-cli/etc/php.ini

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
; This file is created automatically by the docker build
2+
3+
memory_limit = !PHP_MEMORY_LIMIT! ; Variable: PHP_MEMORY_LIMIT

7.0-fpm/Dockerfile

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#
2+
# FPM, PHP 7.0, Magento 2 compatible container.
3+
#
4+
# Credit to Mark Shust <[email protected]> for the basis of this
5+
# Dockerfile in the https://github.com/mageinferno/docker-magento2-php project.
6+
#
7+
8+
FROM php:7.0-fpm
9+
10+
MAINTAINER Nick Jones <[email protected]>
11+
12+
# Install dependencies
13+
RUN apt-get update \
14+
&& apt-get install -y \
15+
cron \
16+
libfreetype6-dev \
17+
libicu-dev \
18+
libjpeg62-turbo-dev \
19+
libmcrypt-dev \
20+
libpng12-dev \
21+
libxslt1-dev
22+
23+
# Configure the gd library
24+
RUN docker-php-ext-configure \
25+
gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
26+
27+
# Install required PHP extensions
28+
RUN docker-php-ext-install \
29+
gd \
30+
intl \
31+
mbstring \
32+
mcrypt \
33+
pdo_mysql \
34+
xsl \
35+
zip
36+
37+
VOLUME /root/.composer/cache
38+
39+
ADD bin/docker-environment /usr/local/bin/
40+
ADD etc/php.ini /usr/local/etc/php/conf.d/zz-magento.ini
41+
ADD etc/php-fpm.conf /usr/local/etc/
42+
43+
ENV PHP_MEMORY_LIMIT 2G
44+
ENV MAGENTO_ROOT /magento
45+
ENV MAGENTO_RUN_MODE developer
46+
ENV DEBUG false
47+
ENV IS_OSX false
48+
49+
ENTRYPOINT ["/usr/local/bin/docker-environment"]
50+
CMD ["php-fpm", "-F"]

7.0-fpm/bin/docker-environment

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
[ "$DEBUG" = "true" ] && set -x
4+
5+
# If we're using OSX then we need to mess with the permissions
6+
if [[ "$IS_OSX" = "true" ]]; then
7+
echo "OSX flag is set, changing www-data uid/gid"
8+
9+
usermod -u 501 www-data
10+
groupmod -g 9920 dialout # Move dialout from 20 to make room for www-data
11+
groupmod -g 20 www-data
12+
fi
13+
14+
# Configure PHP
15+
[ ! -z "${PHP_MEMORY_LIMIT}" ] && sed -i "s/!PHP_MEMORY_LIMIT!/${PHP_MEMORY_LIMIT}/" /usr/local/etc/php/conf.d/zz-magento.ini
16+
17+
# Configure PHP-FPM
18+
[ ! -z "${MAGENTO_RUN_MODE}" ] && sed -i "s/!MAGENTO_RUN_MODE!/${MAGENTO_RUN_MODE}/" /usr/local/etc/php-fpm.conf
19+
20+
exec "$@"

7.0-fpm/etc/php-fpm.conf

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; This file is created automatically by the docker build
2+
3+
[global]
4+
5+
error_log = /proc/self/fd/2
6+
daemonize = no
7+
8+
[www]
9+
10+
; if we send this to /proc/self/fd/1, it never appears
11+
access.log = /proc/self/fd/2
12+
13+
user = www-data
14+
group = www-data
15+
16+
listen = [::]:9000
17+
18+
pm = dynamic
19+
pm.max_children = 10
20+
pm.start_servers = 4
21+
pm.min_spare_servers = 2
22+
pm.max_spare_servers = 6
23+
24+
env[MAGE_MODE] = !MAGENTO_RUN_MODE!; # Variable: MAGENTO_RUN_MODE
25+
26+
clear_env = no
27+
28+
; Ensure worker stdout and stderr are sent to the main error log.
29+
catch_workers_output = yes

7.0-fpm/etc/php.ini

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
; This file is created automatically by the docker build
2+
3+
memory_limit = !PHP_MEMORY_LIMIT! ; Variable: PHP_MEMORY_LIMIT

Readme.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#Magento 2 Docker
2+
3+
## Quick Start
4+
5+
cp composer.env.sample composer.env
6+
# ..put the correct tokens into composer.env
7+
8+
docker-compose run cli magento-installer
9+
docker-compose up -d
10+
docker-compose restart
11+
12+
## Configuration
13+
14+
Configuration is driven through environment variables. A comprehensive list of the environment variables used can be found in each `Dockerfile` and the commands in each `bin/` directory.
15+
16+
* `PHP_MEMORY_LIMIT` - The memory limit to be set in the `php.ini`
17+
* `MAGENTO_ROOT` - The directory to which Magento should be installed
18+
* `MAGENTO_RUN_MODE` - Valid values, as defined in `Magento\Framework\App\State`: `developer`, `production`, `default`.
19+
* `COMPOSER_GITHUB_TOKEN` - Your [GitHub OAuth token](https://getcomposer.org/doc/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens), should it be needed
20+
* `COMPOSER_MAGENTO_USERNAME` - Your Magento Connect public authentication key ([how to get](http://devdocs.magento.com/guides/v2.0/install-gde/prereq/connect-auth.html))
21+
* `COMPOSER_MAGENTO_PASSWORD` - Your Magento Connect private authentication key
22+
* `DEBUG` - Toggles tracing in the bash commands when exectued; nothing to do with Magento`
23+
* `IS_OSX` - If this is set to "true" then the uid and gid of `www-data` will be modified in the container
24+
25+
A sample `docker-compose.yml` is provided in this repository.
26+
27+
## CLI Usage
28+
29+
A number of commands are baked into the image and are available on the `$PATH`. These are:
30+
31+
* `magento-command` - Provides a user-safe wrapper around the `bin/magento` command.
32+
* `magento-installer` - Installs and configures Magento into the directory defined in the `$MAGENTO_ROOT` environment variable.
33+
34+
It's recommended that you mount an external folder to `/root/.composer/cache`, otherwise you'll be waiting all day for Magento to download every time the container is booted.
35+
36+
CLI commands can be triggered by running:
37+
38+
docker-compose run cli magento-installer
39+
40+
Shell access to a CLI container can be triggered by running:
41+
42+
docker-compose run cli bash
43+
44+
## Implementation Notes
45+
46+
* In order to achieve a sane environment for executing commands in, a `docker-environment` script is included as the `ENTRYPOINT` in the container.
47+
48+
## Credits
49+
50+
Thanks to [Mark Shust](https://twitter.com/markshust) for his work on [docker-magento2-php](https://github.com/mageinferno/docker-magento2-php) that was used as a basis for this implementation. You solved a lot of the problems so I didn't need to!

composer.env.sample

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
COMPOSER_GITHUB_TOKEN=0000000000000000000000000000000000000000
2+
COMPOSER_MAGENTO_USERNAME=00000000000000000000000000000000
3+
COMPOSER_MAGENTO_PASSWORD=00000000000000000000000000000000

docker-compose.yml

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
version: "2"
2+
services:
3+
web:
4+
# image: meanbee/magento2-nginx
5+
build:
6+
context: ./nginx
7+
ports:
8+
- "80:80"
9+
links:
10+
- fpm
11+
- db
12+
volumes_from:
13+
- appdata
14+
env_file:
15+
- ./global.env
16+
environment:
17+
- VIRTUAL_HOST=magento2.docker
18+
19+
fpm:
20+
# image: meanbee/magento2-php-fpm:7.0
21+
build:
22+
context: ./7.0-fpm
23+
ports:
24+
- 9000
25+
links:
26+
- db
27+
volumes_from:
28+
- appdata
29+
env_file:
30+
- ./global.env
31+
32+
db:
33+
image: mariadb:10
34+
ports:
35+
- 3306
36+
volumes_from:
37+
- dbdata
38+
environment:
39+
- MYSQL_ROOT_PASSWORD=magento2
40+
- MYSQL_DATABASE=magento2
41+
- MYSQL_USER=magento2
42+
- MYSQL_PASSWORD=magento2
43+
44+
cli:
45+
# image: meanbee/magento2-php-fpm:7.0
46+
build:
47+
context: ./7.0-cli
48+
links:
49+
- db
50+
volumes:
51+
- ~/.composer/cache:/root/.composer/cache
52+
volumes_from:
53+
- appdata
54+
env_file:
55+
- ./global.env
56+
- ./composer.env
57+
environment:
58+
- M2SETUP_DB_HOST=db
59+
- M2SETUP_DB_NAME=magento2
60+
- M2SETUP_DB_USER=magento2
61+
- M2SETUP_DB_PASSWORD=magento2
62+
- M2SETUP_BASE_URL=http://magento2.docker/
63+
- M2SETUP_ADMIN_FIRSTNAME=Admin
64+
- M2SETUP_ADMIN_LASTNAME=User
65+
66+
- M2SETUP_ADMIN_USER=admin
67+
- M2SETUP_ADMIN_PASSWORD=password1
68+
- M2SETUP_VERSION=2.0.2
69+
# - M2SETUP_USE_SAMPLE_DATA=true
70+
71+
appdata:
72+
image: tianon/true
73+
volumes:
74+
- ./magento:/magento
75+
76+
dbdata:
77+
image: tianon/true
78+
volumes:
79+
- /var/lib/mysql

global.env

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
MAGENTO_RUN_MODE=developer
2+
PHP_MEMORY_LIMIT=2048M
3+
IS_OSX=true
4+
DEBUG=false

0 commit comments

Comments
 (0)