Skip to content

Instantly share code, notes, and snippets.

@akunzai
Last active February 4, 2024 03:37
Show Gist options
  • Save akunzai/8a14d7ee7b7a567f1d424f612477f08c to your computer and use it in GitHub Desktop.
Save akunzai/8a14d7ee7b7a567f1d424f612477f08c to your computer and use it in GitHub Desktop.
version: '2'
services:
openmage:
build:
context: .
image: openmage:20.3.0
volumes:
- openmage-data:/var/www/html
- ./php.ini:/usr/local/etc/php/php.ini:ro
environment:
MAGE_IS_DEVELOPER_MODE: '1'
ports:
- "127.0.0.1:80:80"
depends_on:
- mysql
mysql:
# https://hub.docker.com/_/mysql
image: mysql
volumes:
- mysql-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-secret}
MYSQL_DATABASE: ${MYSQL_DATABASE:-openmage}
volumes:
mysql-data: null
openmage-data: null
#!/bin/env bash
set -e
if [[ "$1" == apache2* ]]; then
uid="$(id -u)"
gid="$(id -g)"
if [ "$uid" = '0' ]; then
case "$1" in
apache2*)
user="${APACHE_RUN_USER:-www-data}"
group="${APACHE_RUN_GROUP:-www-data}"
# strip off any '#' symbol ('#1000' is valid syntax for Apache)
pound='#'
user="${user#$pound}"
group="${group#$pound}"
# set user if not exist
if ! id "$user" &>/dev/null; then
# get the user name
: "${USER_NAME:=www-data}"
# change the user name
[[ "$USER_NAME" != "www-data" ]] &&
usermod -l "$USER_NAME" www-data &&
groupmod -n "$USER_NAME" www-data
# update the user ID
groupmod -o -g "$user" "$USER_NAME"
# update the user-group ID
usermod -o -u "$group" "$USER_NAME"
fi
;;
*)
user='www-data'
group='www-data'
;;
esac
else
user="$uid"
group="$gid"
fi
if [ ! -e '/var/www/html/app/etc/config.xml' ]; then
sourceTarArgs=(
--create
--file -
--directory /usr/src/openmage
--one-file-system
--owner "$user" --group "$group"
)
targetTarArgs=(
--extract
--file -
--directory /var/www/html
)
if [ "$uid" != '0' ]; then
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
targetTarArgs+=(--no-overwrite-dir)
fi
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
echo >&2 "OpenMage has been successfully copied to /var/www/html"
fi
fi
exec "$@"
# https://github.com/colinmollenhour/docker-openmage/blob/main/8.2/apache/Dockerfile
# https://github.com/OpenMage/magento-lts/tree/main/dev/openmage
ARG PHP_VERSION=8.2
ARG OPENMAGE_VERSION=20.3.0
FROM alpine as unzipper
ARG OPENMAGE_VERSION
RUN set -eux; \
apk add curl unzip; \
mkdir -p /usr/src/openmage; \
curl -Lo /tmp/openmage.zip https://github.com/OpenMage/magento-lts/releases/download/v${OPENMAGE_VERSION}/openmage-v${OPENMAGE_VERSION}.zip; \
unzip /tmp/openmage.zip -d /usr/src/openmage; \
rm /tmp/openmage.zip;
# https://hub.docker.com/_/php
FROM php:${PHP_VERSION}-apache-bookworm
ENV LANG=en_US.UTF-8
# install MySQL client
RUN apt-get update && \
apt-get install -y --no-install-recommends default-mysql-client && \
apt-get clean -y && rm -rf /var/lib/apt/lists/*
# install pickle
# https://github.com/FriendsOfPHP/pickle
RUN set -eux; \
curl -Lo /usr/local/bin/pickle https://github.com/FriendsOfPHP/pickle/releases/latest/download/pickle.phar && \
chmod +x /usr/local/bin/pickle;
# install the PHP extensions we need
RUN set -eux; \
# https://github.com/colinmollenhour/modman
curl -fSL -o /usr/local/bin/modman https://raw.githubusercontent.com/colinmollenhour/modman/master/modman && \
chmod +x /usr/local/bin/modman; \
# https://github.com/netz98/n98-magerun
curl -fSL -o /usr/local/bin/n98-magerun https://files.magerun.net/n98-magerun.phar && \
chmod +x /usr/local/bin/n98-magerun; \
# install the PHP extensions we need
savedAptMark="$(apt-mark showmanual)"; \
apt-get update; \
apt-get install -y --no-install-recommends default-mysql-client \
libfreetype6-dev libicu-dev libjpeg62-turbo-dev libonig-dev \
libpng-dev libxml2-dev libxslt1-dev libzip-dev libwebp-dev \
${PHP_EXTRA_BUILD_DEPS:-}; \
# https://www.php.net/manual/en/image.installation.php
docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg --with-webp; \
docker-php-ext-install -j$(nproc) opcache \
intl gd mysqli pcntl pdo_mysql soap xsl zip; \
pickle install --no-interaction apcu; \
pickle install --no-interaction redis; \
pickle install --no-interaction xdebug; \
docker-php-ext-enable apcu opcache redis xdebug; \
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
apt-mark auto '.*' > /dev/null; \
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \
find /usr/local -type f -executable -exec ldd '{}' ';' \
| awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); print so }' \
| sort -u \
| xargs -r dpkg-query --search \
| cut -d: -f1 \
| sort -u \
| xargs -r apt-mark manual; \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
rm -rf /var/lib/apt/lists/*;
# set up Apache2
RUN set -eux; \
# enable Apache2 modules
a2enmod rewrite expires include deflate remoteip headers; \
# disable Apache2 server signature
echo 'ServerSignature Off' >> /etc/apache2/apache2.conf; \
echo 'ServerTokens Prod' >> /etc/apache2/apache2.conf; \
# enable support for TLS termination
echo 'SetEnvIf X-Forwarded-Proto https HTTPS=on' >> /etc/apache2/apache2.conf;
# install composer
# https://hub.docker.com/_/composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
# install modman
# https://github.com/colinmollenhour/modman
RUN set -eux; \
curl -fSL -o /usr/local/bin/modman https://raw.githubusercontent.com/colinmollenhour/modman/master/modman && \
chmod +x /usr/local/bin/modman;
# install n98-magerun
# https://github.com/netz98/n98-magerun
RUN set -eux; \
curl -fSL -o /usr/local/bin/n98-magerun https://files.magerun.net/n98-magerun.phar && \
chmod +x /usr/local/bin/n98-magerun;
# set up OpenMage
COPY --chmod=755 ./docker-entrypoint.sh /
COPY --from=unzipper --chown=www-data:www-data /usr/src/openmage /usr/src/openmage
RUN set -eux; \
chmod +x /docker-entrypoint.sh; \
chown -R www-data:www-data /usr/src/openmage; \
chmod -R g+w /usr/src/openmage;
ENTRYPOINT [ "/docker-entrypoint.sh" ]
CMD [ "apache2-foreground" ]
#!/usr/bin/env bash
# https://github.com/OpenMage/magento-lts/blob/main/dev/openmage/install.sh
[ -f .env ] && source .env
docker compose exec openmage test -f app/etc/local.xml
if [ "$?" -eq "0" ]; then
echo "OpenMage already installed!"
exit 0
fi
echo "Checking database..."
for i in $(seq 1 20); do
docker compose exec mysql sh -c "mysql -uroot -p${MYSQL_ROOT_PASSWORD:-secret} -e 'show databases;' 2>/dev/null" | grep -qF 'openmage' && break
sleep 1
done
echo "Installing OpenMage..."
docker compose exec openmage php install.php \
--admin_firstname OpenMage \
--admin_lastname Admin \
--admin_username "${ADMIN_USERNAME:-admin}" \
--admin_password "${ADMIN_PASSWORD:-ChangeTheP@ssw0rd}" \
--admin_email "${ADMIN_EMAIL:[email protected]}" \
--db_host "${OPENMAGE_DB_HOST:-mysql}" \
--db_name "${OPENMAGE_DB_NAME:-openmage}" \
--db_user "${OPENMAGE_DB_USER:-root}" \
--db_pass "${OPENMAGE_DB_PASSWORD:-${MYSQL_ROOT_PASSWORD:-secret}}" \
--locale "${LOCALE:-en_US}" \
--timezone "${TIMEZONE:-America/New_York}" \
--default_currency "${CURRENCY:-USD}" \
--url "$(echo ${BASE_URL:-"https://store.dev.local"} | sed -e 's/^https:/http:/')" \
--secure_base_url "$(echo ${BASE_URL:-"https://store.dev.local"} | sed -e 's/^http:/https:/')" \
--skip_url_validation \
--license_agreement_accepted yes \
--use_rewrites yes \
--use_secure yes \
--use_secure_admin yes \
--encryption_key "${ENCRYPTION_KEY:-}"
expose_php=Off
memory_limit=512M
upload_max_filesize=256M
post_max_size=256M
max_execution_time=600
; https://www.php.net/manual/en/errorfunc.constants.php
error_reporting=E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
display_errors=Off
display_startup_errors=Off
log_errors=On
error_log=/dev/stderr
log_errors_max_len=1024
ignore_repeated_errors=On
ignore_repeated_source=Off
html_errors=Off
; https://secure.php.net/manual/en/opcache.installation.php
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=2
opcache.fast_shutdown=1
; https://www.php.net/manual/en/apcu.configuration.php
apc.enable_cli=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment