Skip to content

Commit 396d93f

Browse files
committed
Cleanup Dockerfile
- Add divider comment between generic and specific sections - Grab composer from official docker image rather than web - Use a more robust shell - Make apt-install footprint smaller - Use OpenSSL with paths rather than use WORKDIR - Make project path setable through env var for build purposes - Only install non-dev dependencies with composer. The develop shoudl consciencely install deve dependencies because of develop PHP version(s) used. - Use COPY rather than ADD as per best practices
1 parent d2c59df commit 396d93f

File tree

1 file changed

+46
-22
lines changed

1 file changed

+46
-22
lines changed

Dockerfile

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,51 @@
11
FROM php:7.3-apache
2-
RUN apt-get update && \
3-
apt-get install -y \
2+
3+
# ==============================================================================
4+
# Set up the machine
5+
# ------------------------------------------------------------------------------
6+
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
7+
8+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
9+
10+
RUN export DEBIAN_FRONTEND=noninteractive \
11+
&& apt-get update && \
12+
apt-get install -y --no-install-recommends \
413
git \
514
libzip-dev \
6-
zlib1g-dev
7-
WORKDIR /tls
8-
RUN openssl req -new -x509 -days 365 -nodes \
9-
-out server.cert \
10-
-keyout server.key \
11-
-subj "/C=RO/ST=Bucharest/L=Bucharest/O=IT/CN=www.example.ro"
12-
RUN docker-php-ext-install mysqli pdo pdo_mysql zip mbstring bcmath
13-
RUN a2enmod rewrite
14-
RUN a2enmod ssl
15-
RUN a2enmod headers
16-
WORKDIR /install
17-
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
18-
RUN php composer-setup.php
19-
RUN php -r "unlink('composer-setup.php');"
20-
ADD . /app
21-
WORKDIR /app
22-
RUN php /install/composer.phar require lcobucci/jwt:3.3.3
23-
RUN php /install/composer.phar update
24-
RUN php /install/composer.phar install
15+
zlib1g-dev \
16+
&& rm -rf /var/lib/apt/lists/*
17+
18+
RUN mkdir /tls && openssl req -new -x509 -days 365 -nodes \
19+
-out /tls/server.cert \
20+
-keyout /tls/server.key \
21+
-subj "/C=NL/ST=Overijssel/L=Enschede/O=PDS Interop/OU=IT/CN=pdsinterop.org"
22+
23+
RUN docker-php-ext-install \
24+
bcmath \
25+
mbstring \
26+
mysqli \
27+
pdo \
28+
pdo_mysql \
29+
zip
30+
31+
RUN a2enmod headers rewrite ssl
32+
2533
COPY site.conf /etc/apache2/sites-enabled/site.conf
26-
RUN chown -R www-data:www-data /app
34+
35+
WORKDIR /app
36+
2737
EXPOSE 443
38+
# ==============================================================================
39+
40+
41+
# ==============================================================================
42+
# Add the source code
43+
# ------------------------------------------------------------------------------
44+
ARG PROJECT_PATH
45+
RUN : "${PROJECT_PATH:=$PWD}"
46+
47+
COPY "${PROJECT_PATH}" /app/
48+
49+
RUN composer install --no-dev --prefer-dist
50+
RUN chown -R www-data:www-data /app
51+
# ==============================================================================

0 commit comments

Comments
 (0)