Skip to content

Commit

Permalink
Merge pull request #66 from sclorg/support_php_template
Browse files Browse the repository at this point in the history
Add support for PHP CakePHP application helm chart
  • Loading branch information
phracek authored Jan 16, 2024
2 parents d189951 + 9d3a8fb commit 88c93c1
Show file tree
Hide file tree
Showing 13 changed files with 329 additions and 0 deletions.
2 changes: 2 additions & 0 deletions charts/redhat/nginx-template/src/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ version: 0.0.1
kubeVersion: '>=1.20.0'
annotations:
charts.openshift.io/name: Red Hat Nginx HTTP Server (nginx) application (experimental).
charts.openshift.io/provider: Red Hat
charts.openshift.io/providerType: redhat
apiVersion: v2
appVersion: 0.0.1
sources:
Expand Down
9 changes: 9 additions & 0 deletions charts/redhat/php-cakephp-application/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
chart:
name: perl-cakephp-template
description: This is the Red Hat quickstart CakePHP application with no database helm chart
publicPgpKey: null
users:
- githubUsername: phracek
vendor:
label: redhat
name: Red Hat
14 changes: 14 additions & 0 deletions charts/redhat/php-cakephp-application/src/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
description: This content is experimental, do not use it in production. An example CakePHP application with no database. For more information
about using this template, including OpenShift considerations, see https://github.com/sclorg/cakephp-ex/blob/master/README.md.
name: php-cakephp-application
tags: quickstart,php,cakephp
version: 0.0.1
kubeVersion: '>=1.20.0'
annotations:
charts.openshift.io/name: Red Hat Apache CakePHP application with no database (experimental)
charts.openshift.io/provider: Red Hat
charts.openshift.io/providerType: redhat
apiVersion: v2
appVersion: 0.0.1
sources:
- https://github.com/sclorg/helm-charts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
annotations:
description: Defines how to build the application
template.alpha.openshift.io/wait-for-ready: "true"
labels:
app: cakephp-example
template: cakephp-example
name: {{ .Values.name }}
spec:
output:
to:
kind: ImageStreamTag
name: {{ .Values.name }}:latest
postCommit:
script: ./vendor/bin/phpunit
source:
contextDir: {{ .Values.context_dir }}
git:
ref: {{ .Values.source_repository_ref }}
uri: {{ .Values.source_repository_url }}
type: Git
strategy:
sourceStrategy:
env:
- name: COMPOSER_MIRROR
value: {{ .Values.composer_mirror }}
from:
kind: ImageStreamTag
name: php:{{ .Values.php_version }}
namespace: {{ .Values.namespace }}
type: Source
triggers:
- type: ImageChange
- type: ConfigChange
- github:
secret: {{ .Values.github_webhook_secret }}
type: GitHub
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
description: Defines how to deploy the application server
image.openshift.io/triggers: |-
[
{
"from": {
"kind": "ImageStreamTag",
"name": "{{ .Values.name }}:latest"
},
"fieldPath": "spec.template.spec.containers[0].image"
}
]
template.alpha.openshift.io/wait-for-ready: "true"
labels:
app: cakephp-example
template: cakephp-example
name: {{ .Values.name }}
spec:
replicas: 1
selector:
matchLabels:
name: {{ .Values.name }}
strategy:
type: RollingUpdate
template:
metadata:
labels:
name: {{ .Values.name }}
name: {{ .Values.name }}
spec:
containers:
- env:
- name: CAKEPHP_SECRET_TOKEN
valueFrom:
secretKeyRef:
key: cakephp-secret-token
name: {{ .Values.name }}
- name: PHP_CLEAR_ENV
value: "OFF"
- name: CAKEPHP_SECURITY_SALT
valueFrom:
secretKeyRef:
key: cakephp-security-salt
name: {{ .Values.name }}
- name: OPCACHE_REVALIDATE_FREQ
value: "{{ .Values.opcache_revalidate_freq }}"
image: " "
livenessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 30
periodSeconds: 60
timeoutSeconds: 3
name: cakephp-example
ports:
- containerPort: 8080
readinessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 3
periodSeconds: 60
timeoutSeconds: 3
resources:
limits:
memory: {{ .Values.memory_limit }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: image.openshift.io/v1
kind: ImageStream
metadata:
annotations:
description: Keeps track of changes in the application image
labels:
app: cakephp-example
template: cakephp-example
name: {{ .Values.name }}
12 changes: 12 additions & 0 deletions charts/redhat/php-cakephp-application/src/templates/route.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: route.openshift.io/v1
kind: Route
metadata:
labels:
app: cakephp-example
template: cakephp-example
name: {{ .Values.name }}
spec:
host: {{ .Values.application_domain }}
to:
kind: Service
name: {{ .Values.name }}
10 changes: 10 additions & 0 deletions charts/redhat/php-cakephp-application/src/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Secret
metadata:
labels:
app: cakephp-example
template: cakephp-example
name: {{ .Values.name }}
stringData:
cakephp-secret-token: {{ .Values.cakephp_secret_token }}
cakephp-security-salt: {{ .Values.cakephp_security_salt }}
16 changes: 16 additions & 0 deletions charts/redhat/php-cakephp-application/src/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
annotations:
description: Exposes and load balances the application pods
labels:
app: cakephp-example
template: cakephp-example
name: {{ .Values.name }}
spec:
ports:
- name: web
port: 8080
targetPort: 8080
selector:
name: {{ .Values.name }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ .Release.Name }}-connection-test"
annotations:
"helm.sh/hook": test
labels:
name: {{ .Values.name }}
template: {{ .Values.name }}
spec:
containers:
- name: "{{ .Release.Name }}-connection-test"
namespace: "{{ .Release.Namespace }}"
image: "registry.redhat.io/ubi8/ubi:latest"
imagePullPolicy: IfNotPresent
command:
- '/bin/bash'
- '-exc'
- >
curl {{ .Values.name }}.{{ .Release.Namespace }}:8080 | grep "Welcome to CakePHP 4.5"
restartPolicy: Never
62 changes: 62 additions & 0 deletions charts/redhat/php-cakephp-application/src/values.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"$schema": "http://json-schema.org/schema#",
"type": "object",
"properties": {
"name": {
"type": "string",
"pattern": "^[a-z0-9-_]+$"
},
"namespace": {
"type": "string",
"title": "The URL of the repository with your application source code."
},
"php_version": {
"type": "string",
"description": "Version of PHP image to be used (8.1-ubi9 by default).",
"enum": [ "latest", "8.0-ubi8", "8.1-ubi9", "8.0-ubi9" ]
},
"memory_limit": {
"type": "string",
"title": "Maximum amount of memory the container can use.",
"form": true,
"render": "slider",
"sliderMin": 512,
"sliderMax": 65536,
"sliderUnit": "Mi"
},
"source_repository_url": {
"type": "string"
},
"source_repository_ref": {
"type": "string"
},
"context_dir": {
"type": "string",
"description": "Set this to the relative path to your project if it is not in the root of your repository."
},
"application_domain": {
"type": "string",
"description": "The exposed hostname that will route to the httpd service, if left blank a value will be defaulted."
},
"github_webhook_secret": {
"type": "string",
"description": "Github trigger secret. A difficult to guess string encoded as part of the webhook URL. Not encrypted."
},
"cakephp_secret_token": {
"type": "string",
"description": "Set this to a long random string."
},
"cakephp_security_salt": {
"type": "string",
"description": "Security salt for session hash."
},
"composer_mirror": {
"type": "string",
"description": "The custom Composer mirror URL."
},
"opcache_revalidate_freq": {
"type": "string",
"description": "How often to check script timestamps for updates, in seconds. 0 will result in OPcache checking for updates on every request."
}
}
}
13 changes: 13 additions & 0 deletions charts/redhat/php-cakephp-application/src/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
application_domain: "" # TODO: must define a default value for .application_domain
cakephp_secret_token: "" # TODO: must define a default value for .cakephp_secret_token
cakephp_security_salt: "" # TODO: must define a default value for .cakephp_security_salt
composer_mirror: "" # TODO: must define a default value for .composer_mirror
context_dir: "" # TODO: must define a default value for .context_dir
github_webhook_secret: "SOMETHING" # TODO: must define a default value for .github_webhook_secret
memory_limit: 512Mi
name: cakephp-example
namespace: openshift
opcache_revalidate_freq: "2"
php_version: 8.1-ubi9
source_repository_ref: "4.X" # TODO: must define a default value for .source_repository_ref
source_repository_url: https://github.com/sclorg/cakephp-ex.git
52 changes: 52 additions & 0 deletions tests/test_php_cakephp_application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os

import pytest
from pathlib import Path

from container_ci_suite.helm import HelmChartsAPI

test_dir = Path(os.path.abspath(os.path.dirname(__file__)))


class TestHelmCakePHPTemplate:

def setup_method(self):
package_name = "php-cakephp-application"
path = test_dir / "../charts/redhat"
self.hc_api = HelmChartsAPI(path=path, package_name=package_name, tarball_dir=test_dir)

def teardown_method(self):
self.hc_api.delete_project()

def test_curl_connection(self):
self.hc_api.package_name = "php-imagestreams"
self.hc_api.helm_package()
assert self.hc_api.helm_installation()
self.hc_api.package_name = "php-cakephp-application"
assert self.hc_api.helm_package()
assert self.hc_api.helm_installation(
values={
"nginx_version": "8.0-ubi8",
"namespace": self.hc_api.namespace
}
)
assert self.hc_api.is_s2i_pod_running()
assert self.hc_api.test_helm_curl_output(
route_name="cakephp-example",
expected_str="Welcome to CakePHP 4.5"
)

def test_by_helm_test(self):
self.hc_api.package_name = "php-imagestreams"
self.hc_api.helm_package()
assert self.hc_api.helm_installation()
self.hc_api.package_name = "php-cakephp-application"
assert self.hc_api.helm_package()
assert self.hc_api.helm_installation(
values={
"nginx_version": "8.0-ubi8",
"namespace": self.hc_api.namespace
}
)
assert self.hc_api.is_s2i_pod_running()
assert self.hc_api.test_helm_chart(expected_str=["Welcome to CakePHP 4.5"])

0 comments on commit 88c93c1

Please sign in to comment.