From 223c900b8695a5597b2f86ad1e19ac7164820a4b Mon Sep 17 00:00:00 2001 From: Fu Cheng Date: Thu, 14 Dec 2023 19:31:00 +0800 Subject: [PATCH] Major update, support only 2.4.x Only Magento Open Source 2.4.x will be supported --- .github/workflows/docker-publish.yml | 99 +++++++++++++++++++ Dockerfile.hbs | 52 +++++----- LICENSE | 2 +- README.md | 66 ++++++++----- crontab.hbs | 3 - developer/Dockerfile | 67 ------------- developer/crontab | 3 - developer/install-magento | 7 -- docker-compose-developer-dev.yml | 28 ------ docker-compose-integrator-dev.yml | 28 ------ docker-compose.yaml.hbs | 57 +++++++++++ docker-compose.yml | 27 ----- env | 2 + install-magento | 32 +++++- integrator/crontab | 4 - integrator/install-magento | 7 -- partials/developer/extraCronJobs | 0 partials/developer/magento2Installation | 8 -- partials/integrator/extraCronJobs | 2 - partials/integrator/magento2Installation | 2 - update.js | 84 ++++++++++------ {integrator => versions/2.4.2-p2}/Dockerfile | 55 ++++++----- {developer => versions/2.4.2-p2}/auth.json | 0 versions/2.4.2-p2/docker-compose.yaml | 57 +++++++++++ versions/2.4.2-p2/install-magento | 37 +++++++ .../2.4.2-p2}/install-sampledata | 0 versions/2.4.6-p3/Dockerfile | 62 ++++++++++++ {integrator => versions/2.4.6-p3}/auth.json | 0 versions/2.4.6-p3/docker-compose.yaml | 57 +++++++++++ versions/2.4.6-p3/install-magento | 37 +++++++ .../2.4.6-p3}/install-sampledata | 0 yarn.lock | 23 +++-- 32 files changed, 603 insertions(+), 305 deletions(-) create mode 100644 .github/workflows/docker-publish.yml delete mode 100644 crontab.hbs delete mode 100644 developer/Dockerfile delete mode 100644 developer/crontab delete mode 100644 developer/install-magento delete mode 100644 docker-compose-developer-dev.yml delete mode 100644 docker-compose-integrator-dev.yml create mode 100644 docker-compose.yaml.hbs delete mode 100644 docker-compose.yml delete mode 100644 integrator/crontab delete mode 100644 integrator/install-magento delete mode 100644 partials/developer/extraCronJobs delete mode 100644 partials/developer/magento2Installation delete mode 100644 partials/integrator/extraCronJobs delete mode 100644 partials/integrator/magento2Installation rename {integrator => versions/2.4.2-p2}/Dockerfile (52%) rename {developer => versions/2.4.2-p2}/auth.json (100%) create mode 100644 versions/2.4.2-p2/docker-compose.yaml create mode 100644 versions/2.4.2-p2/install-magento rename {developer => versions/2.4.2-p2}/install-sampledata (100%) create mode 100644 versions/2.4.6-p3/Dockerfile rename {integrator => versions/2.4.6-p3}/auth.json (100%) create mode 100644 versions/2.4.6-p3/docker-compose.yaml create mode 100644 versions/2.4.6-p3/install-magento rename {integrator => versions/2.4.6-p3}/install-sampledata (100%) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 000000000..75171387f --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,99 @@ +name: Docker + +on: + push: + branches: [ "main" ] + # Publish semver tags as releases. + tags: [ 'v*.*.*' ] + pull_request: + branches: [ "main" ] + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + id-token: write + strategy: + fail-fast: true + matrix: + version: + - 2.4.6-p3 + - 2.4.2-p2 + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Install the cosign tool except on PR + # https://github.com/sigstore/cosign-installer + - name: Install cosign + if: github.event_name != 'pull_request' + uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 #v3.1.1 + with: + cosign-release: 'v2.1.1' + + # Set up BuildKit Docker container builder to be able to build + # multi-platform images and export cache + # https://github.com/docker/setup-buildx-action + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=${{ matrix.version }} + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 + with: + context: versions/${{ matrix.version }} + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + # Sign the resulting Docker image digest except on PRs. + # This will only write to the public Rekor transparency log when the Docker + # repository is public to avoid leaking data. If you would like to publish + # transparency data even for private images, pass --force to cosign below. + # https://github.com/sigstore/cosign + - name: Sign the published Docker image + if: ${{ github.event_name != 'pull_request' }} + env: + # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable + TAGS: ${{ steps.meta.outputs.tags }} + DIGEST: ${{ steps.build-and-push.outputs.digest }} + # This step uses the identity token to provision an ephemeral certificate + # against the sigstore community Fulcio instance. + run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} diff --git a/Dockerfile.hbs b/Dockerfile.hbs index 78af42e1f..26186f2d9 100644 --- a/Dockerfile.hbs +++ b/Dockerfile.hbs @@ -1,9 +1,9 @@ -FROM quay.io/alexcheng1982/apache2-php7:{{phpVersion}} +FROM ghcr.io/alexcheng1982/docker-apache2-php8:{{phpVersion}} LABEL maintainer="alexcheng1982@gmail.com" LABEL php_version="{{phpVersion}}" LABEL magento_version="{{magento2Version}}" -LABEL description="Magento {{magento2Version}} with PHP {{phpVersion}}" +LABEL description="Magento Open Source {{magento2Version}} with PHP {{phpVersion}}" ENV MAGENTO_VERSION {{magento2Version}} ENV INSTALL_DIR /var/www/html @@ -13,30 +13,37 @@ RUN curl -sS https://getcomposer.org/installer | php \ && mv composer.phar /usr/local/bin/composer COPY ./auth.json $COMPOSER_HOME -RUN requirements="libpng++-dev libzip-dev libmcrypt-dev libmcrypt4 libcurl3-dev libfreetype6 libjpeg-turbo8 libjpeg-turbo8-dev libfreetype6-dev libicu-dev libxslt1-dev unzip" \ - && apt-get update \ - && apt-get install -y $requirements \ - && rm -rf /var/lib/apt/lists/* \ - && docker-php-ext-install pdo_mysql \ - && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \ - && docker-php-ext-install gd \ - && docker-php-ext-install mbstring \ - && docker-php-ext-install zip \ - && docker-php-ext-install intl \ - && docker-php-ext-install xsl \ - && docker-php-ext-install soap \ - && docker-php-ext-install bcmath - -RUN yes '' | pecl install mcrypt-1.0.3 \ +RUN requirements="libpng++-dev libzip-dev libmcrypt-dev libmcrypt4 libcurl3-dev libfreetype6 libjpeg-turbo8 libjpeg-turbo8-dev libfreetype6-dev libicu-dev libxslt1-dev zip unzip libxml2 libonig-dev" \ + set -eux; \ + apt-get update; \ + apt-get install -y $requirements; \ + rm -rf /var/lib/apt/lists/* + +RUN set -eux; \ + docker-php-ext-install pdo_mysql; \ + docker-php-ext-configure gd --with-freetype --with-jpeg; \ + docker-php-ext-install gd; \ + docker-php-ext-install mbstring; \ + docker-php-ext-install zip; \ + docker-php-ext-install intl; \ + docker-php-ext-install xsl; \ + docker-php-ext-install soap; \ + docker-php-ext-install sockets; \ + docker-php-ext-install bcmath + +RUN yes '' | pecl install mcrypt-1.0.6 \ && echo 'extension=mcrypt.so' > /usr/local/etc/php/conf.d/mcrypt.ini RUN chsh -s /bin/bash www-data -{{{magento2Installation}}} +RUN chown -R www-data:www-data /var/www + +RUN su www-data -c "composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition $INSTALL_DIR $MAGENTO_VERSION" RUN cd $INSTALL_DIR \ - && find . -type d -exec chmod 770 {} \; \ - && find . -type f -exec chmod 660 {} \; \ + && find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + \ + && find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} + \ + && chown -R :www-data . \ && chmod u+x bin/magento COPY ./install-magento /usr/local/bin/install-magento @@ -52,9 +59,4 @@ RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* WORKDIR $INSTALL_DIR -# Add cron job -ADD crontab /etc/cron.d/magento2-cron -RUN chmod 0644 /etc/cron.d/magento2-cron \ - && crontab -u www-data /etc/cron.d/magento2-cron - VOLUME $INSTALL_DIR \ No newline at end of file diff --git a/LICENSE b/LICENSE index 37498ff10..2f9222a84 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Fu Cheng +Copyright (c) 2023 Fu Cheng Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index c252b6e14..3357c9151 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,32 @@ -# Docker image for Magento 2 +# Docker Image for Magento Open Source 2 -[![](https://images.microbadger.com/badges/image/alexcheng/magento2.svg)](http://microbadger.com/images/alexcheng/magento2) +[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/alexcheng1982) -[![Docker build](http://dockeri.co/image/alexcheng/magento2)](https://hub.docker.com/r/alexcheng/magento2/) +**This repo ONLY maintains Docker images for Magento Open Source 2.4.x. You may still found Docker images for old versions in the [old registry](https://quay.io/repository/alexcheng1982/magento2).** -[![Docker Repository on Quay](https://quay.io/repository/alexcheng1982/magento2/status "Docker Repository on Quay")](https://quay.io/repository/alexcheng1982/magento2) +**Starting from Magento 2.4.x, container images are now hosted in GitHub Container Registry.** -This repo provides Docker images for different Magento 2 versions. Refer to [this page](https://hub.docker.com/r/alexcheng/magento2/tags/) to see all available tags. It uses the same convention as my [Docker image for Magento 1.x](https://github.com/alexcheng1982/docker-magento). +This repo provides Docker images for different Magento 2.4 versions. Refer to [this page](https://hub.docker.com/r/alexcheng/magento2/tags/) to see all available tags. It uses the same convention as my [Docker image for Magento 1.x](https://github.com/alexcheng1982/docker-magento). -This docker image is based on my [docker-apache2-php7](https://github.com/alexcheng1982/docker-apache2-php7) image for Apache 2 and PHP 7. Please refer to the image label `php_version` for the actual PHP version. In general, Magento `2.1.x` uses latest PHP `7.0.x`, Magento `2.2.x` uses latest PHP `7.1.x`, and `2.3.x` uses latest PHP `7.2.x`. Please refer to the label `php_version` of the image to get the actual PHP version. +This docker image is based on my [docker-apache2-php8](https://github.com/alexcheng1982/docker-apache2-php8) image for Apache 2 and PHP 8. Please refer to the image label `php_version` for the actual PHP version. In general, Magento `2.4.x` uses PHP `8.1`. Please refer to the label `php_version` of the image to get the actual PHP version. -> This docker image is based on [phusion/baseimage-docker](https://github.com/phusion/baseimage-docker) with Ubuntu 18.04 LTS. The reason to use `phusion/baseimage-docker` is to support multiple processes, which is important to get cron jobs working in Mangento. +> This docker image is based on [phusion/baseimage-docker](https://github.com/phusion/baseimage-docker) with Ubuntu 22.04 LTS. The reason to use `phusion/baseimage-docker` is to support multiple processes, which is important to get cron jobs working in Mangento. +**Please note: this Docker image is for development and testing only, not ready for production use. Setting up a Magento 2 production server requires more configurations. You can use this image as the base to build customized images.** -**Please note: this Docker image is for development and testing only, not ready for production use. Setting up a Magento 2 production server requires more configurations. Please refer to [official documentations](http://devdocs.magento.com/guides/v2.2/config-guide/deployment/). You can this image as the base to build customized images.** +## Magento 2 Installation Types -## Magento 2 installation types +Magento 2.4 can be installed using [Composer](https://getcomposer.org/) or git. The git-based installation mode is used for contributor of Magento. This Docker image uses Composer as the installation type, so the **Web Setup Wizard** can be used. -Magento 2 has three different ways to [install](http://devdocs.magento.com/guides/v2.0/install-gde/bk-install-guide.html), for users, integrators and developers. This Docker image uses **integrator** as the default installation type, so the **Web Setup Wizard** can be used. For each version, both integrator and developer installation types are available. The user installation type is not currently supported. - -For example, Magento 2 version `2.2.2` has tag `2.2.2`, `2.2.2-integrator` and `2.2.2-developer`. `2.2.2` is the same as `2.2.2-integrator`. Below are some basic instructions. -## Quick start +## Quick Start -The easiest way to start Magento 2 with MySQL is using [Docker Compose](https://docs.docker.com/compose/). Just clone this repo and run following command in the root directory. The default `docker-compose.yml` uses MySQL and phpMyAdmin. +The easiest way to start Magento 2 with MySQL is using [Docker Compose](https://docs.docker.com/compose/). Just clone this repo and run following command in the root directory. The default `docker-compose.yml` uses MySQL, phpMyAdmin, and OpenSearch. ~~~ -$ docker-compose up -d +$ docker compose up -d ~~~ For admin username and password, please refer to the file `env`. You can also change the file `env` to update those configurations. Below are the default configurations. @@ -54,15 +52,19 @@ MAGENTO_ADMIN_LASTNAME=MyStore MAGENTO_ADMIN_EMAIL=amdin@example.com MAGENTO_ADMIN_USERNAME=admin MAGENTO_ADMIN_PASSWORD=magentorocks1 + +OPENSEARCH_HOST=opensearch ~~~ For example, if you want to change the default currency, just update the variable `MAGENTO_DEFAULT_CURRENCY`, e.g. `MAGENTO_DEFAULT_CURRENCY=USD`. To get all the possible values of `MAGENTO_LANGUAGE`, `MAGENTO_TIMEZONE` and `MAGENTO_DEFAULT_CURRENCY`, run the corresponding command shown below: -* `MAGENTO_LANGUAGE` - `bin/magento info:language:list` -* `MAGENTO_TIMEZONE` - `bin/magento info:timezone:list` -* `MAGENTO_DEFAULT_CURRENCY` - `bin/magento info:currency:list` +| Variable | Command | +| -------------------------- | -------------------------------- | +| `MAGENTO_LANGUAGE` | `bin/magento info:language:list` | +| `MAGENTO_TIMEZONE` | `bin/magento info:timezone:list` | +| `MAGENTO_DEFAULT_CURRENCY` | `bin/magento info:currency:list` | For example, to get all possible values of `MAGENTO_LANGUAGE`, run @@ -92,16 +94,33 @@ $ docker exec -it install-magento $ docker exec -it install-sampledata ~~~ -**Please note:** Sample data for Magento 2.2.2 doesn't work at the moment, see [this issue](https://github.com/alexcheng1982/docker-magento2/issues/11). ### Database The default `docker-compose.yml` uses MySQL as the database and starts [phpMyAdmin](https://www.phpmyadmin.net/). The default URL for phpMyAdmin is `http://localhost:8580`. Use MySQL username and password to log in. -Magento starts support of MySQL 5.7 in version `2.1.2`. Before `2.1.2`, MySQL 5.6 should be used. +MySQL `8.0.0` is used as the default database version. + +### Usage + +After Magento 2 is installed, open a browser and navigate to `http://local.magento/`. For admin access, navigate to `http://local.magento/admin/` and log in using the admin username and password specified in the `env` file. Default admin username and password are `admin` and `magentorocks1`, respectively. + +### Running on Windows + +When running on Windows, the port `80` may be occupied by built-in IIS or ASP.NET server. The following command finds ID of the process that occupies port `80`. + +``` +netstat -ano -p TCP | find /I"listening" | find /I"80" +``` + +Then `taskkill /F /PID ` can be used to kill the process to free the port. ## FAQ +### How to use a different port? + +If the default port `80` cannot be used for some reasons, you can change to a different port. Simply change the `MAGENTO_URL` from `http://local.magento` to add the port number, for example, `http://local.magento:8080`. You may also need to modify `docker-compose.yaml` file to update the exported port of the Magento container. + ### How to keep installed Magento? You can add a volume to folder `/var/www/html`, see the `docker-compose.yml` file. @@ -113,7 +132,7 @@ volumes: ### Where is the database? -Magento 2 cannot run without a database. This image is for Magento 2 only. It doesn't contain MySQL server. MySQL server should be started in another container and linked with Magento 2 container. It's recommended to use Docker Compose to start both containers. You can also use [Kubernetes](https://kubernetes.io/) or other tools. +Magento 2 cannot run without a database. This image is for Magento 2 only. It doesn't contain a MySQL server. A MySQL server should be started in another container and linked with Magento 2 container. It's recommended to use Docker Compose to start both containers. You can also use [Kubernetes](https://kubernetes.io/) or other tools. ### Why accessing http://local.magento? @@ -125,6 +144,7 @@ If `localhost` doesn't work, try using `127.0.0.1`. 127.0.0.1 local.magento ``` + ### How to update Magento 2 installation configurations? Depends on how the container is used, @@ -159,7 +179,7 @@ services: volumes: - /dev/mytheme:/var/www/html/app/design/frontend/mytheme/default db: - image: mysql:5.6.23 + image: mysql:8.0.0 volumes: - db-data:/var/lib/mysql/data env_file: @@ -191,4 +211,4 @@ When deploying those changes to production servers, we can simply copy all files ### Test Magento compatibilities -This Docker images has different tags for corresponding Magento versions, e.g. `2.2.1`, `2.2.2`. You can switch to different Magento versions very easily when testing extensions and themes. \ No newline at end of file +This Docker images has different tags for corresponding Magento 2.4 versions. You can switch to different Magento versions very easily when testing extensions and themes. \ No newline at end of file diff --git a/crontab.hbs b/crontab.hbs deleted file mode 100644 index b2aca9e2a..000000000 --- a/crontab.hbs +++ /dev/null @@ -1,3 +0,0 @@ -* * * * * www-data /usr/local/bin/php /var/www/html/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/html/var/log/magento.cron.log -* * * * * www-data /usr/local/bin/php /var/www/html/bin/magento indexer:reindex >> >> /var/www/html/var/log/magento.indexer.log -{{{extraCronJobs}}} diff --git a/developer/Dockerfile b/developer/Dockerfile deleted file mode 100644 index e4b4a8481..000000000 --- a/developer/Dockerfile +++ /dev/null @@ -1,67 +0,0 @@ -FROM quay.io/alexcheng1982/apache2-php7:7.3.12 - -LABEL maintainer="alexcheng1982@gmail.com" -LABEL php_version="7.3.12" -LABEL magento_version="2.3.6" -LABEL description="Magento 2.3.6 with PHP 7.3.12" - -ENV MAGENTO_VERSION 2.3.6 -ENV INSTALL_DIR /var/www/html -ENV COMPOSER_HOME /var/www/.composer/ - -RUN curl -sS https://getcomposer.org/installer | php \ - && mv composer.phar /usr/local/bin/composer -COPY ./auth.json $COMPOSER_HOME - -RUN requirements="libpng++-dev libzip-dev libmcrypt-dev libmcrypt4 libcurl3-dev libfreetype6 libjpeg-turbo8 libjpeg-turbo8-dev libfreetype6-dev libicu-dev libxslt1-dev unzip" \ - && apt-get update \ - && apt-get install -y $requirements \ - && rm -rf /var/lib/apt/lists/* \ - && docker-php-ext-install pdo_mysql \ - && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \ - && docker-php-ext-install gd \ - && docker-php-ext-install mbstring \ - && docker-php-ext-install zip \ - && docker-php-ext-install intl \ - && docker-php-ext-install xsl \ - && docker-php-ext-install soap \ - && docker-php-ext-install bcmath - -RUN yes '' | pecl install mcrypt-1.0.3 \ - && echo 'extension=mcrypt.so' > /usr/local/etc/php/conf.d/mcrypt.ini - -RUN chsh -s /bin/bash www-data - -RUN cd /tmp && \ - curl https://codeload.github.com/magento/magento2/tar.gz/$MAGENTO_VERSION -o $MAGENTO_VERSION.tar.gz && \ - tar xvf $MAGENTO_VERSION.tar.gz && \ - mv magento2-$MAGENTO_VERSION/* magento2-$MAGENTO_VERSION/.htaccess $INSTALL_DIR - -RUN chown -R www-data:www-data /var/www -RUN su www-data -c "cd $INSTALL_DIR && composer install" -RUN su www-data -c "cd $INSTALL_DIR && composer config repositories.magento composer https://repo.magento.com/" - -RUN cd $INSTALL_DIR \ - && find . -type d -exec chmod 770 {} \; \ - && find . -type f -exec chmod 660 {} \; \ - && chmod u+x bin/magento - -COPY ./install-magento /usr/local/bin/install-magento -RUN chmod +x /usr/local/bin/install-magento - -COPY ./install-sampledata /usr/local/bin/install-sampledata -RUN chmod +x /usr/local/bin/install-sampledata - -RUN a2enmod rewrite -RUN echo "memory_limit=2048M" > /usr/local/etc/php/conf.d/memory-limit.ini - -RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* - -WORKDIR $INSTALL_DIR - -# Add cron job -ADD crontab /etc/cron.d/magento2-cron -RUN chmod 0644 /etc/cron.d/magento2-cron \ - && crontab -u www-data /etc/cron.d/magento2-cron - -VOLUME $INSTALL_DIR \ No newline at end of file diff --git a/developer/crontab b/developer/crontab deleted file mode 100644 index 736a16adf..000000000 --- a/developer/crontab +++ /dev/null @@ -1,3 +0,0 @@ -* * * * * www-data /usr/local/bin/php /var/www/html/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/html/var/log/magento.cron.log -* * * * * www-data /usr/local/bin/php /var/www/html/bin/magento indexer:reindex >> >> /var/www/html/var/log/magento.indexer.log - diff --git a/developer/install-magento b/developer/install-magento deleted file mode 100644 index 671656dbd..000000000 --- a/developer/install-magento +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -su www-data <> /var/www/html/var/log/magento.cron.log -* * * * * www-data /usr/local/bin/php /var/www/html/bin/magento indexer:reindex >> >> /var/www/html/var/log/magento.indexer.log -* * * * * www-data /usr/local/bin/php /var/www/html/update/cron.php >> /var/www/html/var/log/update.cron.log -* * * * * www-data /usr/local/bin/php /var/www/html/bin/magento setup:cron:run >> /var/www/html/var/log/setup.cron.log diff --git a/integrator/install-magento b/integrator/install-magento deleted file mode 100644 index 671656dbd..000000000 --- a/integrator/install-magento +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -su www-data <> /var/www/html/var/log/update.cron.log -* * * * * www-data /usr/local/bin/php /var/www/html/bin/magento setup:cron:run >> /var/www/html/var/log/setup.cron.log \ No newline at end of file diff --git a/partials/integrator/magento2Installation b/partials/integrator/magento2Installation deleted file mode 100644 index a842d6b5b..000000000 --- a/partials/integrator/magento2Installation +++ /dev/null @@ -1,2 +0,0 @@ -RUN chown -R www-data:www-data /var/www -RUN su www-data -c "composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition $INSTALL_DIR $MAGENTO_VERSION" \ No newline at end of file diff --git a/update.js b/update.js index 6c22c1418..36e1ed7b1 100644 --- a/update.js +++ b/update.js @@ -1,42 +1,62 @@ -const Handlebars = require('handlebars'); -const Promise = require('bluebird'); -const merge = require('lodash.merge'); +const Handlebars = require("handlebars"); +const Promise = require("bluebird"); +const merge = require("lodash.merge"); const fs = Promise.promisifyAll(require("fs")); const path = require("path"); -const commonOptions = { - phpVersion: '7.3.12', - magento2Version: '2.3.6', -}; +const versions = [ + { + phpVersion: "8.1", + magento2Version: "2.4.6-p3", + openSearchVersion: "2", + }, + { + phpVersion: "8.1", + magento2Version: "2.4.2-p2", + openSearchVersion: "1", + }, +]; -function readPartial(profile, section) { - return fs.readFileAsync(path.join(__dirname, 'partials', profile, section), 'utf8'); +function getVersionDir(version) { + return path.join(__dirname, "versions", version); } -function writeFile(context, profile, fileName, template) { - return fs.readFileAsync(path.join(__dirname, template || `${fileName}.hbs`), 'utf8') - .then(content => Handlebars.compile(content)(context)) - .then(content => fs.writeFileAsync(path.join(__dirname, profile, fileName), content)); +function writeFile(context, version, fileName, template) { + return fs + .readFileAsync(path.join(__dirname, template || `${fileName}.hbs`), "utf8") + .then((content) => Handlebars.compile(content)(context)) + .then((content) => + fs.writeFileAsync(path.join(getVersionDir(version), fileName), content) + ); } -function copyFile(fileName, profile) { - return fs.copyFileAsync(path.join(__dirname, fileName), path.join(__dirname, profile, fileName)); +function copyFile(fileName, version) { + return fs.copyFileAsync( + path.join(__dirname, fileName), + path.join(getVersionDir(version), fileName) + ); } -const profiles = ['integrator', 'developer']; -const sections = ['magento2Installation', 'extraCronJobs']; -const filesToCopy = ['auth.json', 'install-magento', 'install-sampledata']; -const templatedFiles = ['Dockerfile', 'crontab']; -Promise.map(profiles, profile => { - return Promise.reduce(sections, (obj, section) => { - return readPartial(profile, section).then(value => { - obj[section] = value; - return obj; - }) - }, {}).then(profileContext => { - const context = merge({}, commonOptions, profileContext); - return Promise.map(filesToCopy, fileToCopy => copyFile(fileToCopy, profile)) - .then(_ => Promise.map(templatedFiles, templatedFile => writeFile(context, profile, templatedFile))); - }); -}).then(() => console.log("Update successfully")) - .catch(console.error); \ No newline at end of file +function createVersionDir(version) { + const dir = getVersionDir(version); + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir, { recursive: true }); + } +} + +const filesToCopy = ["auth.json", "install-magento", "install-sampledata"]; +const templatedFiles = ["Dockerfile", "docker-compose.yaml"]; +Promise.map(versions, (versionConfig) => { + const context = merge({}, versionConfig); + const version = versionConfig.magento2Version; + createVersionDir(version); + return Promise.map(filesToCopy, (fileToCopy) => + copyFile(fileToCopy, version) + ).then((_) => + Promise.map(templatedFiles, (templatedFile) => + writeFile(context, version, templatedFile) + ) + ); +}) + .then(() => console.log("Updated successfully")) + .catch(console.error); diff --git a/integrator/Dockerfile b/versions/2.4.2-p2/Dockerfile similarity index 52% rename from integrator/Dockerfile rename to versions/2.4.2-p2/Dockerfile index 346edabd0..6185d1da3 100644 --- a/integrator/Dockerfile +++ b/versions/2.4.2-p2/Dockerfile @@ -1,11 +1,11 @@ -FROM quay.io/alexcheng1982/apache2-php7:7.3.12 +FROM ghcr.io/alexcheng1982/docker-apache2-php8:8.1 LABEL maintainer="alexcheng1982@gmail.com" -LABEL php_version="7.3.12" -LABEL magento_version="2.3.6" -LABEL description="Magento 2.3.6 with PHP 7.3.12" +LABEL php_version="8.1" +LABEL magento_version="2.4.2-p2" +LABEL description="Magento Open Source 2.4.2-p2 with PHP 8.1" -ENV MAGENTO_VERSION 2.3.6 +ENV MAGENTO_VERSION 2.4.2-p2 ENV INSTALL_DIR /var/www/html ENV COMPOSER_HOME /var/www/.composer/ @@ -13,31 +13,37 @@ RUN curl -sS https://getcomposer.org/installer | php \ && mv composer.phar /usr/local/bin/composer COPY ./auth.json $COMPOSER_HOME -RUN requirements="libpng++-dev libzip-dev libmcrypt-dev libmcrypt4 libcurl3-dev libfreetype6 libjpeg-turbo8 libjpeg-turbo8-dev libfreetype6-dev libicu-dev libxslt1-dev unzip" \ - && apt-get update \ - && apt-get install -y $requirements \ - && rm -rf /var/lib/apt/lists/* \ - && docker-php-ext-install pdo_mysql \ - && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \ - && docker-php-ext-install gd \ - && docker-php-ext-install mbstring \ - && docker-php-ext-install zip \ - && docker-php-ext-install intl \ - && docker-php-ext-install xsl \ - && docker-php-ext-install soap \ - && docker-php-ext-install bcmath - -RUN yes '' | pecl install mcrypt-1.0.3 \ +RUN requirements="libpng++-dev libzip-dev libmcrypt-dev libmcrypt4 libcurl3-dev libfreetype6 libjpeg-turbo8 libjpeg-turbo8-dev libfreetype6-dev libicu-dev libxslt1-dev zip unzip libxml2 libonig-dev" \ + set -eux; \ + apt-get update; \ + apt-get install -y $requirements; \ + rm -rf /var/lib/apt/lists/* + +RUN set -eux; \ + docker-php-ext-install pdo_mysql; \ + docker-php-ext-configure gd --with-freetype --with-jpeg; \ + docker-php-ext-install gd; \ + docker-php-ext-install mbstring; \ + docker-php-ext-install zip; \ + docker-php-ext-install intl; \ + docker-php-ext-install xsl; \ + docker-php-ext-install soap; \ + docker-php-ext-install sockets; \ + docker-php-ext-install bcmath + +RUN yes '' | pecl install mcrypt-1.0.6 \ && echo 'extension=mcrypt.so' > /usr/local/etc/php/conf.d/mcrypt.ini RUN chsh -s /bin/bash www-data RUN chown -R www-data:www-data /var/www + RUN su www-data -c "composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition $INSTALL_DIR $MAGENTO_VERSION" RUN cd $INSTALL_DIR \ - && find . -type d -exec chmod 770 {} \; \ - && find . -type f -exec chmod 660 {} \; \ + && find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + \ + && find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} + \ + && chown -R :www-data . \ && chmod u+x bin/magento COPY ./install-magento /usr/local/bin/install-magento @@ -53,9 +59,4 @@ RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* WORKDIR $INSTALL_DIR -# Add cron job -ADD crontab /etc/cron.d/magento2-cron -RUN chmod 0644 /etc/cron.d/magento2-cron \ - && crontab -u www-data /etc/cron.d/magento2-cron - VOLUME $INSTALL_DIR \ No newline at end of file diff --git a/developer/auth.json b/versions/2.4.2-p2/auth.json similarity index 100% rename from developer/auth.json rename to versions/2.4.2-p2/auth.json diff --git a/versions/2.4.2-p2/docker-compose.yaml b/versions/2.4.2-p2/docker-compose.yaml new file mode 100644 index 000000000..9026ec749 --- /dev/null +++ b/versions/2.4.2-p2/docker-compose.yaml @@ -0,0 +1,57 @@ +version: '3.0' +services: + web: + image: alexcheng/magento2 + ports: + - "80:80" + links: + - db + - opensearch + depends_on: + - db + - opensearch + volumes: + - magento-data:/var/www/html + env_file: + - env + db: + image: mysql:8.0.0 + volumes: + - db-data:/var/lib/mysql + env_file: + - env + phpmyadmin: + image: phpmyadmin/phpmyadmin + ports: + - "8580:80" + links: + - db + depends_on: + - db + opensearch: + image: opensearchproject/opensearch:1 + container_name: opensearch + environment: + - cluster.name=opensearch-cluster + - node.name=opensearch + - discovery.seed_hosts=opensearch + - cluster.initial_cluster_manager_nodes=opensearch + - bootstrap.memory_lock=true + - plugins.security.disabled=true + - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" + ulimits: + memlock: + soft: -1 + hard: -1 + nofile: + soft: 65536 + hard: 65536 + volumes: + - opensearch-data:/usr/share/opensearch/data + ports: + - 9200:9200 + - 9600:9600 +volumes: + magento-data: + db-data: + opensearch-data: \ No newline at end of file diff --git a/versions/2.4.2-p2/install-magento b/versions/2.4.2-p2/install-magento new file mode 100644 index 000000000..f4dae296b --- /dev/null +++ b/versions/2.4.2-p2/install-magento @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +su www-data < /usr/local/etc/php/conf.d/mcrypt.ini + +RUN chsh -s /bin/bash www-data + +RUN chown -R www-data:www-data /var/www + +RUN su www-data -c "composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition $INSTALL_DIR $MAGENTO_VERSION" + +RUN cd $INSTALL_DIR \ + && find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + \ + && find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} + \ + && chown -R :www-data . \ + && chmod u+x bin/magento + +COPY ./install-magento /usr/local/bin/install-magento +RUN chmod +x /usr/local/bin/install-magento + +COPY ./install-sampledata /usr/local/bin/install-sampledata +RUN chmod +x /usr/local/bin/install-sampledata + +RUN a2enmod rewrite +RUN echo "memory_limit=2048M" > /usr/local/etc/php/conf.d/memory-limit.ini + +RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +WORKDIR $INSTALL_DIR + +VOLUME $INSTALL_DIR \ No newline at end of file diff --git a/integrator/auth.json b/versions/2.4.6-p3/auth.json similarity index 100% rename from integrator/auth.json rename to versions/2.4.6-p3/auth.json diff --git a/versions/2.4.6-p3/docker-compose.yaml b/versions/2.4.6-p3/docker-compose.yaml new file mode 100644 index 000000000..6222971bd --- /dev/null +++ b/versions/2.4.6-p3/docker-compose.yaml @@ -0,0 +1,57 @@ +version: '3.0' +services: + web: + image: alexcheng/magento2 + ports: + - "80:80" + links: + - db + - opensearch + depends_on: + - db + - opensearch + volumes: + - magento-data:/var/www/html + env_file: + - env + db: + image: mysql:8.0.0 + volumes: + - db-data:/var/lib/mysql + env_file: + - env + phpmyadmin: + image: phpmyadmin/phpmyadmin + ports: + - "8580:80" + links: + - db + depends_on: + - db + opensearch: + image: opensearchproject/opensearch:2 + container_name: opensearch + environment: + - cluster.name=opensearch-cluster + - node.name=opensearch + - discovery.seed_hosts=opensearch + - cluster.initial_cluster_manager_nodes=opensearch + - bootstrap.memory_lock=true + - plugins.security.disabled=true + - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" + ulimits: + memlock: + soft: -1 + hard: -1 + nofile: + soft: 65536 + hard: 65536 + volumes: + - opensearch-data:/usr/share/opensearch/data + ports: + - 9200:9200 + - 9600:9600 +volumes: + magento-data: + db-data: + opensearch-data: \ No newline at end of file diff --git a/versions/2.4.6-p3/install-magento b/versions/2.4.6-p3/install-magento new file mode 100644 index 000000000..f4dae296b --- /dev/null +++ b/versions/2.4.6-p3/install-magento @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +su www-data <