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
16 changes: 16 additions & 0 deletions nginx-php-fpm-apb/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM ansibleplaybookbundle/apb-base

LABEL "com.redhat.apb.version"="0.1.0"
LABEL "com.redhat.apb.spec"=\
"bmFtZTogbmdpbngtcGhwLWZwbS1hcGIKaW1hZ2U6IGFuc2libGVwbGF5Ym9va2J1bmRsZS9uZ2lu\
eC1waHAtZnBtLWFwYgpkZXNjcmlwdGlvbjogVGhpcyBpcyBhbiBhcHBsaWNhdGlvbiB3aXRoIHR3\
byBjb250YWluZXJzIG5naW54IGFuZCBwaHAtZnBtLgpiaW5kYWJsZTogRmFsc2UKYXN5bmM6IG9w\
dGlvbmFsCm1ldGFkYXRhOgogIGRpc3BsYXlOYW1lOiBuZ2lueC1waHAtZnBtCnBsYW5zOgogIC0g\
bmFtZTogZGVmYXVsdAogICAgZGVzY3JpcHRpb246IFRoaXMgZGVmYXVsdCBwbGFuIGRlcGxveXMg\
bmdpbngtcGhwLWZwbS1hcGIKICAgIGZyZWU6IFRydWUKICAgIG1ldGFkYXRhOiB7fQogICAgcGFy\
YW1ldGVyczogW10="

COPY playbooks /opt/apb/actions
COPY roles /opt/ansible/roles
RUN chmod -R g=u /opt/{ansible,apb}
USER apb
19 changes: 19 additions & 0 deletions nginx-php-fpm-apb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
nginx-php-fpm-apb
======================

An apb for deploying nginx and php-fpm containers.

## What it does
* Deploys 1 nginx container and 1 php-fpm container and links them.

## Requirements
* Existing project

## Parameters
* namespace: name of an existing namespace / project

## Running the application
`docker run -e "OPENSHIFT_TARGET=<openshift_target>" -e "OPENSHIFT_TOKEN"=<openshift_token>" ansibleplaybookbundle/nginx-php-fpm-apb provision --extra-vars "namespace=<your project name/namespace>"`

## Tearing down the application
`docker run -e "OPENSHIFT_TARGET=<openshift_target>" -e "OPENSHIFT_TOKEN"=<openshift_token>" ansibleplaybookbundle/nginx-php-fpm-apb deprovision --extra-vars "namespace=<your project name/namespace>"`
13 changes: 13 additions & 0 deletions nginx-php-fpm-apb/apb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: nginx-php-fpm-apb
image: ansibleplaybookbundle/nginx-php-fpm-apb
description: This is an application with two containers nginx and php-fpm.
bindable: False
async: optional
metadata:
displayName: nginx-php-fpm
plans:
- name: default
description: This default plan deploys nginx-php-fpm-apb
free: True
metadata: {}
parameters: []
10 changes: 10 additions & 0 deletions nginx-php-fpm-apb/playbooks/deprovision.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- name: nginx-php-fpm-apb playbook to deprovision the application
hosts: localhost
gather_facts: false
connection: local
roles:
- role: ansible.kubernetes-modules
install_python_requirements: no
- role: ansibleplaybookbundle.asb-modules
- role: deprovision-nginx-php-fpm-apb
playbook_debug: false
10 changes: 10 additions & 0 deletions nginx-php-fpm-apb/playbooks/provision.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- name: nginx-php-fpm-apb playbook to provision the application
hosts: localhost
gather_facts: false
connection: local
roles:
- role: ansible.kubernetes-modules
install_python_requirements: no
- role: ansibleplaybookbundle.asb-modules
- role: provision-nginx-php-fpm-apb
playbook_debug: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
##############################################################################
## Deprovision nginx-php-fpm
## This role executes much of the needed functionality to deprovision an
## application using an Ansible Playbook Bundle and delete resources created
## in the sample apb generated by the provision role.
##############################################################################


##############################################################################
## Deprovision a route
##############################################################################
- openshift_v1_route:
name: nginx-php-fpm
namespace: '{{ namespace }}'
state: absent


##############################################################################
## Deprovision a service
##############################################################################
- k8s_v1_service:
name: nginx-php-fpm
namespace: '{{ namespace }}'
state: absent


##############################################################################
## Deprovision a deployment config
## When removing a Deployment Config, OpenShift will automatically clean up
## its associated resources like replication controllers and pods
##############################################################################
- openshift_v1_deployment_config:
name: nginx-php-fpm
namespace: '{{ namespace }}'
state: absent

- name: Delete NGINX configmap
shell: oc delete configmap {{ item }} -n {{ namespace }}
with_items:
- nginx-conf
- site-files

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
server {
listen 8080;
server_name localhost;

location / {
root /var/www/html;
index index.php index.html;
}

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}

location ~ \.php$ {
fastcgi_pass nginx-php-fpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
include fastcgi_params;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php phpinfo(); ?>
</body>
</html>
121 changes: 121 additions & 0 deletions nginx-php-fpm-apb/roles/provision-nginx-php-fpm-apb/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
##############################################################################
## Provision nginx-php-fpm
## This role executes much of the needed functionality to provision an
## application using an Ansible Playbook Bundle. Included in the comments
## below are some sample resources for getting started deploying an application
## to OpenShift.
##############################################################################


##############################################################################
## An OpenShift Origin deployment configuration provides a replication
## controller, spins up pods, and also provides the ability to transition from
## one deployment of an image to a new one.
## https://docs.openshift.org/latest/architecture/core_concepts/deployments.html#deployments-and-deployment-configurations
##############################################################################
- name: create deployment config
openshift_v1_deployment_config:
name: nginx-php-fpm
namespace: '{{ namespace }}'
labels:
app: '{{ namespace }}'
service: nginx-php-fpm
replicas: 1
selector:
app: '{{ namespace }}'
service: nginx-php-fpm
spec_template_metadata_labels:
app: '{{ namespace }}'
service: nginx-php-fpm
containers:
- env:
image: php:7.1-fpm-alpine
imagePullPolicy: IfNotPresent
name: php-fpm
ports:
- container_port: 9000
protocol: TCP
volumeMounts:
- mountPath: /var/www/html
name: site
- env:
image: toccoag/openshift-nginx
imagePullPolicy: IfNotPresent
name: nginx
ports:
- container_port: 80
protocol: TCP
volumeMounts:
- mountPath: /etc/nginx/conf.d
name: configuration
- mountPath: /var/www/html
name: site
restart_policy: Always
volumes:
- name: site
configMap:
name: site-files
items:
- key: index-php
path: index.php
- name: configuration
configMap:
name: nginx-conf
items:
- key: nginx-conf
path: default.conf

##############################################################################
## A Kubernetes service serves as an internal load balancer. It identifies a
## set of replicated pods in order to proxy the connections it receives to them.
## https://docs.openshift.org/latest/architecture/core_concepts/pods_and_services.html#services
##############################################################################
- name: create nginx-php-fpm service
k8s_v1_service:
name: nginx-php-fpm
namespace: '{{ namespace }}'
labels:
app: '{{ namespace }}'
service: nginx-php-fpm
selector:
app: '{{ namespace }}'
service: nginx-php-fpm
ports:
- name: nginx
port: 80
target_port: 8080
- name: php-fpm
port: 9000
target_port: 9000

##############################################################################
## An OpenShift Origin route exposes a service at a host name, so that external
## clients can reach it by name. Each route consists of a name, a service
## selector, and an optional security configuration.
## https://docs.openshift.org/latest/architecture/core_concepts/routes.html
##############################################################################
- name: create nginx-php-fpm route
openshift_v1_route:
name: nginx-php-fpm
namespace: '{{ namespace }}'
labels:
app: '{{ namespace }}'
service: nginx-php-fpm
to_name: nginx-php-fpm
spec_port_target_port: nginx

- name: Copy default.conf
copy:
src: default.conf
dest: /tmp/default.conf

- name: Create NGINX configmap for nginx.conf
shell: oc create configmap nginx-conf --from-file=nginx-conf=/tmp/default.conf -n {{ namespace }}

- name: Copy index.php
copy:
src: index.php
dest: /tmp/index.php

- name: Create NGINX configmap for index.php
shell: oc create configmap site-files --from-file=index-php=/tmp/index.php -n {{ namespace }}