Skip to content

Commit 6943c28

Browse files
author
Alankrit Srivastava
committed
first commit
0 parents  commit 6943c28

File tree

42,281 files changed

+5528714
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42,281 files changed

+5528714
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# magento2-varnish-redis-ssl-docker-compose

Diff for: backups/backup.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
set -x
4+
## Mention your database container name
5+
container_name=mysql
6+
7+
## Mention your mysql root password
8+
mysql_root_password=rootpassword123
9+
10+
DATE=`date +%F-%H-%M-%S`
11+
12+
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`
13+
do
14+
echo $database
15+
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
16+
done
17+

Diff for: cache_server/Dockerfile

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
From ubuntu:14.04
2+
3+
MAINTAINER Alankrit Srivastava [email protected]
4+
5+
##update server
6+
7+
RUN apt-get update \
8+
9+
##install supervisor and setup supervisord.conf file
10+
11+
&& apt-get install -y supervisor \
12+
13+
&& mkdir -p /var/log/supervisor \
14+
15+
##install varnish
16+
17+
&& apt-get -y install varnish \
18+
19+
&& rm /etc/varnish/default.vcl \
20+
21+
&& rm /etc/default/varnish
22+
23+
EXPOSE 6082 80
24+
25+
CMD ["/usr/bin/supervisord"]

Diff for: cache_server/default.vcl

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import std;
2+
# The minimal Varnish version is 3.0.5
3+
# For SSL offloading, pass the following header in your proxy server or load balancer: 'X-Forwarded-Proto: https'
4+
5+
6+
backend default {
7+
.host = "apache2";
8+
.port = "8080";
9+
}
10+
11+
acl purge {
12+
"127.0.0.1";
13+
}
14+
15+
sub vcl_recv {
16+
if (req.restarts == 0) {
17+
if (req.http.x-forwarded-for) {
18+
set req.http.X-Forwarded-For =
19+
req.http.X-Forwarded-For + ", " + client.ip;
20+
} else {
21+
set req.http.X-Forwarded-For = client.ip;
22+
}
23+
}
24+
25+
if (req.request == "PURGE") {
26+
if (client.ip !~ purge) {
27+
error 405 "Method not allowed";
28+
}
29+
if (!req.http.X-Magento-Tags-Pattern) {
30+
error 400 "X-Magento-Tags-Pattern header required";
31+
}
32+
ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
33+
error 200 "Purged";
34+
}
35+
36+
if (req.request != "GET" &&
37+
req.request != "HEAD" &&
38+
req.request != "PUT" &&
39+
req.request != "POST" &&
40+
req.request != "TRACE" &&
41+
req.request != "OPTIONS" &&
42+
req.request != "DELETE") {
43+
/* Non-RFC2616 or CONNECT which is weird. */
44+
return (pipe);
45+
}
46+
47+
# We only deal with GET and HEAD by default
48+
if (req.request != "GET" && req.request != "HEAD") {
49+
return (pass);
50+
}
51+
52+
# Bypass shopping cart, checkout and search requests
53+
if (req.url ~ "/checkout" || req.url ~ "/catalogsearch") {
54+
return (pass);
55+
}
56+
57+
# normalize url in case of leading HTTP scheme and domain
58+
set req.url = regsub(req.url, "^http[s]?://", "");
59+
60+
# collect all cookies
61+
std.collect(req.http.Cookie);
62+
63+
# static files are always cacheable. remove SSL flag and cookie
64+
if (req.url ~ "^/(pub/)?(media|static)/.*\.(ico|css|js|jpg|jpeg|png|gif|tiff|bmp|gz|tgz|bz2|tbz|mp3|ogg|svg|swf|woff|woff2|eot|ttf|otf)$") {
65+
unset req.http.Https;
66+
unset req.http.X-Forwarded-Proto;
67+
unset req.http.Cookie;
68+
}
69+
70+
set req.grace = 1m;
71+
72+
return (lookup);
73+
}
74+
75+
sub vcl_hash {
76+
if (req.http.cookie ~ "X-Magento-Vary=") {
77+
hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "\1"));
78+
}
79+
80+
if (req.http.X-Forwarded-Proto) {
81+
hash_data(req.http.X-Forwarded-Proto);
82+
}
83+
84+
}
85+
86+
sub vcl_fetch {
87+
if (beresp.http.content-type ~ "text") {
88+
set beresp.do_esi = true;
89+
}
90+
91+
if (req.url ~ "\.js$" || beresp.http.content-type ~ "text") {
92+
set beresp.do_gzip = true;
93+
}
94+
95+
# cache only successfully responses and 404s
96+
if (beresp.status != 200 && beresp.status != 404) {
97+
set beresp.ttl = 0s;
98+
return (hit_for_pass);
99+
} elsif (beresp.http.Cache-Control ~ "private") {
100+
return (hit_for_pass);
101+
}
102+
103+
if (beresp.http.X-Magento-Debug) {
104+
set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control;
105+
}
106+
107+
# validate if we need to cache it and prevent from setting cookie
108+
# images, css and js are cacheable by default so we have to remove cookie also
109+
if (beresp.ttl > 0s && (req.request == "GET" || req.request == "HEAD")) {
110+
unset beresp.http.set-cookie;
111+
if (req.url !~ "\.(ico|css|js|jpg|jpeg|png|gif|tiff|bmp|mp3|ogg|svg|swf|woff|woff2|eot|ttf|otf)(\?|$)") {
112+
set beresp.http.Pragma = "no-cache";
113+
set beresp.http.Expires = "-1";
114+
set beresp.http.Cache-Control = "no-store, no-cache, must-revalidate, max-age=0";
115+
set beresp.grace = 1m;
116+
}
117+
}
118+
}
119+
120+
sub vcl_deliver {
121+
if (resp.http.X-Magento-Debug) {
122+
if (obj.hits > 0) {
123+
set resp.http.X-Magento-Cache-Debug = "HIT";
124+
} else {
125+
set resp.http.X-Magento-Cache-Debug = "MISS";
126+
}
127+
} else {
128+
unset resp.http.Age;
129+
}
130+
131+
unset resp.http.X-Magento-Debug;
132+
unset resp.http.X-Magento-Tags;
133+
unset resp.http.X-Powered-By;
134+
unset resp.http.Server;
135+
unset resp.http.X-Varnish;
136+
unset resp.http.Via;
137+
unset resp.http.Link;
138+
}

Diff for: cache_server/supervisord.conf

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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"

Diff for: cache_server/varnish

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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=""

Diff for: database_server/Dockerfile

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
From ubuntu:14.04
2+
3+
MAINTAINER Alankrit Srivastava [email protected]
4+
5+
ARG mysql_password
6+
7+
##update server
8+
9+
RUN apt-get update \
10+
11+
## Install mysql-server
12+
13+
&& DEBIAN_FRONTEND=noninteractive apt-get -y install debconf-utils \
14+
15+
&& echo "mysql-server-5.6 mysql-server/root_password password ${mysql_password}" | debconf-set-selections \
16+
17+
&& echo "mysql-server-5.6 mysql-server/root_password_again password ${mysql_password}" | debconf-set-selections \
18+
19+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server-5.6 \
20+
21+
&& sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf \
22+
23+
##install supervisor and setup supervisord.conf file
24+
25+
&& apt-get install -y supervisor \
26+
27+
&& mkdir -p /var/log/supervisor
28+
29+
VOLUME /var/lib/mysql
30+
31+
Expose 3306
32+
33+
CMD ["/usr/bin/supervisord"]

Diff for: database_server/mysql.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
set -x
4+
database_name=magento_db ## Mention database name
5+
database_user=magento_user ## Mention database user
6+
database_root_password=rootpassword123 ## Mention mysql root password.
7+
8+
## Same password must be passed as argument during image build.
9+
10+
## Database user password will be randomly generated
11+
12+
database_user_password=`date | md5sum | fold -w 12 | head -n 1`
13+
14+
## Database user password will be stored in /var/log/check.log ##
15+
## Remove /var/log/check.log after retrieving password . ##
16+
17+
database_availability_check=`mysqlshow --user=root --password=$database_root_password | grep -ow $database_name`
18+
19+
if [ "$database_availability_check" == "$database_name" ]; then
20+
exit 1
21+
else
22+
mysql -u root -p$database_root_password -e "create database $database_name;"
23+
mysql -u root -p$database_root_password -e "grant all on $database_name.* to '$database_user'@'%' identified by '$database_user_password';"
24+
echo "Your database user "$database_user" password for database "$database_name" is "$database_user_password"" > /var/log/check.log
25+
fi
26+

Diff for: database_server/supervisord.conf

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[supervisord]
2+
nodaemon=true
3+
4+
[program:mysql]
5+
command=/usr/bin/mysqld_safe
6+
7+
[program:script_of_user_creation]
8+
command=/bin/bash -c "chmod a+x /etc/mysql.sh; /etc/mysql.sh"

0 commit comments

Comments
 (0)