├── README.md ├── backups └── backup.sh ├── cache_server ├── Dockerfile ├── default.vcl ├── supervisord.conf └── varnish ├── database_server ├── Dockerfile ├── mysql.sh └── supervisord.conf ├── docker-compose.yml ├── magento2 └── README.md ├── redis_server ├── Dockerfile └── supervisord.conf ├── ssl_server ├── Dockerfile ├── default ├── nginx.conf └── supervisord.conf └── web_server ├── Dockerfile └── supervisord.conf /README.md: -------------------------------------------------------------------------------- 1 | ### Optimising Magento 2 with Varnish Cache, Redis and Nginx SSL termination on the Multi-container Architecture Using Docker-Compose tool. 2 | 3 | This repository corresponds to architecture setup as mentioned in blog https://cloudkul.com/blog/integrate-magento-2-varnish-cache-redis-server-ssl-termination-using-docker-compose/ . 4 | 5 | ##### Docker-Compose Tool 6 | 7 | As mentioned in Docker docs, Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a Compose file to configure your application’s services. Then, using a single command, you create and start all the services from your configuration. 8 | 9 | With the help of docker-compose we can define containers to be built, their configuration, links, volumes, ports etc in a single file and it gets launched by a single command. We can add multiple servers and services just by adding them to docker-compose configuration file. This configuration file is in YAML format. 10 | 11 | Getting started with docker-compose is a few steps process: 12 | 13 | > Create a Dockerfile defining the application environment. We can create separate Dockerfile for our different services. As Dockerfile are lightweight, so our application can be replicated anywhere. 14 | 15 | > Create a docker-compose.yml file defining services that needed for application run. We can define volumes to be mapped, ports to be exposed, links to be created, arguments to be passed etc in our docker-compose.yml file. 16 | 17 | > Run ‘docker-compose build’ to create Docker image. After creating Dockerfile, docker-compose.yml and placing our volumes at right places, we can create our image. 18 | 19 | > Run ‘docker-compose up -d’ to run the docker containers. After image build up, we can run all of our containers as mentioned in configuration files by this single command. 20 | 21 | ##### Dockerizing Magento 2, Varnish Cache, Redis server over SSL with Docker-Compose 22 | 23 | Docker is an open-source project that can be integrated with almost all the applications allowing scope of isolation and flexibility. It can be integrated with Magento 2 as well. Magento is an e-commerce platform written in PHP and based on zend framework available under both open-source and commercial licenses. 24 | 25 | Varnish cache is a web application accelerator also known as a caching HTTP reverse proxy. Varnish cache visits your server once to cache the page, then all future requests for the same page will be served by Varnish cache. Varnish acts a reverse proxy server that directs client requests to the back-end apache2 server. Whenever a client makes a request, Varnish server checks the content within the cache and in case data not found, it sends the request to backend server and fetch the content to client and keep a copy of the data as cache. When the same request is made, Varnish does not bother apache2 server, it just fetch the data from the cache. It provides an additional level of abstraction and control to ensure the smooth flow of network traffic between clients and servers. 26 | 27 | Redis is an open source, BSD licensed, advanced key-value store that can optionally be used in Magento for back end and session storage. When first time page is loaded, a database is queried on the server. Redis caches the query. Next time other user loads the page the results are provided from the redis without quering the actual database. 28 | 29 | Magento 2 works out of box with Varnish Cache and provides its own VCL file for its setup. Magento supports many backend caches like MemcacheD and APC that are commonly used. However, Redis has become a popular and powerful cache system for Magento and other web applications. 30 | 31 | Nginx servers as reverse proxy server that receives traffic on port 80 and 443 and then proxy pass it to listening port of Varnish Cache server. It is done to deploy a way to direct both HTTP and HTTPS traffic to Varnish cache server which in turn, if needed, forward it apache2 server. 32 | 33 | In this project, we are using: 34 | 35 | > Operating system: Ubuntu 16.04 36 | 37 | > Web Server: Apache2 38 | 39 | > Database Server: Mysql-server-5.7 40 | 41 | > Cache Server: Varnish 4.1 42 | 43 | > PHP version: PHP-7.1 44 | 45 | > Redis server: Redis 46 | 47 | > SSL server: Nginx 1.10.1 48 | 49 | To begin with, please install docker and docker-compose on your ubuntu server. 50 | 51 | Then follow the following steps: 52 | 53 | 1). Clone or download this repository as 54 | 55 | 56 | > git clone https://github.com/webkul/magento2-varnish-redis-ssl-docker-compose.git. 57 | 58 | 2) Set mysql root credentials and name of the database to be created in *database_server* block ~/magento2-varnish-redis-ssl-docker-compose/docker-compose.yml: 59 | 60 | > mysql_password= 61 | 62 | > mysql_database= 63 | 64 | 3). Download Magento 2 version you wish to dockerize and upload it in directory magento2 in parallel docker-compose.yml. 65 | 66 | > Go to https://magento.com/tech-resources/download? . 67 | 68 | 4). Replace localhost in 'server_name' in ~/magento2-varnish-redis-ssl-docker-compose/ssl_server/default with your domain name or IP address. 69 | 70 | 5). Build the docker image. 71 | 72 | > docker-compose build 73 | 74 | 6). Check the built image as: 75 | 76 | > docker images 77 | 78 | 7). Run the containers from built image as: 79 | 80 | > docker-compose up -d 81 | 82 | 8). Check the running docker containers by command: 83 | 84 | > docker-compose ps 85 | 86 | > docker ps 87 | 88 | 89 | Now, your server setup is all ready, now hit your domain name or IP to install Magento 2. Now to configure Varnish for Magento 2 and test its working, please refer to blog https://cloudkul.com/blog/magento-2-and-varnish-cache-integration-with-docker-compose/. 90 | 91 | > Use name or id of the mysql container as database host. 92 | 93 | To configure Magento 2 for redis-server, please refer to blog https://cloudkul.com/blog/integrate-magento-2-varnish-cache-redis-server-ssl-termination-using-docker-compose/ . 94 | 95 | 96 | ##### Backing up Databases from Mysql-Server container 97 | 98 | Although we had secured our application code keeping it on our host but database is as important as server code. So in order to keep their backup we schedule a shell script that will take backups of all the databases present in mysql-server container and keep them in archived from on our host. Shell script is present on ~/magento2-varnish-redis-ssl-docker-compose/backups/db_backup.sh. Please refer to blog https://cloudkul.com/blog/integrate-magento-2-varnish-cache-redis-server-ssl-termination-using-docker-compose/ for backup management. 99 | 100 | If you face any issues, kindly report back. 101 | 102 | 103 | #### GETTING SUPPORT 104 | 105 | If you have any issues, contact us at support@webkul.com or raise ticket at https://webkul.uvdesk.com/ 106 | 107 | -------------------------------------------------------------------------------- /backups/backup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -u 4 | ## Mention your database container name 5 | container_name=mysql 6 | 7 | ## Mention mysql root password 8 | 9 | MYSQL_ROOT_PASSWORD=mention_your_mysql_root_password 10 | 11 | DATE=`date +%F-%H-%M-%S` 12 | 13 | for database in `echo 'show databases;' | docker exec -i mysql mysql --user=root --password=$MYSQL_ROOT_PASSWORD | grep -v Database | grep -v information_schema | grep -v mysql | grep -v performance_schema` 14 | do 15 | echo $database 16 | docker exec $container_name mysqldump -u root -p$MYSQL_ROOT_PASSWORD $database > $database-$DATE.sql && tar -zcvf $database-$DATE.tar.gz $database-$DATE.sql && rm $database-$DATE.sql && echo "$database-$DATE.tar.gz has been created on `date`" >> database_backup.log 17 | done 18 | 19 | -------------------------------------------------------------------------------- /cache_server/Dockerfile: -------------------------------------------------------------------------------- 1 | From ubuntu:16.04 2 | 3 | MAINTAINER Alankrit Srivastava alankrit.srivastava256@webkul.com 4 | 5 | ##update server 6 | 7 | RUN apt-get update \ 8 | ##install supervisor and setup supervisord.conf file 9 | && apt-get install -y supervisor \ 10 | && mkdir -p /var/log/supervisor \ 11 | ##install varnish 12 | && apt-get -y install varnish \ 13 | && rm /etc/varnish/default.vcl \ 14 | && rm /etc/default/varnish 15 | EXPOSE 6082 6081 16 | CMD ["/usr/bin/supervisord"] 17 | -------------------------------------------------------------------------------- /cache_server/default.vcl: -------------------------------------------------------------------------------- 1 | 2 | vcl 4.0; 3 | 4 | import std; 5 | # The minimal Varnish version is 5.0 6 | # For SSL offloading, pass the following header in your proxy server or load balancer: 'X-Forwarded-Proto: https' 7 | 8 | backend default { 9 | .host = "apache2"; 10 | .port = "8080"; 11 | .first_byte_timeout = 600s; 12 | } 13 | 14 | acl purge { 15 | "localhost"; 16 | } 17 | 18 | sub vcl_recv { 19 | if (req.method == "PURGE") { 20 | if (client.ip !~ purge) { 21 | return (synth(405, "Method not allowed")); 22 | } 23 | # To use the X-Pool header for purging varnish during automated deployments, make sure the X-Pool header 24 | # has been added to the response in your backend server config. This is used, for example, by the 25 | # capistrano-magento2 gem for purging old content from varnish during it's deploy routine. 26 | if (!req.http.X-Magento-Tags-Pattern && !req.http.X-Pool) { 27 | return (synth(400, "X-Magento-Tags-Pattern or X-Pool header required")); 28 | } 29 | if (req.http.X-Magento-Tags-Pattern) { 30 | ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern); 31 | } 32 | if (req.http.X-Pool) { 33 | ban("obj.http.X-Pool ~ " + req.http.X-Pool); 34 | } 35 | return (synth(200, "Purged")); 36 | } 37 | 38 | if (req.method != "GET" && 39 | req.method != "HEAD" && 40 | req.method != "PUT" && 41 | req.method != "POST" && 42 | req.method != "TRACE" && 43 | req.method != "OPTIONS" && 44 | req.method != "DELETE") { 45 | /* Non-RFC2616 or CONNECT which is weird. */ 46 | return (pipe); 47 | } 48 | 49 | # We only deal with GET and HEAD by default 50 | if (req.method != "GET" && req.method != "HEAD") { 51 | return (pass); 52 | } 53 | 54 | # Bypass shopping cart, checkout and search requests 55 | if (req.url ~ "/checkout" || req.url ~ "/catalogsearch") { 56 | return (pass); 57 | } 58 | 59 | # Bypass health check requests 60 | if (req.url ~ "/pub/health_check.php") { 61 | return (pass); 62 | } 63 | 64 | # Set initial grace period usage status 65 | set req.http.grace = "none"; 66 | 67 | # normalize url in case of leading HTTP scheme and domain 68 | set req.url = regsub(req.url, "^http[s]?://", ""); 69 | 70 | # collect all cookies 71 | std.collect(req.http.Cookie); 72 | 73 | # Compression filter. See https://www.varnish-cache.org/trac/wiki/FAQ/Compression 74 | if (req.http.Accept-Encoding) { 75 | if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$") { 76 | # No point in compressing these 77 | unset req.http.Accept-Encoding; 78 | } elsif (req.http.Accept-Encoding ~ "gzip") { 79 | set req.http.Accept-Encoding = "gzip"; 80 | } elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") { 81 | set req.http.Accept-Encoding = "deflate"; 82 | } else { 83 | # unkown algorithm 84 | unset req.http.Accept-Encoding; 85 | } 86 | } 87 | 88 | # Remove Google gclid parameters to minimize the cache objects 89 | set req.url = regsuball(req.url,"\?gclid=[^&]+$",""); # strips when QS = "?gclid=AAA" 90 | set req.url = regsuball(req.url,"\?gclid=[^&]+&","?"); # strips when QS = "?gclid=AAA&foo=bar" 91 | set req.url = regsuball(req.url,"&gclid=[^&]+",""); # strips when QS = "?foo=bar&gclid=AAA" or QS = "?foo=bar&gclid=AAA&bar=baz" 92 | 93 | # Static files caching 94 | if (req.url ~ "^/(pub/)?(media|static)/") { 95 | # Static files should not be cached by default 96 | return (pass); 97 | 98 | # But if you use a few locales and don't use CDN you can enable caching static files by commenting previous line (#return (pass);) and uncommenting next 3 lines 99 | #unset req.http.Https; 100 | #unset req.http.X-Forwarded-Proto; 101 | #unset req.http.Cookie; 102 | } 103 | 104 | return (hash); 105 | } 106 | 107 | sub vcl_hash { 108 | if (req.http.cookie ~ "X-Magento-Vary=") { 109 | hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "\1")); 110 | } 111 | 112 | # For multi site configurations to not cache each other's content 113 | if (req.http.host) { 114 | hash_data(req.http.host); 115 | } else { 116 | hash_data(server.ip); 117 | } 118 | 119 | # To make sure http users don't see ssl warning 120 | if (req.http.X-Forwarded-Proto) { 121 | hash_data(req.http.X-Forwarded-Proto); 122 | } 123 | 124 | } 125 | 126 | sub vcl_backend_response { 127 | 128 | set beresp.grace = 3d; 129 | 130 | if (beresp.http.content-type ~ "text") { 131 | set beresp.do_esi = true; 132 | } 133 | 134 | if (bereq.url ~ "\.js$" || beresp.http.content-type ~ "text") { 135 | set beresp.do_gzip = true; 136 | } 137 | 138 | # cache only successfully responses and 404s 139 | if (beresp.status != 200 && beresp.status != 404) { 140 | set beresp.ttl = 0s; 141 | set beresp.uncacheable = true; 142 | return (deliver); 143 | } elsif (beresp.http.Cache-Control ~ "private") { 144 | set beresp.uncacheable = true; 145 | set beresp.ttl = 86400s; 146 | return (deliver); 147 | } 148 | 149 | if (beresp.http.X-Magento-Debug) { 150 | set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control; 151 | } 152 | 153 | # validate if we need to cache it and prevent from setting cookie 154 | if (beresp.ttl > 0s && (bereq.method == "GET" || bereq.method == "HEAD")) { 155 | unset beresp.http.set-cookie; 156 | } 157 | 158 | # If page is not cacheable then bypass varnish for 2 minutes as Hit-For-Pass 159 | if (beresp.ttl <= 0s || 160 | beresp.http.Surrogate-control ~ "no-store" || 161 | (!beresp.http.Surrogate-Control && beresp.http.Vary == "*")) { 162 | # Mark as Hit-For-Pass for the next 2 minutes 163 | set beresp.ttl = 120s; 164 | set beresp.uncacheable = true; 165 | } 166 | return (deliver); 167 | } 168 | 169 | sub vcl_deliver { 170 | if (resp.http.X-Magento-Debug) { 171 | if (resp.http.x-varnish ~ " ") { 172 | set resp.http.X-Magento-Cache-Debug = "HIT"; 173 | set resp.http.Grace = req.http.grace; 174 | } else { 175 | set resp.http.X-Magento-Cache-Debug = "MISS"; 176 | } 177 | } else { 178 | unset resp.http.Age; 179 | } 180 | 181 | unset resp.http.X-Magento-Debug; 182 | unset resp.http.X-Magento-Tags; 183 | unset resp.http.X-Powered-By; 184 | unset resp.http.Server; 185 | unset resp.http.X-Varnish; 186 | unset resp.http.Via; 187 | unset resp.http.Link; 188 | } 189 | 190 | sub vcl_hit { 191 | if (obj.ttl >= 0s) { 192 | # Hit within TTL period 193 | return (deliver); 194 | } 195 | if (std.healthy(req.backend_hint)) { 196 | if (obj.ttl + 300s > 0s) { 197 | # Hit after TTL expiration, but within grace period 198 | set req.http.grace = "normal (healthy server)"; 199 | return (deliver); 200 | } else { 201 | # Hit after TTL and grace expiration 202 | return (miss); 203 | } 204 | } else { 205 | # server is not healthy, retrieve from cache 206 | set req.http.grace = "unlimited (unhealthy server)"; 207 | return (deliver); 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /cache_server/supervisord.conf: -------------------------------------------------------------------------------- 1 | [supervisord] 2 | nodaemon=true 3 | 4 | [program:varnish3.0] 5 | command=/bin/bash -c "/usr/sbin/varnishd -P /run/varnishd.pid -a :6081 -F -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m" 6 | -------------------------------------------------------------------------------- /cache_server/varnish: -------------------------------------------------------------------------------- 1 | # Configuration file for varnish 2 | # 3 | # /etc/init.d/varnish expects the variables $DAEMON_OPTS, $NFILES and $MEMLOCK 4 | # to be set from this shell script fragment. 5 | # 6 | # Note: If systemd is installed, this file is obsolete and ignored. You will 7 | # need to copy /lib/systemd/system/varnish.service to /etc/systemd/system/ and 8 | # edit that file. 9 | 10 | # Should we start varnishd at boot? Set to "no" to disable. 11 | START=yes 12 | 13 | # Maximum number of open files (for ulimit -n) 14 | NFILES=131072 15 | 16 | # Maximum locked memory size (for ulimit -l) 17 | # Used for locking the shared memory log in memory. If you increase log size, 18 | # you need to increase this number as well 19 | MEMLOCK=82000 20 | 21 | # Default varnish instance name is the local nodename. Can be overridden with 22 | # the -n switch, to have more instances on a single server. 23 | # You may need to uncomment this variable for alternatives 1 and 3 below. 24 | # INSTANCE=$(uname -n) 25 | 26 | # This file contains 4 alternatives, please use only one. 27 | 28 | ## Alternative 1, Minimal configuration, no VCL 29 | # 30 | # Listen on port 6081, administration on localhost:6082, and forward to 31 | # content server on localhost:8080. Use a 1GB fixed-size cache file. 32 | # 33 | # This example uses the INSTANCE variable above, which you need to uncomment. 34 | # 35 | # DAEMON_OPTS="-a :6081 \ 36 | # -T localhost:6082 \ 37 | # -b localhost:8080 \ 38 | # -u varnish -g varnish \ 39 | # -S /etc/varnish/secret \ 40 | # -s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,1G" 41 | 42 | 43 | ## Alternative 2, Configuration with VCL 44 | # 45 | # Listen on port 6081, administration on localhost:6082, and forward to 46 | # one content server selected by the vcl file, based on the request. 47 | # 48 | DAEMON_OPTS="-a :6081 \ 49 | -T localhost:6082 \ 50 | -f /etc/varnish/default.vcl \ 51 | -S /etc/varnish/secret \ 52 | -s malloc,256m" 53 | 54 | 55 | ## Alternative 3, Advanced configuration 56 | # 57 | # This example uses the INSTANCE variable above, which you need to uncomment. 58 | # 59 | # See varnishd(1) for more information. 60 | # 61 | # # Main configuration file. You probably want to change it :) 62 | # VARNISH_VCL_CONF=/etc/varnish/default.vcl 63 | # 64 | # # Default address and port to bind to 65 | # # Blank address means all IPv4 and IPv6 interfaces, otherwise specify 66 | # # a host name, an IPv4 dotted quad, or an IPv6 address in brackets. 67 | # VARNISH_LISTEN_ADDRESS= 68 | # VARNISH_LISTEN_PORT=6081 69 | # 70 | # # Telnet admin interface listen address and port 71 | # VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1 72 | # VARNISH_ADMIN_LISTEN_PORT=6082 73 | # 74 | # # The minimum number of worker threads to start 75 | # VARNISH_MIN_THREADS=1 76 | # 77 | # # The Maximum number of worker threads to start 78 | # VARNISH_MAX_THREADS=1000 79 | # 80 | # # Idle timeout for worker threads 81 | # VARNISH_THREAD_TIMEOUT=120 82 | # 83 | # # Cache file location 84 | # VARNISH_STORAGE_FILE=/var/lib/varnish/$INSTANCE/varnish_storage.bin 85 | # 86 | # # Cache file size: in bytes, optionally using k / M / G / T suffix, 87 | # # or in percentage of available disk space using the % suffix. 88 | # VARNISH_STORAGE_SIZE=1G 89 | # 90 | # # File containing administration secret 91 | # VARNISH_SECRET_FILE=/etc/varnish/secret 92 | # 93 | # # Backend storage specification 94 | # VARNISH_STORAGE="file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}" 95 | # 96 | # # Default TTL used when the backend does not specify one 97 | # VARNISH_TTL=120 98 | # 99 | # # DAEMON_OPTS is used by the init script. If you add or remove options, make 100 | # # sure you update this section, too. 101 | # DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \ 102 | # -f ${VARNISH_VCL_CONF} \ 103 | # -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \ 104 | # -t ${VARNISH_TTL} \ 105 | # -w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT} \ 106 | # -S ${VARNISH_SECRET_FILE} \ 107 | # -s ${VARNISH_STORAGE}" 108 | # 109 | 110 | 111 | ## Alternative 4, Do It Yourself 112 | # 113 | # DAEMON_OPTS="" 114 | -------------------------------------------------------------------------------- /database_server/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:16.04 2 | 3 | LABEL maintainer="Alankrit Srivastava " 4 | 5 | ARG mysql_password 6 | ARG mysql_database 7 | env MYSQL_ROOT_PASSWORD ${mysql_password} 8 | env MYSQL_DATABASE ${mysql_database} 9 | 10 | RUN apt-get update \ 11 | && echo "mysql-server-5.7 mysql-server/root_password password ${mysql_password}" | debconf-set-selections \ 12 | && echo "mysql-server-5.7 mysql-server/root_password_again password ${mysql_password}" | debconf-set-selections \ 13 | && DEBIAN_FRONTEND=noninteractive apt-get -y install mysql-server-5.7 && \ 14 | mkdir -p /var/lib/mysql && \ 15 | mkdir -p /var/run/mysqld && \ 16 | mkdir -p /var/log/mysql && \ 17 | touch /var/run/mysqld/mysqld.sock && \ 18 | touch /var/run/mysqld/mysqld.pid && \ 19 | chown -R mysql:mysql /var/lib/mysql && \ 20 | chown -R mysql:mysql /var/run/mysqld && \ 21 | chown -R mysql:mysql /var/log/mysql &&\ 22 | chmod -R 777 /var/run/mysqld/ \ 23 | && sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/mysql.conf.d/mysqld.cnf \ 24 | ##install supervisor and setup supervisord.conf file 25 | && apt-get install -y supervisor nano \ 26 | && mkdir -p /var/log/supervisor 27 | CMD ["/usr/bin/supervisord"] 28 | -------------------------------------------------------------------------------- /database_server/mysql.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -u 4 | sleep 4 5 | database_connectivity_check=no 6 | var=1 7 | while [ "$database_connectivity_check" != "mysql" ]; do 8 | /etc/init.d/mysql start 9 | sleep 2 10 | database_connectivity_check=`mysqlshow --user=root --password=$MYSQL_ROOT_PASSWORD | grep -o mysql` 11 | if [ $var -ge 4 ]; then 12 | exit 1 13 | fi 14 | var=$((var+1)) 15 | done 16 | 17 | 18 | database_availability_check=`mysqlshow --user=root --password=$MYSQL_ROOT_PASSWORD | grep -ow "$MYSQL_DATABASE"` 19 | 20 | if [ "$database_availability_check" == "$MYSQL_DATABASE" ]; then 21 | exit 1 22 | else 23 | mysql -u root -p$MYSQL_ROOT_PASSWORD -e "grant all on *.* to 'root'@'%' identified by '$MYSQL_ROOT_PASSWORD';" 24 | mysql -u root -p$MYSQL_ROOT_PASSWORD -e "create database $MYSQL_DATABASE;" 25 | mysql -u root -p$MYSQL_ROOT_PASSWORD -e "grant all on $MYSQL_DATABASE.* to 'root'@'%' identified by '$MYSQL_ROOT_PASSWORD';" 26 | supervisorctl stop database_creation && supervisorctl remove database_creation 27 | echo "Database $MYSQL_DATABASE created" 28 | fi 29 | -------------------------------------------------------------------------------- /database_server/supervisord.conf: -------------------------------------------------------------------------------- 1 | [supervisord] 2 | nodaemon=true 3 | 4 | 5 | [program:mysql] 6 | command=/bin/bash -c "touch /var/run/mysqld/mysqld.sock;touch /var/run/mysqld/mysqld.pid;chown -R mysql:mysql /var/lib/mysql;chown -R mysql:mysql /var/run/mysqld;chown -R mysql:mysql /var/log/mysql;chmod -R 777 /var/run/mysqld/;/etc/init.d/mysql restart" 7 | 8 | [program:database_creation] 9 | command=/bin/bash -c "chmod a+x /etc/mysql.sh; /etc/mysql.sh" 10 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | ssl_server: 4 | build: 5 | context: ./ssl_server/ 6 | container_name: nginx 7 | depends_on: 8 | - web_server 9 | - cache_server 10 | - database_server 11 | - redis_server 12 | volumes: 13 | - ./ssl_server/supervisord.conf:/etc/supervisor/conf.d/supervisord.conf 14 | - ./ssl_server/default:/etc/nginx/sites-enabled/default 15 | - ./ssl_server/nginx.conf:/etc/nginx/nginx.conf 16 | links: 17 | - web_server 18 | - cache_server 19 | - database_server 20 | - redis_server 21 | ports: 22 | - "80:80" 23 | - "443:443" 24 | 25 | redis_server: 26 | build: 27 | context: ./redis_server/ 28 | container_name: redis 29 | depends_on: 30 | - web_server 31 | - cache_server 32 | - database_server 33 | volumes: 34 | - ./redis_server/supervisord.conf:/etc/supervisor/conf.d/supervisord.conf 35 | links: 36 | - web_server 37 | - database_server 38 | 39 | ports: 40 | - "6379:6379" 41 | 42 | cache_server: 43 | build: 44 | context: ./cache_server/ 45 | container_name: varnish 46 | depends_on: 47 | - web_server 48 | volumes: 49 | - ./cache_server/default.vcl:/etc/varnish/default.vcl 50 | - ./cache_server/varnish:/etc/default/varnish 51 | - ./cache_server/supervisord.conf:/etc/supervisor/conf.d/supervisord.conf 52 | ports: 53 | - "6081:6081" 54 | - "6082:6082" 55 | links: 56 | - web_server 57 | - database_server 58 | 59 | 60 | web_server: 61 | build: 62 | context: ./web_server/ 63 | container_name: apache2 64 | volumes: 65 | - ./magento2:/var/www/html 66 | - ./web_server/supervisord.conf:/etc/supervisor/conf.d/supervisord.conf 67 | ports: 68 | - "8080:8080" 69 | links: 70 | - database_server 71 | 72 | database_server: 73 | build: 74 | context: ./database_server/ 75 | args: 76 | - mysql_password=mention_your_mysql_root_password 77 | - mysql_database=mention_your_database_name 78 | container_name: mysql 79 | volumes: 80 | - ./database_server/supervisord.conf:/etc/supervisor/conf.d/supervisord.conf 81 | - ./database_server/mysql.sh:/etc/mysql.sh 82 | ports: 83 | - "3306:3306" 84 | -------------------------------------------------------------------------------- /magento2/README.md: -------------------------------------------------------------------------------- 1 | Upload your Magento 2 files and directories here. 2 | -------------------------------------------------------------------------------- /redis_server/Dockerfile: -------------------------------------------------------------------------------- 1 | From ubuntu:16.04 2 | 3 | MAINTAINER Alankrit Srivastava alankrit.srivastava256@webkul.com 4 | 5 | ##update server 6 | 7 | RUN apt-get update \ 8 | && apt-get install -y locales \ 9 | && locale-gen en_US.UTF-8 \ 10 | && export LANG=en_US.UTF-8 \ 11 | && apt-get update \ 12 | && apt-get install -y software-properties-common \ 13 | && LC_ALL=en_US.UTF-8 add-apt-repository -y ppa:chris-lea/redis-server \ 14 | && apt-get update \ 15 | && apt-get -y install redis-server \ 16 | && sed -i -e"s/^bind\s127.0.0.1/bind 0.0.0.0/" /etc/redis/redis.conf \ 17 | && chown -R redis: /var/log/redis/ \ 18 | ##install supervisor and setup supervisord.conf file 19 | && apt-get install -y supervisor \ 20 | && mkdir -p /var/log/supervisor 21 | COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf 22 | EXPOSE 6379 23 | CMD ["/usr/bin/supervisord"] 24 | -------------------------------------------------------------------------------- /redis_server/supervisord.conf: -------------------------------------------------------------------------------- 1 | [supervisord] 2 | nodaemon=true 3 | 4 | [program:redis] 5 | command=/usr/bin/redis-server /etc/redis/redis.conf 6 | 7 | -------------------------------------------------------------------------------- /ssl_server/Dockerfile: -------------------------------------------------------------------------------- 1 | From ubuntu:16.04 2 | 3 | MAINTAINER Alankrit Srivastava alankrit.srivastava256@webkul.com 4 | 5 | ##update server 6 | 7 | RUN apt-get update \ 8 | ##install nginx 9 | && apt-get install -y locales \ 10 | && locale-gen en_US.UTF-8 \ 11 | && export LANG=en_US.UTF-8 \ 12 | && apt-get update \ 13 | && apt-get install -y software-properties-common \ 14 | && LC_ALL=en_US.UTF-8 add-apt-repository -y ppa:nginx/stable \ 15 | && apt-get -y update \ 16 | && apt-get -y install nginx \ 17 | && rm /etc/nginx/sites-enabled/default \ 18 | ## Generate self signed certificate 19 | && cd /etc/nginx && echo -e "\n\n\n\n\n\n\n" | openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/cert.key -out /etc/nginx/cert.crt \ 20 | ##install supervisor and setup supervisord.conf file 21 | && apt-get install -y supervisor \ 22 | && mkdir -p /var/log/supervisor 23 | Expose 80 443 24 | 25 | CMD ["/usr/bin/supervisord"] 26 | -------------------------------------------------------------------------------- /ssl_server/default: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80 default_server; 3 | add_header 'Access-Control-Allow-Origin' '*'; 4 | server_name localhost; ## mention ip address or domain name 5 | # return 302 https://$server_name$request_uri; 6 | 7 | location / { 8 | include /etc/nginx/proxy_params; 9 | proxy_pass http://varnish:6081; 10 | } 11 | } 12 | server { 13 | listen 443; 14 | add_header 'Access-Control-Allow-Origin' '*'; 15 | server_name localhost; ## mention ip address or domain name 16 | ssl on; 17 | ssl_certificate /etc/nginx/cert.crt; 18 | ssl_certificate_key /etc/nginx/cert.key; 19 | ssl_session_timeout 5m; 20 | ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; 21 | ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES"; 22 | ssl_prefer_server_ciphers on; 23 | location / { 24 | include /etc/nginx/proxy_params; 25 | proxy_pass http://varnish:6081; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ssl_server/nginx.conf: -------------------------------------------------------------------------------- 1 | user www-data; 2 | worker_processes auto; 3 | pid /run/nginx.pid; 4 | include /etc/nginx/modules-enabled/*.conf; 5 | 6 | events { 7 | worker_connections 768; 8 | # multi_accept on; 9 | } 10 | 11 | http { 12 | 13 | ## 14 | # Basic Settings 15 | ## 16 | 17 | sendfile on; 18 | tcp_nopush on; 19 | tcp_nodelay on; 20 | keepalive_timeout 65; 21 | types_hash_max_size 2048; 22 | # server_tokens off; 23 | 24 | # server_names_hash_bucket_size 64; 25 | # server_name_in_redirect off; 26 | 27 | include /etc/nginx/mime.types; 28 | default_type application/octet-stream; 29 | 30 | ## 31 | # SSL Settings 32 | ## 33 | 34 | ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE 35 | ssl_prefer_server_ciphers on; 36 | 37 | ## 38 | # Logging Settings 39 | ## 40 | 41 | access_log /var/log/nginx/access.log; 42 | error_log /var/log/nginx/error.log; 43 | 44 | ## 45 | # Gzip Settings 46 | ## 47 | 48 | gzip on; 49 | gzip_disable "msie6"; 50 | 51 | # gzip_vary on; 52 | # gzip_proxied any; 53 | # gzip_comp_level 6; 54 | # gzip_buffers 16 8k; 55 | # gzip_http_version 1.1; 56 | # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; 57 | 58 | ## 59 | # Virtual Host Configs 60 | ## 61 | 62 | include /etc/nginx/conf.d/*.conf; 63 | include /etc/nginx/sites-enabled/*; 64 | } 65 | 66 | 67 | #mail { 68 | # # See sample authentication script at: 69 | # # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript 70 | # 71 | # # auth_http localhost/auth.php; 72 | # # pop3_capabilities "TOP" "USER"; 73 | # # imap_capabilities "IMAP4rev1" "UIDPLUS"; 74 | # 75 | # server { 76 | # listen localhost:110; 77 | # protocol pop3; 78 | # proxy on; 79 | # } 80 | # 81 | # server { 82 | # listen localhost:143; 83 | # protocol imap; 84 | # proxy on; 85 | # } 86 | #} 87 | 88 | -------------------------------------------------------------------------------- /ssl_server/supervisord.conf: -------------------------------------------------------------------------------- 1 | [supervisord] 2 | nodaemon=true 3 | 4 | [program:nginx] 5 | command=/usr/sbin/nginx -c /etc/nginx/nginx.conf 6 | 7 | 8 | -------------------------------------------------------------------------------- /web_server/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:16.04 2 | 3 | LABEL maintainer="Alankrit Srivastava " 4 | 5 | RUN apt-get update \ 6 | && apt-get -y install apache2 nano mysql-client \ 7 | && a2enmod rewrite \ 8 | && a2enmod headers \ 9 | && export LANG=en_US.UTF-8 \ 10 | && apt-get update \ 11 | && apt-get install -y software-properties-common \ 12 | && apt-get install -y language-pack-en-base \ 13 | && LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php \ 14 | && apt-get update \ 15 | && apt-get -y install php7.1 php7.1-curl php7.1-intl php7.1-gd php7.1-dom php7.1-mcrypt php7.1-iconv php7.1-xsl php7.1-mbstring php7.1-ctype php7.1-zip php7.1-pdo php7.1-xml php7.1-bz2 php7.1-calendar php7.1-exif php7.1-fileinfo php7.1-json php7.1-mysqli php7.1-mysql php7.1-posix php7.1-tokenizer php7.1-xmlwriter php7.1-xmlreader php7.1-phar php7.1-soap php7.1-mysql php7.1-fpm php7.1-bcmath libapache2-mod-php7.1 \ 16 | && sed -i -e"s/^memory_limit\s*=\s*128M/memory_limit = 512M/" /etc/php/7.1/apache2/php.ini \ 17 | && rm /var/www/html/* \ 18 | && sed -i "s/None/all/g" /etc/apache2/apache2.conf \ 19 | && sed -i "s/80/8080/g" /etc/apache2/ports.conf /etc/apache2/sites-enabled/000-default.conf \ 20 | ##install supervisor and setup supervisord.conf file 21 | && apt-get install -y supervisor \ 22 | && mkdir -p /var/log/supervisor 23 | env APACHE_RUN_USER www-data 24 | env APACHE_RUN_GROUP www-data 25 | env APACHE_PID_FILE /var/run/apache2.pid 26 | env APACHE_RUN_DIR /var/run/apache2 27 | env APACHE_LOCK_DIR /var/lock/apache2 28 | env APACHE_LOG_DIR /var/log/apache2 29 | env LANG C 30 | 31 | WORKDIR /var/www/html 32 | 33 | CMD ["/usr/bin/supervisord"] 34 | 35 | -------------------------------------------------------------------------------- /web_server/supervisord.conf: -------------------------------------------------------------------------------- 1 | [supervisord] 2 | nodaemon=true 3 | 4 | [program:apache2] 5 | command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND" 6 | 7 | [program:user_permission] 8 | command=/bin/bash -c "chown -R www-data: /var/www/" 9 | --------------------------------------------------------------------------------