Skip to content

Commit c808a63

Browse files
Romain BastideMadCat34
authored andcommitted
Modify Dockerfile to use multi-stage (dev, prod) laminas#71
Add a docker-compose.override.yml file Add a .dockerignore filewq Signed-off-by: MadCat34 <madcat34@gmail.com>
1 parent a726d52 commit c808a63

File tree

4 files changed

+93
-60
lines changed

4 files changed

+93
-60
lines changed

.dockerignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# All is ignored by default
2+
*
3+
4+
# Whitelist files and directories
5+
!composer.json
6+
!COPYRIGHT.md
7+
!LICENSE.md
8+
!README.md
9+
!bin/
10+
!config/
11+
!data/
12+
!module/
13+
!public/

Dockerfile

Lines changed: 62 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,83 @@
1-
FROM php:8.3-apache
1+
ARG PHP_VERSION=8.3
2+
ARG COMPOSER_VERSION="latest"
23

3-
LABEL maintainer="getlaminas.org" \
4-
org.label-schema.docker.dockerfile="/Dockerfile" \
5-
org.label-schema.name="Laminas MVC Skeleton" \
6-
org.label-schema.url="https://docs.getlaminas.org/mvc/" \
7-
org.label-schema.vcs-url="https://github.com/laminas/laminas-mvc-skeleton"
4+
# Use a Composer image to install dependencies
5+
# Composer should not be installed in the final image
6+
FROM composer:${COMPOSER_VERSION} AS composer
7+
8+
# ---------- Base image ----------
9+
FROM php:${PHP_VERSION}-apache AS base
10+
11+
WORKDIR /var/www
12+
13+
COPY --link --from=composer /usr/bin/composer /usr/bin/composer
14+
15+
## Utility to install PHP extensions
16+
ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
817

918
## Update package information
10-
RUN apt-get update
19+
RUN apt-get update && apt-get upgrade -y --no-install-recommends \
20+
&& rm -rf /var/lib/apt/lists/*
21+
22+
RUN set -eux; \
23+
install-php-extensions \
24+
apcu \
25+
intl \
26+
opcache \
27+
zip \
28+
## Add here all extensions you need
29+
# memcached \
30+
# mongodb \
31+
# redis \
32+
# mbstring \
33+
# pdo_mysql \
34+
# pdo_pgsql \
35+
;
1136

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

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

21-
###
22-
## PHP Extensisons
23-
###
43+
## --- Development image ---
44+
FROM base AS dev
2445

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

29-
## Install intl library and extension
30-
RUN apt-get install --yes libicu-dev \
31-
&& docker-php-ext-configure intl \
32-
&& docker-php-ext-install intl
33-
34-
###
35-
## Optional PHP extensions
36-
###
37-
38-
## mbstring for i18n string support
39-
# RUN docker-php-ext-install mbstring
48+
WORKDIR /var/www
4049

41-
###
42-
## Some laminas/laminas-db supported PDO extensions
43-
###
50+
ENV APP_ENV=development
4451

45-
## MySQL PDO support
46-
# RUN docker-php-ext-install pdo_mysql
52+
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
4753

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

52-
###
53-
## laminas/laminas-cache supported extensions
54-
###
58+
## ---------- Production image ----------
59+
FROM base AS prod
5560

56-
## APCU
57-
# RUN pecl install apcu \
58-
# && docker-php-ext-enable apcu
61+
LABEL maintainer="getlaminas.org" \
62+
org.label-schema.docker.dockerfile="/Dockerfile" \
63+
org.label-schema.name="Laminas MVC Skeleton" \
64+
org.label-schema.url="https://docs.getlaminas.org/mvc/" \
65+
org.label-schema.vcs-url="https://github.com/laminas/laminas-mvc-skeleton"
5966

60-
## Memcached
61-
# RUN apt-get install --yes libmemcached-dev \
62-
# && pecl install memcached \
63-
# && docker-php-ext-enable memcached
67+
WORKDIR /var/www
6468

65-
## MongoDB
66-
# RUN pecl install mongodb \
67-
# && docker-php-ext-enable mongodb
69+
ENV APP_ENV=production
6870

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

74+
#Clean up
75+
RUN apt-get clean \
76+
&& rm -rf /root/.composer \
77+
&& rm -rf /usr/local/bin/install-php-extensions \
78+
&& rm -rf /usr/local/bin/docker-php-ext-* \
79+
&& rm -rf /usr/src/php.tar.xz \
80+
&& rm -rf /usr/bin/phpize \
81+
&& rm -rf /usr/bin/php-config
7782

78-
WORKDIR /var/www
83+
USER www-data

docker-compose.override.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
services:
2+
laminas:
3+
build:
4+
target: dev
5+
environment:
6+
- APP_ENV=development
7+
volumes:
8+
- ./bin:/var/www/bin
9+
- ./config:/var/www/config
10+
- ./data:/var/www/data
11+
- ./module:/var/www/module
12+
- ./public:/var/www/public

docker-compose.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
services:
22
laminas:
3-
build: .
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
target: prod
7+
environment:
8+
- APP_ENV=production
49
ports:
510
- "8080:80"
6-
volumes:
7-
- .:/var/www

0 commit comments

Comments
 (0)