Skip to content

Commit

Permalink
Use a single Dockerfile for the API images
Browse files Browse the repository at this point in the history
  • Loading branch information
teohhanhui committed May 4, 2018
1 parent 62aa7dc commit ba033c9
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ indent_size = 4
indent_style = space
indent_size = 2

[Dockerfile*]
[Dockerfile]
indent_style = tab
indent_size = 4

Expand Down
36 changes: 34 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,33 @@ addons:
apt:
packages:
- docker-ce
- socat

env:
global:
- MINIKUBE_WANTUPDATENOTIFICATION=false
- MINIKUBE_WANTREPORTERRORPROMPT=false
- CHANGE_MINIKUBE_NONE_USER=true

before_install:
- docker run --rm jpetazzo/nsenter cat /nsenter > nsenter && chmod +x nsenter && sudo mv nsenter /usr/local/bin/
- curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash -s -- --version v2.9.0
- curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.26.1/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
- curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
- mkdir $HOME/.kube || true
- touch $HOME/.kube/config

install: true

before_script:
- sudo service postgresql stop
- curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash -s -- --version v2.6.1
# wait for postgresql to shutdown
- while sudo lsof -Pi :5432 -sTCP:LISTEN -t; do sleep 1; done

script:
- if jq '.extra.symfony.id != null' api/composer.json -e > /dev/null; then echo 'composer.json must not have symfony.id' 1>&2 && false; fi
- docker-compose build
- docker-compose run --no-deps -T php sh -c 'composer validate --no-check-publish'
- helm lint api/helm/api/
- docker-compose up -d
- sleep 30
- docker-compose exec -T php composer req sensiolabs/security-checker
Expand All @@ -33,6 +46,25 @@ script:
- curl -k https://localhost:444 # Admin (HTTP/2)
- curl -k https://localhost:8443 # API (HTTP/2)
- curl -k https://localhost:8444 # Varnish (HTTP/2)
- docker-compose down
- sudo -E minikube start --vm-driver=none --bootstrapper=localkube --kubernetes-version=v1.10.0
- helm lint ./api/helm/api/
# this for loop waits until kubectl can access the api server that Minikube has created
- for i in {1..150}; do
kubectl get po &> /dev/null;
if [ $? -ne 1 ]; then
break;
fi;
sleep 2;
done;
- helm init --service-account default --wait
- helm dependency build ./api/helm/api
- helm install --wait --debug
--set php.pullPolicy=IfNotPresent
--set nginx.pullPolicy=IfNotPresent
--set varnish.pullPolicy=IfNotPresent
./api/helm/api
- curl http://localhost # Ingress

before_deploy:
- echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin "$DOCKER_REGISTRY"
Expand Down
2 changes: 1 addition & 1 deletion api/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
**/.gitattributes
**/.gitignore
**/.gitmodules
**/Dockerfile*
**/Dockerfile
**/Thumbs.db
.editorconfig
.env*
Expand Down
1 change: 0 additions & 1 deletion api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
###< symfony/framework-bundle ###

/helm/api/charts
/helm/api/requirements.lock

###> friendsofphp/php-cs-fixer ###
.php_cs
Expand Down
29 changes: 28 additions & 1 deletion api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ARG PHP_VERSION=7.2
ARG NGINX_VERSION=1.13
ARG ALPINE_VERSION=3.7
FROM php:${PHP_VERSION}-fpm-alpine${ALPINE_VERSION}

FROM php:${PHP_VERSION}-fpm-alpine${ALPINE_VERSION} AS api_platform_php

RUN apk add --no-cache \
git
Expand All @@ -10,8 +12,10 @@ RUN set -xe \
&& apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
icu-dev \
libzip-dev \
postgresql-dev \
zlib-dev \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install -j$(nproc) \
intl \
pdo_pgsql \
Expand Down Expand Up @@ -63,3 +67,26 @@ RUN chmod +x /usr/local/bin/docker-entrypoint

ENTRYPOINT ["docker-entrypoint"]
CMD ["php-fpm"]

FROM nginx:${NGINX_VERSION}-alpine AS api_platform_nginx

COPY docker/nginx/conf.d /etc/nginx/conf.d/

WORKDIR /srv/api

COPY --from=api_platform_php /srv/api/public public/

FROM alpine:${ALPINE_VERSION} AS api_platform_varnish

RUN apk add --no-cache varnish

COPY docker/varnish/conf /etc/varnish/

COPY docker/varnish/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint

WORKDIR /var/lib/varnish

EXPOSE 80
ENTRYPOINT ["docker-entrypoint"]
CMD ["varnishd"]
4 changes: 0 additions & 4 deletions api/Dockerfile.nginx

This file was deleted.

10 changes: 0 additions & 10 deletions api/Dockerfile.varnish

This file was deleted.

19 changes: 19 additions & 0 deletions api/docker/varnish/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh
set -e

# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
set -- varnishd "$@"
fi

# default args
if [ "$1" = 'varnishd' ] && [ $# -eq 1 ]; then
set -- varnishd \
-F \
-a :"${VARNISH_PORT:-80}" \
-f "${VARNISH_VCL:-/etc/varnish/default.vcl}" \
-s malloc,"${VARNISH_MEMORY:-256M}" \
${VARNISH_DAEMON_OPTS:-}
fi

exec "$@"
5 changes: 0 additions & 5 deletions api/docker/varnish/start.sh

This file was deleted.

2 changes: 1 addition & 1 deletion api/helm/api/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v1
description: A Helm chart for an API Platform API
name: api
version: 0.1.0
version: 0.2.0
icon: https://api-platform.com/logo-250x250.png
6 changes: 6 additions & 0 deletions api/helm/api/requirements.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: postgresql
repository: https://kubernetes-charts.storage.googleapis.com/
version: 0.11.0
digest: sha256:461a83f20429597b7b3f2d38bbad7f5cedb6c26d57af5e0cc02f87147ae28acb
generated: 2018-05-04T19:06:48.914008844+02:00
2 changes: 1 addition & 1 deletion api/helm/api/requirements.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dependencies:
- name: postgresql
version: 0.8.1
version: 0.11.0
repository: https://kubernetes-charts.storage.googleapis.com/
condition: postgresql.enabled
2 changes: 1 addition & 1 deletion api/helm/api/templates/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ metadata:
type: Opaque
data:
{{ if .Values.postgresql.enabled }}
database-url: {{ printf "pgsql://%s:%s@%s/%s?serverVersion=9.6" .Values.postgresql.postgresUser .Values.postgresql.postgresPassword $postgresqlServiceName .Values.postgresql.postgresDatabase | b64enc | quote }}
database-url: {{ printf "pgsql://%s:%s@%s/%s" .Values.postgresql.postgresUser .Values.postgresql.postgresPassword $postgresqlServiceName .Values.postgresql.postgresDatabase | b64enc | quote }}
{{ else }}
database-url: {{ .Values.postgresql.url | b64enc | quote }}
{{ end }}
Expand Down
10 changes: 5 additions & 5 deletions api/helm/api/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ secret: ChangeMe
corsAllowOrigin: http://example.com

php:
repository: gcr.io/test-api-platform/php
repository: quay.io/api-platform/php
tag: latest
pullPolicy: Always
replicaCount: 1

nginx:
repository: gcr.io/test-api-platform/nginx
repository: quay.io/api-platform/nginx
tag: latest
pullPolicy: Always
replicaCount: 1

varnish:
enabled: true
#url: https://example.com
repository: gcr.io/test-api-platform/varnish
repository: quay.io/api-platform/varnish
tag: latest
pullPolicy: Always
replicaCount: 1
Expand All @@ -40,14 +40,14 @@ ingress:
postgresql:
enabled: true
# If bringing your own PostgreSQL, the full uri to use
#url: pgsql://api-platform:!ChangeMe!@example.com/api?serverVersion=10.1
#url: pgsql://api-platform:!ChangeMe!@example.com/api
postgresUser: api-platform
postgresPassword: ChangeMe
postgresDatabase: api
# Persistent Volume Storage configuration.
# ref: https://kubernetes.io/docs/user-guide/persistent-volumes
persistence:
enabled: false
enabled: true

resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
Expand Down
7 changes: 4 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
version: '3.2'
version: '3.4'

services:
php:
image: ${CONTAINER_REGISTRY_BASE}/php
build:
context: ./api
target: api_platform_php
cache_from:
- ${CONTAINER_REGISTRY_BASE}/php
depends_on:
Expand All @@ -21,7 +22,7 @@ services:
image: ${CONTAINER_REGISTRY_BASE}/nginx
build:
context: ./api
dockerfile: Dockerfile.nginx
target: api_platform_nginx
cache_from:
- ${CONTAINER_REGISTRY_BASE}/nginx
depends_on:
Expand All @@ -35,7 +36,7 @@ services:
image: ${CONTAINER_REGISTRY_BASE}/varnish
build:
context: ./api
dockerfile: Dockerfile.varnish
target: api_platform_varnish
cache_from:
- ${CONTAINER_REGISTRY_BASE}/varnish
depends_on:
Expand Down

0 comments on commit ba033c9

Please sign in to comment.