Skip to content

Commit

Permalink
Add installation types - developer and integrator
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcheng1982 committed Feb 26, 2018
1 parent 1aefd81 commit 96a2aa4
Show file tree
Hide file tree
Showing 24 changed files with 422 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.bash_history
node_modules
54 changes: 54 additions & 0 deletions Dockerfile.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
FROM alexcheng/apache2-php7:{{phpVersion}}

Label maintainer="[email protected]"

ENV MAGENTO_VERSION {{magento2Version}}
ENV INSTALL_DIR /var/www/html
ENV COMPOSER_HOME /var/www/.composer/

RUN curl -sS https://getcomposer.org/installer | php \
&& mv composer.phar /usr/local/bin/composer
COPY ./auth.json $COMPOSER_HOME

RUN requirements="libpng12-dev libmcrypt-dev libmcrypt4 libcurl3-dev libfreetype6 libjpeg-turbo8 libjpeg-turbo8-dev libpng12-dev libfreetype6-dev libicu-dev libxslt1-dev" \
&& apt-get update \
&& apt-get install -y $requirements \
&& rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd \
&& docker-php-ext-install mcrypt \
&& docker-php-ext-install mbstring \
&& docker-php-ext-install zip \
&& docker-php-ext-install intl \
&& docker-php-ext-install xsl \
&& docker-php-ext-install soap \
&& requirementsToRemove="libpng12-dev libmcrypt-dev libcurl3-dev libpng12-dev libfreetype6-dev libjpeg-turbo8-dev" \
&& apt-get purge --auto-remove -y $requirementsToRemove

RUN chsh -s /bin/bash www-data

{{{magento2Installation}}}

RUN cd $INSTALL_DIR \
&& find . -type d -exec chmod 770 {} \; \
&& find . -type f -exec chmod 660 {} \; \
&& chmod u+x bin/magento

COPY ./install-magento /usr/local/bin/install-magento
RUN chmod +x /usr/local/bin/install-magento

COPY ./install-sampledata /usr/local/bin/install-sampledata
RUN chmod +x /usr/local/bin/install-sampledata

RUN a2enmod rewrite
RUN echo "memory_limit=2048M" > /usr/local/etc/php/conf.d/memory-limit.ini

RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

WORKDIR $INSTALL_DIR

# Add cron job
ADD crontab /etc/cron.d/magento2-cron
RUN chmod 0644 /etc/cron.d/magento2-cron \
&& crontab -u www-data /etc/cron.d/magento2-cron
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ __Note__ This docker image uses the *Contributing developer* profile to install

**Please note: this Docker image is for development and testing only, not for production use. Setting up a Magento 2 production server requires more configurations. Please refer to [official documentations](http://devdocs.magento.com/guides/v2.2/config-guide/deployment/).**

## Magento 2 installation types

Magento 2 has three different ways to [install](http://devdocs.magento.com/guides/v2.0/install-gde/bk-install-guide.html), for users, integrators and developers. This Docker image uses **integrator** as the default installation type, so the **Web Setup Wizard** can be used. For each version, both integrator and developer installation types are available. The user installation type is not currently supported.

For example, Magento 2 version `2.2.2` has tag `2.2.2`, `2.2.2-integrator` and `2.2.2-developer`. `2.2.2` is the same as `2.2.2-integrator`.

Below are some basic instructions.

## Quick start
Expand Down
2 changes: 0 additions & 2 deletions crontab

This file was deleted.

3 changes: 3 additions & 0 deletions crontab.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* * * * * www-data /usr/local/bin/php /var/www/html/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/html/var/log/magento.cron.log
* * * * * www-data /usr/local/bin/php /var/www/html/bin/magento indexer:reindex
{{{extraCronJobs}}}
45 changes: 21 additions & 24 deletions Dockerfile → developer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
FROM alexcheng/apache2-php7:7.1.11

MAINTAINER Fu Cheng <[email protected]>

RUN a2enmod rewrite
Label maintainer="[email protected]"

ENV MAGENTO_VERSION 2.2.2

RUN rm -rf /var/www/html/* \
&& apt-get update \
&& apt-get install -y wget

RUN cd /tmp && curl https://codeload.github.com/magento/magento2/tar.gz/$MAGENTO_VERSION -o $MAGENTO_VERSION.tar.gz && tar xvf $MAGENTO_VERSION.tar.gz && mv magento2-$MAGENTO_VERSION/* magento2-$MAGENTO_VERSION/.htaccess /var/www/html

ENV INSTALL_DIR /var/www/html
ENV COMPOSER_HOME /var/www/.composer/

RUN curl -sS https://getcomposer.org/installer | php \
&& mv composer.phar /usr/local/bin/composer
COPY ./auth.json $COMPOSER_HOME

RUN requirements="libpng12-dev libmcrypt-dev libmcrypt4 libcurl3-dev libfreetype6 libjpeg-turbo8 libjpeg-turbo8-dev libpng12-dev libfreetype6-dev libicu-dev libxslt1-dev" \
&& apt-get update \
&& apt-get install -y $requirements \
&& rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-install pdo_mysql \
Expand All @@ -30,33 +26,34 @@ RUN requirements="libpng12-dev libmcrypt-dev libmcrypt4 libcurl3-dev libfreetype
&& requirementsToRemove="libpng12-dev libmcrypt-dev libcurl3-dev libpng12-dev libfreetype6-dev libjpeg-turbo8-dev" \
&& apt-get purge --auto-remove -y $requirementsToRemove

COPY ./auth.json /var/www/.composer/
RUN chsh -s /bin/bash www-data

RUN cd /tmp && \
curl https://codeload.github.com/magento/magento2/tar.gz/$MAGENTO_VERSION -o $MAGENTO_VERSION.tar.gz && \
tar xvf $MAGENTO_VERSION.tar.gz && \
mv magento2-$MAGENTO_VERSION/* magento2-$MAGENTO_VERSION/.htaccess $INSTALL_DIR

RUN chown -R www-data:www-data /var/www
RUN su www-data -c "cd /var/www/html && composer install"
RUN cd /var/www/html \
RUN su www-data -c "cd $INSTALL_DIR && composer install"
RUN su www-data -c "cd $INSTALL_DIR && composer config repositories.magento composer https://repo.magento.com/"

RUN cd $INSTALL_DIR \
&& find . -type d -exec chmod 770 {} \; \
&& find . -type f -exec chmod 660 {} \; \
&& chmod u+x bin/magento


RUN su www-data -c "cd /var/www/html && composer config repositories.magento composer https://repo.magento.com/"


COPY ./bin/install-magento /usr/local/bin/install-magento
COPY ./install-magento /usr/local/bin/install-magento
RUN chmod +x /usr/local/bin/install-magento

COPY ./bin/install-sampledata /usr/local/bin/install-sampledata
COPY ./install-sampledata /usr/local/bin/install-sampledata
RUN chmod +x /usr/local/bin/install-sampledata

RUN echo "memory_limit=1024M" > /usr/local/etc/php/conf.d/memory-limit.ini
RUN a2enmod rewrite
RUN echo "memory_limit=2048M" > /usr/local/etc/php/conf.d/memory-limit.ini

RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

#Commented out the next 3 lines, because i don't see no use of this
WORKDIR /var/www/html
#VOLUME /var/www/html/var
#VOLUME /var/www/html/pub
WORKDIR $INSTALL_DIR

# Add cron job
ADD crontab /etc/cron.d/magento2-cron
Expand Down
8 changes: 8 additions & 0 deletions developer/auth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"http-basic": {
"repo.magento.com": {
"username": "5310458a34d580de1700dfe826ff19a1",
"password": "255059b03eb9d30604d5ef52fca7465d"
}
}
}
3 changes: 3 additions & 0 deletions developer/crontab
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* * * * * www-data /usr/local/bin/php /var/www/html/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/html/var/log/magento.cron.log
* * * * * www-data /usr/local/bin/php /var/www/html/bin/magento indexer:reindex

File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions install-magento
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

su www-data <<EOSU
/var/www/html/bin/magento setup:install --base-url=$MAGENTO_URL --backend-frontname=$MAGENTO_BACKEND_FRONTNAME --language=$MAGENTO_LANGUAGE --timezone=$MAGENTO_TIMEZONE --currency=$MAGENTO_DEFAULT_CURRENCY --db-host=$MYSQL_HOST --db-name=$MYSQL_DATABASE --db-user=$MYSQL_USER --db-password=$MYSQL_PASSWORD --use-secure=$MAGENTO_USE_SECURE --base-url-secure=$MAGENTO_BASE_URL_SECURE --use-secure-admin=$MAGENTO_USE_SECURE_ADMIN --admin-firstname=$MAGENTO_ADMIN_FIRSTNAME --admin-lastname=$MAGENTO_ADMIN_LASTNAME --admin-email=$MAGENTO_ADMIN_EMAIL --admin-user=$MAGENTO_ADMIN_USERNAME --admin-password=$MAGENTO_ADMIN_PASSWORD
EOSU
13 changes: 13 additions & 0 deletions install-sampledata
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

su www-data <<EOSU
ln -s ~/.composer/auth.json /var/www/html/var/composer_home/
/var/www/html/bin/magento sampledata:deploy
/var/www/html/bin/magento setup:upgrade
/var/www/html/bin/magento setup:di:compile
EOSU
55 changes: 55 additions & 0 deletions integrator/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
FROM alexcheng/apache2-php7:7.1.11

Label maintainer="[email protected]"

ENV MAGENTO_VERSION 2.2.2
ENV INSTALL_DIR /var/www/html
ENV COMPOSER_HOME /var/www/.composer/

RUN curl -sS https://getcomposer.org/installer | php \
&& mv composer.phar /usr/local/bin/composer
COPY ./auth.json $COMPOSER_HOME

RUN requirements="libpng12-dev libmcrypt-dev libmcrypt4 libcurl3-dev libfreetype6 libjpeg-turbo8 libjpeg-turbo8-dev libpng12-dev libfreetype6-dev libicu-dev libxslt1-dev" \
&& apt-get update \
&& apt-get install -y $requirements \
&& rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd \
&& docker-php-ext-install mcrypt \
&& docker-php-ext-install mbstring \
&& docker-php-ext-install zip \
&& docker-php-ext-install intl \
&& docker-php-ext-install xsl \
&& docker-php-ext-install soap \
&& requirementsToRemove="libpng12-dev libmcrypt-dev libcurl3-dev libpng12-dev libfreetype6-dev libjpeg-turbo8-dev" \
&& apt-get purge --auto-remove -y $requirementsToRemove

RUN chsh -s /bin/bash www-data

RUN chown -R www-data:www-data /var/www
RUN su www-data -c "composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition $INSTALL_DIR $MAGENTO_VERSION"

RUN cd $INSTALL_DIR \
&& find . -type d -exec chmod 770 {} \; \
&& find . -type f -exec chmod 660 {} \; \
&& chmod u+x bin/magento

COPY ./install-magento /usr/local/bin/install-magento
RUN chmod +x /usr/local/bin/install-magento

COPY ./install-sampledata /usr/local/bin/install-sampledata
RUN chmod +x /usr/local/bin/install-sampledata

RUN a2enmod rewrite
RUN echo "memory_limit=2048M" > /usr/local/etc/php/conf.d/memory-limit.ini

RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

WORKDIR $INSTALL_DIR

# Add cron job
ADD crontab /etc/cron.d/magento2-cron
RUN chmod 0644 /etc/cron.d/magento2-cron \
&& crontab -u www-data /etc/cron.d/magento2-cron
8 changes: 8 additions & 0 deletions integrator/auth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"http-basic": {
"repo.magento.com": {
"username": "5310458a34d580de1700dfe826ff19a1",
"password": "255059b03eb9d30604d5ef52fca7465d"
}
}
}
4 changes: 4 additions & 0 deletions integrator/crontab
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* * * * * www-data /usr/local/bin/php /var/www/html/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/html/var/log/magento.cron.log
* * * * * www-data /usr/local/bin/php /var/www/html/bin/magento indexer:reindex
* * * * * www-data /usr/local/bin/php /var/www/html/update/cron.php >> /var/www/html/var/log/update.cron.log
* * * * * www-data /usr/local/bin/php /var/www/html/bin/magento setup:cron:run >> /var/www/html/var/log/setup.cron.log
7 changes: 7 additions & 0 deletions integrator/install-magento
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

su www-data <<EOSU
/var/www/html/bin/magento setup:install --base-url=$MAGENTO_URL --backend-frontname=$MAGENTO_BACKEND_FRONTNAME --language=$MAGENTO_LANGUAGE --timezone=$MAGENTO_TIMEZONE --currency=$MAGENTO_DEFAULT_CURRENCY --db-host=$MYSQL_HOST --db-name=$MYSQL_DATABASE --db-user=$MYSQL_USER --db-password=$MYSQL_PASSWORD --use-secure=$MAGENTO_USE_SECURE --base-url-secure=$MAGENTO_BASE_URL_SECURE --use-secure-admin=$MAGENTO_USE_SECURE_ADMIN --admin-firstname=$MAGENTO_ADMIN_FIRSTNAME --admin-lastname=$MAGENTO_ADMIN_LASTNAME --admin-email=$MAGENTO_ADMIN_EMAIL --admin-user=$MAGENTO_ADMIN_USERNAME --admin-password=$MAGENTO_ADMIN_PASSWORD
EOSU
13 changes: 13 additions & 0 deletions integrator/install-sampledata
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

su www-data <<EOSU
ln -s ~/.composer/auth.json /var/www/html/var/composer_home/
/var/www/html/bin/magento sampledata:deploy
/var/www/html/bin/magento setup:upgrade
/var/www/html/bin/magento setup:di:compile
EOSU
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "docker-magento2",
"version": "1.0.0",
"description": "Docker image for Magento 2",
"main": "update.js",
"repository": {
"type": "git",
"url": "git+https://github.com/alexcheng1982/docker-magento2.git"
},
"keywords": [],
"author": "Fu Cheng <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/alexcheng1982/docker-magento2/issues"
},
"homepage": "https://github.com/alexcheng1982/docker-magento2#readme",
"dependencies": {
"bluebird": "^3.5.1",
"handlebars": "^4.0.11",
"lodash.merge": "^4.6.1"
}
}
Empty file.
8 changes: 8 additions & 0 deletions partials/developer/magento2Installation
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
RUN cd /tmp && \
curl https://codeload.github.com/magento/magento2/tar.gz/$MAGENTO_VERSION -o $MAGENTO_VERSION.tar.gz && \
tar xvf $MAGENTO_VERSION.tar.gz && \
mv magento2-$MAGENTO_VERSION/* magento2-$MAGENTO_VERSION/.htaccess $INSTALL_DIR

RUN chown -R www-data:www-data /var/www
RUN su www-data -c "cd $INSTALL_DIR && composer install"
RUN su www-data -c "cd $INSTALL_DIR && composer config repositories.magento composer https://repo.magento.com/"
2 changes: 2 additions & 0 deletions partials/integrator/extraCronJobs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* * * * * www-data /usr/local/bin/php /var/www/html/update/cron.php >> /var/www/html/var/log/update.cron.log
* * * * * www-data /usr/local/bin/php /var/www/html/bin/magento setup:cron:run >> /var/www/html/var/log/setup.cron.log
2 changes: 2 additions & 0 deletions partials/integrator/magento2Installation
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
RUN chown -R www-data:www-data /var/www
RUN su www-data -c "composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition $INSTALL_DIR $MAGENTO_VERSION"
42 changes: 42 additions & 0 deletions update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const Handlebars = require('handlebars');
const Promise = require('bluebird');
const merge = require('lodash.merge');
const fs = Promise.promisifyAll(require("fs"));
const path = require("path");

const commonOptions = {
phpVersion: '7.1.11',
magento2Version: '2.2.2',
};

function readPartial(profile, section) {
return fs.readFileAsync(path.join(__dirname, 'partials', profile, section), 'utf8');
}

function writeFile(context, profile, fileName, template) {
return fs.readFileAsync(path.join(__dirname, template || `${fileName}.hbs`), 'utf8')
.then(content => Handlebars.compile(content)(context))
.then(content => fs.writeFileAsync(path.join(__dirname, profile, fileName), content));
}

function copyFile(fileName, profile) {
return fs.copyFileAsync(path.join(__dirname, fileName), path.join(__dirname, profile, fileName));
}

const profiles = ['integrator', 'developer'];
const sections = ['magento2Installation', 'extraCronJobs'];
const filesToCopy = ['auth.json', 'install-magento', 'install-sampledata'];
const templatedFiles = ['Dockerfile', 'crontab'];
Promise.map(profiles, profile => {
return Promise.reduce(sections, (obj, section) => {
return readPartial(profile, section).then(value => {
obj[section] = value;
return obj;
})
}, {}).then(profileContext => {
const context = merge({}, commonOptions, profileContext);
return Promise.map(filesToCopy, fileToCopy => copyFile(fileToCopy, profile))
.then(_ => Promise.map(templatedFiles, templatedFile => writeFile(context, profile, templatedFile)));
});
}).then(() => console.log("Update successfully"))
.catch(console.error);
Loading

0 comments on commit 96a2aa4

Please sign in to comment.