Skip to content

Commit

Permalink
Update Dev container setup
Browse files Browse the repository at this point in the history
  • Loading branch information
akunzai committed Apr 20, 2024
1 parent e8455a7 commit 31e9016
Show file tree
Hide file tree
Showing 11 changed files with 577 additions and 68 deletions.
37 changes: 37 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Dev Containers

## Requirements

- [Docker Engine](https://docs.docker.com/install/)
- [Docker Compose V2](https://docs.docker.com/compose/cli-command/)
- [mkcert](https://github.com/FiloSottile/mkcert)
- [Visual Studio Code](https://code.visualstudio.com/)
- Bash

## Getting Start

```sh
# set up TLS certs and hosts in Host
./init.sh www.dev.local store.dev.local

# starting container or open folder in container
docker compose up -d

# install OpenMage
./openmage/install.sh
```

## Admin URLs

- [OpenMage](https://store.dev.local/admin/)
- [Joomla!](https://www.dev.local/administrator/)

## Credentials

- Username: `admin`
- Password: `ChangeTheP@ssw0rd`

## Setup

- [OpenMage](./openmage/)
- [Joomla!](./joomla/)
85 changes: 72 additions & 13 deletions .devcontainer/compose.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,90 @@
version: '2'

name: magebridgecore_devcontainer
services:
joomla:
build:
context: .
dockerfile: Dockerfile
args:
VARIANT: "8.1-apache-bookworm"
JOOMLA_VERSION: "3.10.11"
context: ./joomla
image: joomla:3.10-magebridge
volumes:
- ..:/workspace:cached
- joomla-data:/var/www/html
- ..:/workspace:cached
- ./php.ini:/usr/local/etc/php/php.ini:ro
- ./joomla/log:/var/www/html/administrator/logs
environment:
JOOMLA_DB_HOST: ${JOOMLA_DB_HOST:-mysql}
JOOMLA_DB_PASSWORD: ${JOOMLA_DB_PASSWORD:-${MYSQL_ROOT_PASSWORD:-secret}}
# https://xdebug.org/docs/all_settings
XDEBUG_CONFIG: 'client_host=localhost log=/tmp/xdebug.log'
XDEBUG_MODE: debug
external_links:
- traefik:store.dev.local
labels:
- traefik.enable=true
- traefik.http.routers.joomla.entrypoints=websecure
- traefik.http.routers.joomla.rule=Host(`www.dev.local`)
depends_on:
- mysql
- traefik

openmage:
build:
context: ./openmage
image: openmage:1.9-magebridge
volumes:
- openmage-data:/var/www/html
- ..:/var/www/html/.modman/MageBridge:cached
- ./php.ini:/usr/local/etc/php/php.ini:ro
- ./openmage/log:/var/www/html/var/log
environment:
JOOMLA_DB_HOST: mysql
JOOMLA_DB_PASSWORD: secret
# https://github.com/OpenMage/magento-lts/blob/32773dd4f82bb44bac89e8eca97379dad2a10af5/app/Mage.php#L22
# MAGE_IS_DEVELOPER_MODE: '1'
# https://xdebug.org/docs/all_settings
XDEBUG_CONFIG: 'client_host=localhost log=/tmp/xdebug.log'
XDEBUG_MODE: debug
external_links:
- traefik:www.dev.local
labels:
- traefik.enable=true
- traefik.http.routers.openmage.entrypoints=websecure
- traefik.http.routers.openmage.rule=Host(`store.dev.local`)
depends_on:
- mysql
- traefik

mysql:
# https://hub.docker.com/_/mysql
image: mysql
volumes:
- mysql-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: joomla
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-secret}
MYSQL_DATABASE: ${MYSQL_DATABASE:-openmage}
ports:
- 127.0.0.1:3306:3306

traefik:
# https://hub.docker.com/_/traefik
image: traefik
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./traefik/etc:/etc/traefik
- ./certs:/etc/traefik/certs
command:
- --api.insecure=true
- --api.dashboard=true
- --entrypoints.web.address=:80
- --entrypoints.web.http.redirections.entryPoint.to=websecure
- --entrypoints.web.http.redirections.entryPoint.scheme=https
- --entrypoints.websecure.address=:443
- --entrypoints.websecure.http.tls=true
- --providers.docker=true
- --providers.docker.exposedByDefault=false
- --providers.file.directory=/etc/traefik/dynamic/
ports:
- 127.0.0.1:80:80
- 127.0.0.1:443:443
- 127.0.0.1:9090:8080

volumes:
joomla-data: null
mysql-data: null
mysql-data: null
openmage-data: null
32 changes: 32 additions & 0 deletions .devcontainer/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

set -euo pipefail

if [ $# -le 0 ] || [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
echo "Usage: $0 <host> [<host>...]"
exit 1
fi

for host in "$@"; do
if ! grep -q "${host}" /etc/hosts; then
echo "127.0.0.1 ${host}" | sudo tee -a /etc/hosts
fi
done

CURRENTDIR=$(dirname "$0")
CERT_FILE="${CURRENTDIR}/certs/cert.pem"
KEY_FILE="${CURRENTDIR}/certs/key.pem"

if [ -e "${KEY_FILE}" ] && [ -e "${CERT_FILE}" ]; then
echo "Certificate already exists"
exit 0
fi

if [ -z "$(command -v mkcert)" ]; then
echo "mkcert is not installed, try 'brew install mkcert'"
exit 1
fi

mkcert -install
mkdir -vp $(dirname "$CERT_FILE")
mkcert -cert-file "$CERT_FILE" -key-file "$KEY_FILE" $@
99 changes: 44 additions & 55 deletions .devcontainer/joomla/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
# https://mcr.microsoft.com/v2/vscode/devcontainers/php/tags/list
ARG VARIANT=8.1-apache-bookworm
# https://github.com/devcontainers/images/blob/main/src/php/.devcontainer/Dockerfile
FROM mcr.microsoft.com/vscode/devcontainers/php:${VARIANT}
ARG PHP_VERSION=7.4
# https://hub.docker.com/_/joomla
ARG JOOMLA_VERSION=3.10.12

ENV LANG=C.UTF-8
# Disable remote database security requirements.
ENV JOOMLA_INSTALLATION_DISABLE_LOCALHOST_CHECK=1
FROM joomla:${JOOMLA_VERSION}-apache AS joomla

# install MariaDB client
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get install -y mariadb-client \
# https://hub.docker.com/_/php
FROM php:${PHP_VERSION}-apache

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/*

# enable Apache2 modules
RUN a2enmod rewrite expires include deflate remoteip headers;
# 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.
# install the PHP extensions we need
RUN set -eux; \
savedAptMark="$(apt-mark showmanual)"; \
apt-get update; \
apt-get install -y --no-install-recommends \
libfreetype6-dev libicu-dev libjpeg62-turbo-dev \
libpng-dev libxslt1-dev libzip-dev libwebp-dev libxml2-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 soap \
intl gd mysqli pcntl pdo_mysql xsl zip; \
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-3.1.6; \
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; \
Expand All @@ -40,50 +50,29 @@ RUN set -eux; \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
rm -rf /var/lib/apt/lists/*;

# set recommended PHP.ini settings
# see https://secure.php.net/manual/en/opcache.installation.php
# set up Apache2
RUN set -eux; \
docker-php-ext-enable opcache; \
{ \
echo 'opcache.memory_consumption=128'; \
echo 'opcache.interned_strings_buffer=8'; \
echo 'opcache.max_accelerated_files=4000'; \
echo 'opcache.revalidate_freq=2'; \
echo 'opcache.fast_shutdown=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
# set recommended error logging
RUN { \
# https://www.php.net/manual/en/errorfunc.constants.php
echo 'error_reporting = E_ERROR | E_WARNING | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING | E_RECOVERABLE_ERROR'; \
echo 'display_errors = Off'; \
echo 'display_startup_errors = Off'; \
echo 'log_errors = On'; \
echo 'error_log = /dev/stderr'; \
echo 'log_errors_max_len = 1024'; \
echo 'ignore_repeated_errors = On'; \
echo 'ignore_repeated_source = Off'; \
echo 'html_errors = Off'; \
} > /usr/local/etc/php/conf.d/error-logging.ini
# 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;

# Xdebug's default debugging port has changed from 9000 to 9003 since v3
RUN sed -i 's/9000/9003/' /usr/local/etc/php/conf.d/xdebug.ini
# Reset step debugging activation from yes to default (trigger)
RUN sed -i '/xdebug.start_with_request/d' /usr/local/etc/php/conf.d/xdebug.ini
# install composer
# https://hub.docker.com/_/composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

# https://hub.docker.com/_/joomla
ARG JOOMLA_VERSION=3.10.11
# Download package and extract to web volume
RUN set -ex; \
curl -o joomla.tar.bz2 -SL https://github.com/joomla/joomla-cms/releases/download/${JOOMLA_VERSION}/Joomla_${JOOMLA_VERSION}-Stable-Full_Package.tar.bz2; \
mkdir /usr/src/joomla; \
tar -xf joomla.tar.bz2 -C /usr/src/joomla; \
rm joomla.tar.bz2; \
chown -R www-data:www-data /usr/src/joomla; \
# set up Joomla!
# Disable remote database security requirements.
ENV JOOMLA_INSTALLATION_DISABLE_LOCALHOST_CHECK=1
COPY --from=joomla /entrypoint.sh /
COPY --from=joomla /makedb.php /
COPY --from=joomla --chown=www-data:www-data /usr/src/joomla /usr/src/joomla
RUN set -eux; \
chown -R www-data:www-data /usr/src/joomla; \
chmod -R g+w /usr/src/joomla;

COPY --from=joomla:3.10.11 /entrypoint.sh /entrypoint.sh
COPY --from=joomla:3.10.11 /makedb.php /makedb.php

EXPOSE 8080
ENTRYPOINT ["/entrypoint.sh"]
CMD ["apache2-foreground"]
66 changes: 66 additions & 0 deletions .devcontainer/joomla/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Joomla! Setup

## Extension Installation

> System->Install->Extensions
Upload Package File: `pkg_magebridge.zip`

## Enable Extensions

> System->Manage->Extensions
- Plugin: `Authentication - MageBridge`
- Plugin: `Content - MageBridge`
- Plugin: `MageBridge - Core`
- Plugin: `Magento - MageBridge`
- Plugin: `System - MageBridge`
- Plugin: `User - MageBridge`

## Configuration

> Components->`MageBridge`->Configuration
### API

- Hostname: `store.dev.local`
- API User: `magebridge_api`
- API Key: `ChangeTheAp1K3y`

### Bridge

- Protocol: `HTTPS`
- Enforce SSL: `Entire site`

### Users

User synchronization

- Magento Customer Group: `General`
- Joomla! Usergroup: `Registered`
- Username from Email: `Yes`

User importing and exporting

- Website: `Main Website (1)`
- Customer Group: `General`

## Add Root item

> Menus->`Main Menu`->`Add New Menu Item`
### Details

- Title: `Store`
- Alias: `store`
- Menu Item Type: `MageBridge`->`Root`

### Magento Scope

- Store/Store View: `English(default)`

## System Check

> Components->`MageBridge`->`System Check`
Ensure all necessary checks have passed!
Loading

0 comments on commit 31e9016

Please sign in to comment.