Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.idea/*
.DS_Store
Docker/
30 changes: 30 additions & 0 deletions Docker/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
COMPOSE_PROJECT_NAME=zip-magento2

ZIPMONEY_SANDBOX_PUBLIC_KEY=
ZIPMONEY_SANDBOX_PRIVATE_KEY=
MAGE_REPO_PUBLIC_KEY=
MAGE_REPO_PRIVATE_KEY=

MAGENTO_VERSION=2.4.5-p1
PHP_VERSION=8.1.1
ELASTICSEARCH_VERSION=7.17.8
MARIADB_VERSION=10.4

[email protected]
MAGENTO_ADMIN_FIRSTNAME=Shitiz
MAGENTO_ADMIN_LASTNAME=Garg
MAGENTO_ADMIN_USERNAME=admin
MAGENTO_ADMIN_PASSWORD=Testing1234;
MAGENTO_ENCRYPTION_KEY=d25657075d00b940ff37edd2f8ecd4df

MAGENTO_HOST=localhost
MAGENTO_EXTERNAL_HTTP_PORT=8080
MAGENTO_EXTERNAL_HTTPS_PORT=8443
MAGENTO_DATABASE_HOST=mariadb
MAGENTO_DATABASE_PORT=3306
MAGENTO_DATABASE_USER=bn_magento
MAGENTO_DATABASE_NAME=bitnami_magento
MAGENTO_DATABASE_PASSWORD=test1234
ELASTICSEARCH_HOST=elasticsearch
ELASTICSEARCH_PORT=9200
SENDMAIL_PATH='/usr/local/bin/mhsendmail --smtp-addr="mailhog:1025"'
96 changes: 96 additions & 0 deletions Docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
version: '3'
services:
mariadb:
image: mariadb:$MARIADB_VERSION
environment:
- MARIADB_USER=$MAGENTO_DATABASE_USER
- MARIADB_DATABASE=$MAGENTO_DATABASE_NAME
- MARIADB_PASSWORD=$MAGENTO_DATABASE_PASSWORD
- MARIADB_ROOT_PASSWORD=$MAGENTO_DATABASE_PASSWORD
volumes:
- 'mariadb:/var/lib/mysql'

elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:$ELASTICSEARCH_VERSION
volumes:
- 'elasticsearch:/usr/share/elasticsearch/data'
environment:
- discovery.type=single-node
- xpack.security.enabled=false
- "ES_JAVA_OPTS=-Xms2G -Xmx2G"
ulimits:
memlock:
soft: -1
hard: -1

# Note: This image purely exists to install and build Magento. The primary reason we separated out CLI and FPM
# are because:
# 1) Cannot mount Zip plugin properly before composer has installed because then /app/app/code directory wouldn't be empty
# and composer would refuse installation. PS: Mounting to a separate directory and symlinking doesn't work either,
# since Magento keeps throwing an error that templates are outside Magento's root. The solution was to have a separate image
# which copies the plugin files into module directory after composer has setup Magento, installs the module, deletes the module
# then transfer the files into the Web VM where the plugin is directly mounted from the source files.
# 2) It is way faster on macOS to build within a Docker VM then move the files to outside FS for persistance then it is
# to install the files on a mounted folder.
php-cli-magento:
build:
context: ./php-cli-magento
args:
PHP_VERSION: ${PHP_VERSION}
env_file:
- './.env'
volumes:
- 'magento:/app-dest'
- '..:/magento-zip'
- '/magento-zip/Docker'
- '/magento-zip/.git'
- 'composer:/composer'
depends_on:
- mariadb
- elasticsearch

# Serves Magento using PHP-FPM
php-fpm-magento:
build:
context: ./php-fpm-magento
args:
PHP_VERSION: ${PHP_VERSION:-8.1.1}
ports:
- 9000:9000
env_file:
- './.env'
volumes:
- 'magento:/app'
- '..:/app/app/code/Zip/ZipPayment'
- '/app/app/code/Zip/ZipPayment/.git'
- '/app/app/code/Zip/ZipPayment/Docker'
depends_on:
- mariadb
- elasticsearch
- php-cli-magento

nginx:
build: ./nginx
depends_on:
- php-fpm-magento
ports:
- 8000:80
- 8080:8080
environment:
- FPM_HOST=php-fpm-magento
restart: unless-stopped
volumes:
- 'magento:/app'

mailhog:
hostname: $MAGENTO_HOST
image: 'mailhog/mailhog:latest'
ports:
- '1025:1025'
- '8025:8025'

volumes:
mariadb:
elasticsearch:
magento:
composer:
40 changes: 40 additions & 0 deletions Docker/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM nginx:1.19

ENV UPLOAD_MAX_FILESIZE 64M
ENV XDEBUG_HOST fpm_xdebug
ENV FPM_HOST fpm
ENV FPM_PORT 9000
ENV UPSTREAM_HOST 127.0.0.1
ENV UPSTREAM_PORT 8080
ENV MAGENTO_ROOT /app
ENV MAGENTO_RUN_MODE developer
ENV MFTF_UTILS 0
ENV DEBUG false
ENV NGINX_WORKER_PROCESSES 1
ENV NGINX_WORKER_CONNECTIONS 1024

COPY etc/nginx.conf /etc/nginx/
COPY etc/vhost.conf /etc/nginx/conf.d/default.conf
COPY etc/xdebug-upstream.conf /etc/nginx/conf.d/xdebug/upstream.conf

RUN mkdir /etc/nginx/ssl

RUN apt-get update && \
apt-get install -y openssl

RUN openssl req -x509 -newkey rsa:2048 -sha256 -days 730 -nodes \
-keyout /etc/nginx/ssl/magento.key -out /etc/nginx/ssl/magento.crt \
-subj "/C=US/ST=TX/L=Austin/O=Adobe Commerce/OU=Cloud Docker/CN=magento2.docker" \
-addext "subjectAltName=DNS:magento2.docker,DNS:www.magento2.docker"

VOLUME ${MAGENTO_ROOT}

COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN ["chmod", "+x", "/docker-entrypoint.sh"]
ENTRYPOINT ["/docker-entrypoint.sh"]

EXPOSE 443

WORKDIR ${MAGENTO_ROOT}

CMD ["nginx", "-g", "daemon off;"]
27 changes: 27 additions & 0 deletions Docker/nginx/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

[ "$DEBUG" = "true" ] && set -x

VHOST_FILE="/etc/nginx/conf.d/default.conf"
NGINX_FILE="/etc/nginx/nginx.conf"
XDEBUG_UPSTREAM_FILE="/etc/nginx/conf.d/xdebug/upstream.conf"

[ ! -z "${FPM_HOST}" ] && sed -i "s/!FPM_HOST!/${FPM_HOST}/" $VHOST_FILE
[ ! -z "${XDEBUG_HOST}" ] && sed -i "s/!XDEBUG_HOST!/${XDEBUG_HOST}/" $XDEBUG_UPSTREAM_FILE
[ ! -z "${FPM_PORT}" ] && sed -i "s/!FPM_PORT!/${FPM_PORT}/" $VHOST_FILE
[ ! -z "${FPM_PORT}" ] && sed -i "s/!FPM_PORT!/${FPM_PORT}/" $XDEBUG_UPSTREAM_FILE
[ ! -z "${UPSTREAM_HOST}" ] && sed -i "s/!UPSTREAM_HOST!/${UPSTREAM_HOST}/" $VHOST_FILE
[ ! -z "${UPSTREAM_PORT}" ] && sed -i "s/!UPSTREAM_PORT!/${UPSTREAM_PORT}/" $VHOST_FILE
[ ! -z "${MAGENTO_ROOT}" ] && sed -i "s#!MAGENTO_ROOT!#${MAGENTO_ROOT}#" $VHOST_FILE
[ ! -z "${MAGENTO_RUN_MODE}" ] && sed -i "s/!MAGENTO_RUN_MODE!/${MAGENTO_RUN_MODE}/" $VHOST_FILE
[ ! -z "${MFTF_UTILS}" ] && sed -i "s/!MFTF_UTILS!/${MFTF_UTILS}/" $VHOST_FILE
[ ! -z "${UPLOAD_MAX_FILESIZE}" ] && sed -i "s/!UPLOAD_MAX_FILESIZE!/${UPLOAD_MAX_FILESIZE}/" $VHOST_FILE
[ ! -z "${WITH_XDEBUG}" ] && sed -i "s/!WITH_XDEBUG!/${WITH_XDEBUG}/" $VHOST_FILE
[ "${WITH_XDEBUG}" == "1" ] && sed -i "s/#include_xdebug_upstream/include/" $NGINX_FILE
[ ! -z "${NGINX_WORKER_PROCESSES}" ] && sed -i "s/!NGINX_WORKER_PROCESSES!/${NGINX_WORKER_PROCESSES}/" $NGINX_FILE
[ ! -z "${NGINX_WORKER_CONNECTIONS}" ] && sed -i "s/!NGINX_WORKER_CONNECTIONS!/${NGINX_WORKER_CONNECTIONS}/" $NGINX_FILE

# Check if the nginx syntax is fine, then launch.
nginx -t

exec "$@"
34 changes: 34 additions & 0 deletions Docker/nginx/etc/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
worker_processes !NGINX_WORKER_PROCESSES!;

error_log /var/log/nginx/error.log debug;
pid /var/run/nginx.pid;

events {
# this should be equal to value of "ulimit -n"
# reference: https://www.digitalocean.com/community/tutorials/how-to-optimize-nginx-configuration
worker_connections !NGINX_WORKER_CONNECTIONS!;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main
'$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

client_max_body_size 20M;

#include_xdebug_upstream /etc/nginx/conf.d/xdebug/upstream.conf;
include /etc/nginx/conf.d/*.conf;
}
Loading