Skip to content

Instantly share code, notes, and snippets.

@badri
Last active August 6, 2018 04:30
Show Gist options
  • Save badri/80fe1bcce4d748ee8609c64b0a82650b to your computer and use it in GitHub Desktop.
Save badri/80fe1bcce4d748ee8609c64b0a82650b to your computer and use it in GitHub Desktop.
OpenShift LEMP template construction
apiVersion: v1
kind: Template
metadata:
name: ubuntu-lemp
objects:
- apiVersion: v1
kind: BuildConfig
metadata:
annotations:
openshift.io/generated-by: OpenShiftNewApp
name: ${NAME}
spec:
output:
to:
kind: ImageStreamTag
name: ${NAME}:latest
source:
git:
ref: ${SOURCE_REPOSITORY_REF}
uri: ${SOURCE_REPOSITORY_URL}
type: Git
strategy:
sourceStrategy:
from:
kind: ImageStreamTag
name: openshift-drupal:v6
namespace: ${NAMESPACE}
type: Source
triggers:
- type: ImageChange
- type: ConfigChange
- github:
secret: ${GITHUB_WEBHOOK_SECRET}
type: GitHub
- apiVersion: v1
kind: ImageStream
metadata:
annotations:
openshift.io/generated-by: OpenShiftNewApp
name: ${NAME}
- apiVersion: v1
kind: DeploymentConfig
metadata:
annotations:
openshift.io/generated-by: OpenShiftNewApp
name: ${NAME}
spec:
replicas: 1
selector:
name: ${NAME}
strategy:
type: Recreate
template:
metadata:
annotations:
openshift.io/generated-by: OpenShiftNewApp
labels:
name: ${NAME}
spec:
containers:
- env:
- name: MYSQL_HOST
value: ${MYSQL_SERVICE_NAME}
- name: MYSQL_PORT
value: "3306"
- name: MYSQL_DATABASE
valueFrom:
secretKeyRef:
key: database-name
name: mysql
- name: MYSQL_USER
valueFrom:
secretKeyRef:
key: database-user
name: mysql
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
key: database-password
name: mysql
image: ' '
imagePullPolicy: Always
name: env-clear
ports:
- containerPort: 8080
protocol: TCP
resources:
limits:
memory: ${MEMORY_LIMIT}
triggers:
- type: ConfigChange
- imageChangeParams:
automatic: true
containerNames:
- env-clear
from:
kind: ImageStreamTag
name: ${NAME}:latest
type: ImageChange
- apiVersion: v1
kind: DeploymentConfig
metadata:
annotations:
template.alpha.openshift.io/wait-for-ready: "true"
name: ${MYSQL_SERVICE_NAME}
spec:
replicas: 1
selector:
name: ${MYSQL_SERVICE_NAME}
strategy:
type: Recreate
template:
metadata:
labels:
name: ${MYSQL_SERVICE_NAME}
spec:
containers:
- env:
- name: MYSQL_USER
valueFrom:
secretKeyRef:
key: database-user
name: mysql
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
key: database-password
name: mysql
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
key: database-root-password
name: mysql
- name: MYSQL_DATABASE
valueFrom:
secretKeyRef:
key: database-name
name: mysql
image: ' '
livenessProbe:
failureThreshold: 3
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 3306
timeoutSeconds: 1
name: mysql
ports:
- containerPort: 3306
protocol: TCP
readinessProbe:
exec:
command:
- /bin/sh
- -i
- -c
- MYSQL_PWD="$MYSQL_PASSWORD" mysql -h 127.0.0.1 -u $MYSQL_USER -D $MYSQL_DATABASE
-e 'SELECT 1'
failureThreshold: 3
initialDelaySeconds: 5
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: ${MEMORY_MYSQL_LIMIT}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/lib/mysql/data
name: ${MYSQL_SERVICE_NAME}-data
volumes:
- name: ${MYSQL_SERVICE_NAME}-data
persistentVolumeClaim:
claimName: ${MYSQL_SERVICE_NAME}
triggers:
- imageChangeParams:
automatic: true
containerNames:
- mysql
from:
kind: ImageStreamTag
name: mysql:5.7
namespace: ${NAMESPACE}
type: ImageChange
- type: ConfigChange
- apiVersion: v1
kind: Route
metadata:
annotations:
openshift.io/host.generated: "true"
name: ${NAME}
spec:
host: ${APPLICATION_DOMAIN}
to:
kind: Service
name: ${NAME}
- apiVersion: v1
kind: Service
metadata:
annotations:
service.alpha.openshift.io/dependencies: '[{"name": "${MYSQL_SERVICE_NAME}",
"kind": "Service"}]'
name: ${NAME}
spec:
ports:
- name: web
port: 8080
protocol: TCP
targetPort: 8080
selector:
name: ${NAME}
- apiVersion: v1
kind: Service
metadata:
annotations:
name: ${MYSQL_SERVICE_NAME}
spec:
ports:
- name: mysql
port: 3306
protocol: TCP
targetPort: 3306
selector:
name: ${MYSQL_SERVICE_NAME}
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ${MYSQL_SERVICE_NAME}
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: ${VOLUME_CAPACITY}
parameters:
- description: The name assigned to all of the frontend objects defined in this template.
displayName: Name
name: NAME
required: true
value: ubuntu-lemp-persistent
- description: The OpenShift Namespace where the ImageStream resides.
displayName: Namespace
name: NAMESPACE
required: true
value: openshift
- description: Maximum amount of memory the Ubuntu LEMP container can use.
displayName: Memory Limit
name: MEMORY_LIMIT
required: true
value: 512Mi
- description: Maximum amount of memory the MySQL container can use.
displayName: Memory Limit (MySQL)
name: MEMORY_MYSQL_LIMIT
required: true
value: 512Mi
- description: Volume space available for data, e.g. 512Mi, 2Gi
displayName: Volume Capacity
name: VOLUME_CAPACITY
required: true
value: 1Gi
- description: The URL of the repository with your application source code.
displayName: Git Repository URL
name: SOURCE_REPOSITORY_URL
required: true
value: https://github.com/shapeblock/php-mysql.git
- description: Set this to a branch name, tag or other ref of your repository if you
are not using the default branch.
displayName: Git Reference
name: SOURCE_REPOSITORY_REF
- description: The exposed hostname that will route to the LEMP service, if left
blank a value will be defaulted.
displayName: Application Hostname
name: APPLICATION_DOMAIN
- description: Github trigger secret. A difficult to guess string encoded as part
of the webhook URL. Not encrypted.
displayName: GitHub Webhook Secret
from: '[a-zA-Z0-9]{40}'
generate: expression
name: GITHUB_WEBHOOK_SECRET
- displayName: Database Service Name
name: MYSQL_SERVICE_NAME
required: true
value: mysql
- displayName: Database Name
name: MYSQL_DATABASE
required: true
value: default
- displayName: Database User
name: MYSQL_USER
required: true
value: ubuntulemp
- displayName: Database Password
from: '[a-zA-Z0-9]{16}'
generate: expression
name: MYSQL_PASSWORD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment