Skip to content

Commit

Permalink
Modify Dockerfile to use multi-stage (dev, prod) laminas#71
Browse files Browse the repository at this point in the history
Add a docker-compose.override.yml file
Add a .dockerignore filewq

Signed-off-by: MadCat34 <[email protected]>
  • Loading branch information
Romain Bastide authored and MadCat34 committed Dec 18, 2024
1 parent a726d52 commit c808a63
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 60 deletions.
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# All is ignored by default
*

# Whitelist files and directories
!composer.json
!COPYRIGHT.md
!LICENSE.md
!README.md
!bin/
!config/
!data/
!module/
!public/
119 changes: 62 additions & 57 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,78 +1,83 @@
FROM php:8.3-apache
ARG PHP_VERSION=8.3
ARG COMPOSER_VERSION="latest"

LABEL maintainer="getlaminas.org" \
org.label-schema.docker.dockerfile="/Dockerfile" \
org.label-schema.name="Laminas MVC Skeleton" \
org.label-schema.url="https://docs.getlaminas.org/mvc/" \
org.label-schema.vcs-url="https://github.com/laminas/laminas-mvc-skeleton"
# Use a Composer image to install dependencies
# Composer should not be installed in the final image
FROM composer:${COMPOSER_VERSION} AS composer

# ---------- Base image ----------
FROM php:${PHP_VERSION}-apache AS base

WORKDIR /var/www

COPY --link --from=composer /usr/bin/composer /usr/bin/composer

## Utility to install PHP extensions
ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

## Update package information
RUN apt-get update
RUN apt-get update && apt-get upgrade -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

RUN set -eux; \
install-php-extensions \
apcu \
intl \
opcache \
zip \
## Add here all extensions you need
# memcached \
# mongodb \
# redis \
# mbstring \
# pdo_mysql \
# pdo_pgsql \
;

## Configure Apache
RUN a2enmod rewrite \
&& sed -i 's!/var/www/html!/var/www/public!g' /etc/apache2/sites-available/000-default.conf \
&& mv /var/www/html /var/www/public

## Install Composer
RUN curl -sS https://getcomposer.org/installer \
| php -- --install-dir=/usr/local/bin --filename=composer
COPY --chown=www-data:www-data . .

###
## PHP Extensisons
###
## --- Development image ---
FROM base AS dev

## Install zip libraries and extension
RUN apt-get install --yes git zlib1g-dev libzip-dev \
&& docker-php-ext-install zip
VOLUME /var/www

## Install intl library and extension
RUN apt-get install --yes libicu-dev \
&& docker-php-ext-configure intl \
&& docker-php-ext-install intl

###
## Optional PHP extensions
###

## mbstring for i18n string support
# RUN docker-php-ext-install mbstring
WORKDIR /var/www

###
## Some laminas/laminas-db supported PDO extensions
###
ENV APP_ENV=development

## MySQL PDO support
# RUN docker-php-ext-install pdo_mysql
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

## PostgreSQL PDO support
# RUN apt-get install --yes libpq-dev \
# && docker-php-ext-install pdo_pgsql
RUN install-php-extensions xdebug \
&& composer install --no-cache --prefer-dist --no-scripts --no-progress --no-plugins --no-interaction \
&& composer dump-autoload --optimize --classmap-authoritative

###
## laminas/laminas-cache supported extensions
###
## ---------- Production image ----------
FROM base AS prod

## APCU
# RUN pecl install apcu \
# && docker-php-ext-enable apcu
LABEL maintainer="getlaminas.org" \
org.label-schema.docker.dockerfile="/Dockerfile" \
org.label-schema.name="Laminas MVC Skeleton" \
org.label-schema.url="https://docs.getlaminas.org/mvc/" \
org.label-schema.vcs-url="https://github.com/laminas/laminas-mvc-skeleton"

## Memcached
# RUN apt-get install --yes libmemcached-dev \
# && pecl install memcached \
# && docker-php-ext-enable memcached
WORKDIR /var/www

## MongoDB
# RUN pecl install mongodb \
# && docker-php-ext-enable mongodb
ENV APP_ENV=production

## Redis support. igbinary and libzstd-dev are only needed based on
## redis pecl options
# RUN pecl install igbinary \
# && docker-php-ext-enable igbinary \
# && apt-get install --yes libzstd-dev \
# && pecl install redis \
# && docker-php-ext-enable redis
RUN composer install --no-cache --prefer-dist --no-dev --no-scripts --no-progress --no-plugins --no-interaction \
&& composer dump-autoload --optimize --apcu

#Clean up
RUN apt-get clean \
&& rm -rf /root/.composer \
&& rm -rf /usr/local/bin/install-php-extensions \
&& rm -rf /usr/local/bin/docker-php-ext-* \
&& rm -rf /usr/src/php.tar.xz \
&& rm -rf /usr/bin/phpize \
&& rm -rf /usr/bin/php-config

WORKDIR /var/www
USER www-data
12 changes: 12 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
laminas:
build:
target: dev
environment:
- APP_ENV=development
volumes:
- ./bin:/var/www/bin
- ./config:/var/www/config
- ./data:/var/www/data
- ./module:/var/www/module
- ./public:/var/www/public
9 changes: 6 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
services:
laminas:
build: .
build:
context: .
dockerfile: Dockerfile
target: prod
environment:
- APP_ENV=production
ports:
- "8080:80"
volumes:
- .:/var/www

0 comments on commit c808a63

Please sign in to comment.