Skip to content
Open
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
28 changes: 28 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Docker build (and Run the acceptance tests)

on:
push:
branches:
- master
pull_request:
branches:
- master
- feature/*
- fix/*

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Via the Makefile, build the Docker image
run: make build

- name: Via the Makefile, run the acceptance tests
run: make run-tests-acceptance

- name: Via the Makefile, stop the started contaiers
if: always()
run: make stop
36 changes: 36 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Run the integration tests

on:
push:
branches:
- master
pull_request:
branches:
- master
- feature/*
- fix/*

jobs:
validate:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install packages
run: composer install --no-interaction

- name: Run phpcs
run: vendor/bin/phpcs

- name: Run phpstan
run: vendor/bin/phpstan analyse src --ansi

- name: Run (unit and api) tests with code coverage
run: vendor/bin/codecept run unit,api --coverage --coverage-xml

- name: Publish code coverage
if: github.event_name == 'pull_request'
run: bash <(curl -s https://codecov.io/bash) -f tests/_output/coverage.xml
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

* PHP/Symfony : Base-project with docker/docker-compose configuration
* API : Add the */ping* route
* API : Add the */health* route
* CI/CD : Add the Travis CI configuration
* CI/CD : Add the GitHub Actions configuration
* Code Quality : phpcs / phpstan
* Code Quality : Publish the code coverage report to *codecov.io*
* Tests: Unitary/Api/Acceptance tests via codeception
14 changes: 5 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,17 @@ ARG ARG_APP_ENV=prod
ENV APP_ENV=$ARG_APP_ENV

# prevent the reinstallation of vendors at every changes in the source code
COPY composer.json composer.lock symfony.lock ./
COPY .env composer.json composer.lock symfony.lock ./
RUN set -eux; \
composer install --prefer-dist --no-dev --no-scripts --no-progress --no-suggest; \
composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress --no-suggest; \
composer clear-cache

# do not use .env files in production
COPY .env ./
RUN composer dump-env ${APP_ENV}; \
rm .env

# copy only specifically what we need
# Copy only specifically what we need
COPY bin bin/
COPY config config/
COPY public public/
COPY src src/
COPY templates templates/

RUN set -eux; \
mkdir -p var/cache var/log; \
Expand Down Expand Up @@ -119,4 +115,4 @@ COPY docker/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf

WORKDIR /srv/api/public

COPY --from=api_symfony_php /srv/api/public ./
COPY --from=api_symfony_php /srv/api/public ./
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Web service with PHP/Symfony
# API base-project with PHP/Symfony
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can generate automatically helm configuration Table with https://github.com/norwoodj/helm-docs or others tools

[![Build Status](https://travis-ci.org/epourail/template-api-symfony.svg?branch=master)](https://travis-ci.org/epourail/template-api-symfony)
[![codecov](https://codecov.io/gh/epourail/template-api-symfony/branch/master/graph/badge.svg)](https://codecov.io/gh/epourail/template-api-symfony)

Expand All @@ -9,9 +9,13 @@ Features
- [x] api-php : PHP 7.3 / Symfony 5.X
- [x] api-nginx : NGINX 1.17
- [x] api-tests : CodeCeption 4.0
- [x] Docker Compose Integration
- [x] Orchestration :
- [x] Kubernetes
- [x] Makefile
- [x] Tests : unitary, api, acceptance
- [x] Tests : unitary, api, acceptance (codeception)
- [x] Continuous Integration : Travis
- [x] Continuous Integration : GitHub actions
- [x] Code Coverage Report : Codecov
- [x] Code quality
- [x] PHP Code Sniffer (phpcs)
Expand Down Expand Up @@ -74,6 +78,23 @@ X-Robots-Tag: noindex
pong
```

Readiness probe

```bash
➜ curl -i http://127.0.0.1:8881/health
HTTP/1.1 200 OK
Server: nginx/1.17.6
Content-Type: text/plain; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/7.3.13
Cache-Control: no-cache, private
Date: Thu, 02 Jan 2020 12:52:13 GMT
X-Robots-Tag: noindex

healthy
```

## Test

```bash
Expand Down
22 changes: 22 additions & 0 deletions charts/template-api/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
17 changes: 17 additions & 0 deletions charts/template-api/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
appVersion: "1.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Docker image tag of template here to avoid compatibility issues. If this chart can be used by any symfony application, you can copy the chart version. The chart is therefore insensitive as in your default values ‘values.yaml’ here nginx:stable

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It must be a semver

description: A Helm base-chart for Kubernetes to deploy the api
name: template-api
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name is really important here, thinks generic and reusable. I suggest symfony. It will be available like this epourail/symfony

version: 0.1.0
keywords:
Copy link
Collaborator

@Ealenn Ealenn Feb 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The keywords is used in repository UI / CLI search command. You can add

  • symfony
  • php
  • boilerplate
    ...

- api
- php
- symfony
- ping
- template
- rest
- test
sources:
- https://github.com/epourail/template-api-symfony
maintainers:
- name: Julien Verger
56 changes: 56 additions & 0 deletions charts/template-api/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "template-api.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "template-api.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "template-api.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "template-api.labels" -}}
app.kubernetes.io/name: {{ include "template-api.name" . }}
helm.sh/chart: {{ include "template-api.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

{{/*
Create the name of the service account to use
*/}}
{{- define "template-api.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "template-api.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
57 changes: 57 additions & 0 deletions charts/template-api/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "template-api.fullname" . }}
labels:
{{ include "template-api.labels" . | indent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "template-api.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "template-api.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ template "template-api.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 80
protocol: TCP
livenessProbe:
httpGet:
path: /ping
port: http
readinessProbe:
httpGet:
path: /health
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
41 changes: 41 additions & 0 deletions charts/template-api/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "template-api.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{ include "template-api.labels" . | indent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ . }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
16 changes: 16 additions & 0 deletions charts/template-api/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "template-api.fullname" . }}
labels:
{{ include "template-api.labels" . | indent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
app.kubernetes.io/name: {{ include "template-api.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
8 changes: 8 additions & 0 deletions charts/template-api/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ template "template-api.serviceAccountName" . }}
labels:
{{ include "template-api.labels" . | indent 4 }}
{{- end -}}
15 changes: 15 additions & 0 deletions charts/template-api/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "template-api.fullname" . }}-test-connection"
labels:
{{ include "template-api.labels" . | indent 4 }}
annotations:
"helm.sh/hook": test-success
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "template-api.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
Loading