Skip to content

Commit

Permalink
feat(build): add Docker image build
Browse files Browse the repository at this point in the history
  • Loading branch information
hippothomas committed Jan 17, 2024
1 parent 332468b commit dff8998
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
ARG VERSION="8.3"

FROM php:${VERSION}-apache

# Set the working directory in the container
WORKDIR /var/www/html

# Copy the code into the container
COPY . .

## Copy custom configurations
COPY ./deployment/apache.conf /etc/apache2/sites-available/000-default.conf
COPY ./deployment/php.ini /usr/local/etc/php/conf.d/custom-php.ini

# Install PHP extensions and other dependencies
RUN apt-get update && \
apt-get install -y wget libpq-dev libicu-dev && \
docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql && \
docker-php-ext-install intl opcache pgsql pdo pdo_pgsql && \
pecl install mongodb && \
docker-php-ext-enable mongodb && \
rm -rf /var/lib/apt/lists/* && \
a2enmod rewrite

## Install composer
RUN wget https://getcomposer.org/installer && \
php installer --install-dir=/usr/local/bin/ --filename=composer && \
rm installer

## Install application dependencies
ENV APP_ENV=prod
RUN composer install --no-dev --no-interaction --optimize-autoloader

## Change files owner to apache default user
RUN chown -R www-data:www-data /var/www/html

## Cleanup
RUN composer dump-autoload --no-dev --classmap-authoritative && \
rm /usr/local/bin/composer

# Expose the port Apache listens on
EXPOSE 80
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ External data collection service from [Waistline](https://github.com/davidhealey
## Stack
- **Framework**: [Symfony](https://symfony.com/)

## Build custom Docker image
```
docker build -t waistline-api:latest .
```

## License
See the [LICENSE](LICENSE.md) file for license rights and limitations (MIT).
13 changes: 13 additions & 0 deletions deployment/apache.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ServerName localhost
<VirtualHost *:80>
DocumentRoot /var/www/html/public

<Directory /var/www/html/public>
Require all granted
DirectoryIndex index.php
AllowOverride All
</Directory>

ErrorLog /var/log/apache2/waistline-api_error.log
CustomLog /var/log/apache2/waistline-api_access.log combined
</VirtualHost>
25 changes: 25 additions & 0 deletions deployment/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
; general configuration
memory_limit = 256M
error_reporting = E_ERROR
expose_php = 0
date.timezone = UTC
session.use_strict_mode = 1

; https://symfony.com/doc/current/performance.html
; Use the OPcache class preloading
opcache.preload = /var/www/html/config/preload.php
; required for opcache.preload:
opcache.preload_user = www-data
; maximum memory that OPcache can use to store compiled PHP files
opcache.memory_consumption = 256
; maximum number of files that can be stored in the cache
opcache.max_accelerated_files = 20000
; amount of memory used to store interned strings
opcache.interned_strings_buffer = 16
; check for whether a file has already been cached
opcache.enable_file_override = 1

; maximum memory allocated to store the results
realpath_cache_size = 4096K
; save the results for 10 minutes (600 seconds)
realpath_cache_ttl = 600

0 comments on commit dff8998

Please sign in to comment.