Skip to content

Instantly share code, notes, and snippets.

@TobiasXy
Last active November 15, 2019 03:15
Show Gist options
  • Save TobiasXy/133a8037b22f64c36c0f09edc2608d25 to your computer and use it in GitHub Desktop.
Save TobiasXy/133a8037b22f64c36c0f09edc2608d25 to your computer and use it in GitHub Desktop.
Symfony on Kubernetes
FROM php:7.3.5-fpm AS base
# Add Microsoft repo for Microsoft ODBC Driver 17 for Linux
RUN apt-get update && apt-get install -y gnupg apt-transport-https \
&& curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
&& curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list
# Install Dependencies
# libpng-dev, libjpeg-dev and libwebp-dev for gd extension
# unzip for composer
RUN apt-get update \
&& ACCEPT_EULA=Y apt-get install -y \
unzip \
unixodbc-dev \
msodbcsql17 \
libicu-dev \
libwebp-dev \
libjpeg-dev \
libpng-dev \
locales \
&& echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen
# Install pdo_sqlsrv and sqlsrv from PECL.
RUN pecl install pdo_sqlsrv-5.6.1 sqlsrv-5.6.1 \
&& docker-php-ext-enable pdo_sqlsrv sqlsrv \
&& docker-php-ext-configure gd --with-gd --with-webp-dir --with-jpeg-dir \
&& docker-php-ext-install opcache intl gd
COPY conf/php/php.ini /usr/local/etc/php/php.ini
COPY conf/php/www-pool.conf /usr/local/etc/php-fpm.d/www.conf
FROM base AS build-env
# install git for composer
RUN apt-get update \
&& apt-get install git -y
COPY --from=composer:1.8.5 /usr/bin/composer /usr/bin/composer
COPY composer.json composer.lock symfony.lock /var/www/html/
ARG COMPOSER_AUTH='{"bitbucket-oauth": {"bitbucket.org": {"consumer-key": "<insert-consumer-key>","consumer-secret": "<insert-consumer-secret>"}}}'
ARG COMPOSER_ALLOW_SUPERUSER="1"
ARG APP_ENV=prod
RUN composer install --no-scripts --no-autoloader --no-interaction
# Copy the actual app for composer autoload generation
COPY . /var/www/html
RUN mkdir var \
&& composer dump-autoload --optimize \
&& composer dump-env prod --empty \
&& composer run-script post-install-cmd
FROM base
COPY . /var/www/html
COPY --from=build-env /var/www/html/.env.local.php /var/www/html/.env.local.php
COPY --from=build-env /var/www/html/vendor /var/www/html/vendor
COPY --from=build-env /var/www/html/var /var/www/html/var
apiVersion: apps/v1
kind: Deployment
metadata:
name: api-deployment
namespace: default
labels:
app: api
spec:
replicas: 2
selector:
matchLabels:
app: api
template:
metadata:
labels:
app: api
spec:
imagePullSecrets:
- name: regcred
containers:
- name: nginx
image: <reference to the nginx docker image on our private registry>
ports:
- containerPort: 80
resources:
requests:
cpu: 50m
memory: 10M
limits:
cpu: 50m
memory: 10M
livenessProbe:
httpGet:
path: /ping
port: 80
initialDelaySeconds: 120
periodSeconds: 20
timeoutSeconds: 3
readinessProbe:
httpGet:
path: /ping
port: 80
periodSeconds: 20
initialDelaySeconds: 5
- name: app
image: <the app image>
envFrom:
- configMapRef:
name: api-config
- secretRef:
name: api-secrets
ports:
- containerPort: 9000
resources:
requests:
memory: 150M
cpu: 80m
limits:
memory: 300M
cpu: 150m
livenessProbe:
tcpSocket:
port: 9000
initialDelaySeconds: 60
periodSeconds: 10
timeoutSeconds: 2
readinessProbe:
tcpSocket:
port: 9000
periodSeconds: 10
initialDelaySeconds: 5
---
apiVersion: v1
kind: Service
metadata:
name: api-service
namespace: default
spec:
type: ClusterIP
ports:
- name: http
port: 80
selector:
app: api
server {
listen 80; ## listen for ipv4; this line is default and implied
root /var/www/html/public;
# Make site accessible from http://localhost/
server_name _;
# Disable sendfile as per https://docs.vagrantup.com/v2/synced-folders/virtualbox.html
sendfile off;
# Add stdout logging
error_log /dev/stdout info;
access_log /dev/stdout;
client_max_body_size 50m;
rewrite ^(.*?)$ /index.php$1 last;
location ~ ^/index\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_read_timeout 300s;
include fastcgi_params;
internal;
}
location ~ \.php$ {
return 404;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment