Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docker): add internal application Dockerfile #41

Merged
merged 17 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions infra/docker/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ USER root

# Install redis with igbinary
RUN apk add --no-cache pcre-dev~=8.45 $PHPIZE_DEPS \
&& pecl install igbinary \
&& pecl install -D "enable-redis-igbinary='yes' enable-redis-lzf='no' enable-redis-zstd='no'" redis \
&& docker-php-ext-enable redis igbinary \
&& apk del pcre-dev $PHPIZE_DEPS
&& pecl install igbinary \
&& pecl install -D "enable-redis-igbinary='yes' enable-redis-lzf='no' enable-redis-zstd='no'" redis \
&& docker-php-ext-enable redis igbinary \
&& apk del pcre-dev $PHPIZE_DEPS

RUN apk add --no-cache icu-dev \
&& docker-php-ext-configure intl \
&& docker-php-ext-install pdo_mysql opcache intl
&& docker-php-ext-configure intl \
&& docker-php-ext-install pdo_mysql opcache intl

# PHP config file
COPY ./php.ini ${PHP_INI_DIR}/conf.d/1000-php.ini
Expand Down
26 changes: 25 additions & 1 deletion infra/docker/internal/Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
FROM php:8.2-fpm
# hadolint global ignore=DL3018,SC2086
FROM ghcr.io/dvsa/dvsa-docker-images/php/7.4/fpm-nginx:0

USER root

# Installing require dependencies
RUN apk add --no-cache pcre-dev~=8.45 $PHPIZE_DEPS \
&& pecl install igbinary \
&& pecl install -D "enable-redis-igbinary='yes' enable-redis-lzf='no' enable-redis-zstd='no'" redis \
&& docker-php-ext-enable redis igbinary \
&& apk del pcre-dev $PHPIZE_DEPS

RUN apk add --no-cache icu-dev \
&& docker-php-ext-configure intl \
&& docker-php-ext-install pdo_mysql opcache intl

# PHP config file
COPY ./php.ini ${PHP_INI_DIR}/conf.d/1000-php.ini

ADD --chown=www-data ./internal.tar.gz /var/www/html

# nginx server config file
COPY internal.conf /etc/nginx/conf.d/internal.conf

USER www-data
142 changes: 142 additions & 0 deletions infra/docker/internal/internal.conf
JoshuaLicense marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# Add Access-Control-Allow-Origin.
map $sent_http_content_type $cors {
# Images
~*image/ "*";

# Web fonts
~*font/ "*";
~*application/vnd.ms-fontobject "*";
~*application/x-font-ttf "*";
~*application/font-woff "*";
~*application/x-font-woff "*";
~*application/font-woff2 "*";
}

# Add Referrer-Policy for HTML documents.
map $sent_http_content_type $referrer_policy {
~*text/(css|html|javascript)|application\/pdf|xml "strict-origin-when-cross-origin";
}

server {
listen 8080;
listen [::]:8080;

server_name _;

root /var/www/public;

# Protect website against clickjacking.
#
# The example below sends the `X-Frame-Options` response header with the value
# `DENY`, informing browsers not to display the content of the web page in any
# frame.
#
# This might not be the best setting for everyone. You should read about the
# other two possible values the `X-Frame-Options` header field can have:
# `SAMEORIGIN` and `ALLOW-FROM`.
# https://tools.ietf.org/html/rfc7034#section-2.1.
#
# Keep in mind that while you could send the `X-Frame-Options` header for all
# of your website's pages, this has the potential downside that it forbids even
# non-malicious framing of your content.
#
# Nonetheless, you should ensure that you send the `X-Frame-Options` header for
# all pages that allow a user to make a state-changing operation (e.g: pages
# that contain one-click purchase links, checkout or bank-transfer confirmation
# pages, pages that make permanent configuration changes, etc.).
#
# Sending the `X-Frame-Options` header can also protect your website against
# more than just clickjacking attacks.
# https://cure53.de/xfo-clickjacking.pdf.
#
# (!) The `Content-Security-Policy` header has a `frame-ancestors` directive
# which obsoletes this header for supporting browsers.
#
# https://tools.ietf.org/html/rfc7034
# https://owasp.org/www-project-secure-headers/#x-frame-options
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
# https://docs.microsoft.com/archive/blogs/ieinternals/combating-clickjacking-with-x-frame-options

add_header X-Frame-Options $x_frame_options always;

# Prevent some browsers from MIME-sniffing the response.
#
# This reduces exposure to drive-by download attacks and cross-origin data
# leaks, and should be left uncommented, especially if the server is serving
# user-uploaded content or content that could potentially be treated as
# executable by the browser.
#
# https://owasp.org/www-project-secure-headers/#x-content-type-options
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options
# https://blogs.msdn.microsoft.com/ie/2008/07/02/ie8-security-part-v-comprehensive-protection/
# https://mimesniff.spec.whatwg.org/

add_header X-Content-Type-Options nosniff always;

# Allow cross-origin requests.
#
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
# https://enable-cors.org/
# https://www.w3.org/TR/cors/

# (!) Do not use this without understanding the consequences.
# This will permit access from any other website.
# Instead of using this file, consider using a specific rule such as
# allowing access based on (sub)domain:
#
# add_header Access-Control-Allow-Origin "subdomain.example.com";

add_header Access-Control-Allow-Origin $cors;

# Set a strict Referrer Policy to mitigate information leakage.
#
# (1) The `Referrer-Policy` header is included in responses for resources
# that are able to request (or navigate to) other resources.
#
# This includes the commonly used resource types:
# HTML, CSS, XML/SVG, PDF documents, scripts and workers.
#
# To prevent referrer leakage entirely, specify the `no-referrer` value
# instead. Note that the effect could impact analytics metrics negatively.
#
# To check your Referrer Policy, you can use an online service, such as:
# https://securityheaders.com/
# https://observatory.mozilla.org/
#
# https://www.w3.org/TR/referrer-policy/
# https://owasp.org/www-project-secure-headers/#referrer-policy
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy
# https://scotthelme.co.uk/a-new-security-header-referrer-policy/

add_header Referrer-Policy $referrer_policy always;

# Block access to files that can expose sensitive information.
#
# By default, block access to backup and source files that may be left by some
# text editors and can pose a security risk when anyone has access to them.
#
# https://feross.org/cmsploit/
#
# (!) Update the `location` regular expression from below to include any files
# that might end up on your production server and can expose sensitive
# information about your website. These files may include: configuration
# files, files that contain metadata about the project (e.g.: project
# dependencies, build scripts, etc.).

location ~* (?:#.*#|\.(?:bak|conf|dist|fla|in[ci]|log|orig|psd|sh|sql|sw[op])|~)$ {
deny all;
}

location / {
try_files $uri /index.php?$query_string;
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php-fpm.socket;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
}
19 changes: 19 additions & 0 deletions infra/docker/internal/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
; PHP's initialization file, generally called php.ini, is responsible for
; configuring many of the aspects of PHP's behavior.
; For more information on the config file, please see:
; https://www.php.net/manual/en/index.php

[opcache]
; The maximum number of keys (and therefore scripts) in the OPcache hash table
; The Allowed value is between 200 and 100000.
opcache.max_accelerated_files=4000

; Validate timestamps of scripts on each request.
opcache.validate_timestamps=1

; Specifies the frequency at which OPcache checks for changes to PHP scripts
; in the filesystem. The value is in seconds.
opcache.revalidate_freq=60

; Enable the cli
opcache.enable_cli=1
12 changes: 6 additions & 6 deletions infra/docker/selfserve/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ USER root

# Installing require dependencies
RUN apk add --no-cache pcre-dev~=8.45 $PHPIZE_DEPS \
&& pecl install igbinary \
&& pecl install -D "enable-redis-igbinary='yes' enable-redis-lzf='no' enable-redis-zstd='no'" redis \
&& docker-php-ext-enable redis igbinary \
&& apk del pcre-dev $PHPIZE_DEPS
&& pecl install igbinary \
&& pecl install -D "enable-redis-igbinary='yes' enable-redis-lzf='no' enable-redis-zstd='no'" redis \
&& docker-php-ext-enable redis igbinary \
&& apk del pcre-dev $PHPIZE_DEPS

RUN apk add --no-cache icu-dev \
&& docker-php-ext-configure intl \
&& docker-php-ext-install pdo_mysql opcache intl
&& docker-php-ext-configure intl \
&& docker-php-ext-install pdo_mysql opcache intl

# PHP config file
COPY ./php.ini ${PHP_INI_DIR}/conf.d/1000-php.ini
Expand Down