diff --git a/incubator/nginx/examples/nginx.jsonnet b/incubator/nginx/examples/nginx.jsonnet index 485b5d6..c1dd6cf 100644 --- a/incubator/nginx/examples/nginx.jsonnet +++ b/incubator/nginx/examples/nginx.jsonnet @@ -3,9 +3,23 @@ local nginx = import '../nginx.libsonnet'; local namespace = "dev-alex"; local appName = "nginx-app"; +// sample configuration for php-fpm +// Note: must escape file path with extra \ +local sbConfig = "server { + listen 0.0.0.0:80; + root /app; + location / { + index index.html index.php; + } + location ~ \\.php$ { + fastcgi_pass phpfpm-server:9000; + fastcgi_index index.php; + include fastcgi.conf; + } +}"; k.core.v1.list.new([ nginx.parts.deployment.withServerBlock(namespace, appName), nginx.parts.service(namespace, appName), - nginx.parts.serverBlockConfigMap(namespace, appName), + nginx.parts.serverBlockConfigMap(namespace, appName, sbConfig), ]) diff --git a/incubator/nginx/mixin.yaml b/incubator/nginx/mixin.yaml index d740c28..3efd805 100644 --- a/incubator/nginx/mixin.yaml +++ b/incubator/nginx/mixin.yaml @@ -1,7 +1,7 @@ { "name": "nginx", "version": "0.0.1", - "description": "TODO: YOUR DESCRIPTION HERE", + "description": "This library makes it easy to deploy a Nginx Server to your Kubernetes cluster using ksonnet prototypes. Each prototype is made up of a subset of the following preconfigured components: deployment, service, and network policy.", "author": "ksonnet team ", "contributors": [ { diff --git a/incubator/nginx/nginx.libsonnet b/incubator/nginx/nginx.libsonnet index 67bf541..3dcaaf4 100644 --- a/incubator/nginx/nginx.libsonnet +++ b/incubator/nginx/nginx.libsonnet @@ -115,25 +115,7 @@ local container = deployment.mixin.spec.template.spec.containersType; }, }, - serverBlockConfigMap(namespace, name):: { - local defaults = { - // example PHP-FPM vhost - vhost: - ||| - server { - listen 0.0.0.0:80; - root /app; - location / { - index index.html index.php; - } - location ~ \.php$ { - fastcgi_pass phpfpm-server:9000; - fastcgi_index index.php; - include fastcgi.conf; - } - } - ||| - }, + serverBlockConfigMap(namespace, name, sbConfig):: { apiVersion: "v1", kind: "ConfigMap", metadata: { @@ -142,7 +124,7 @@ local container = deployment.mixin.spec.template.spec.containersType; labels: { app: name }, }, data: { - "vhost.conf": defaults.vhost, + "vhost.conf": sbConfig, }, }, }, diff --git a/incubator/nginx/prototypes/nginx-server-block.jsonnet b/incubator/nginx/prototypes/nginx-server-block.jsonnet index ecef175..c0af6af 100644 --- a/incubator/nginx/prototypes/nginx-server-block.jsonnet +++ b/incubator/nginx/prototypes/nginx-server-block.jsonnet @@ -1,21 +1,21 @@ // @apiVersion 0.0.1 // @name io.ksonnet.pkg.nginx-server-block -// @description Deploys a simple, stateless nginx server with server blocks (roughly equivalent -// to nginx virtual hosts). The nginx container is deployed using a -// Kubernetes deployment, and is exposed to a network with a service. -// @param namespace string Namespace in which to put the application -// @param name string Name to give to all components. - -// TODO: How should the ServerBlockConf be exposed to the user? Not quite sure what the default does except for setting web server to port 80. +// @description When generated and applied, this prototype deploys stateless nginx server with server blocks (roughly equivalent +// to Apache virtual hosts). The nginx container is deployed using a +// Kubernetes deployment, and is exposed to a network with a service. The configMap is used to specify the files served. +// @param namespace string Namespace to specify destination within cluster +// @param name string Name of app to attach as identifier to all parts +// @param sbConfig string Server block configuration data to store local k = import 'ksonnet.beta.2/k.libsonnet'; local nginx = import 'incubator/nginx/nginx.libsonnet'; local namespace = import 'param://namespace'; local appName = import 'param://name'; +local serverBlockConfig = import 'param://serverblockconfig' k.core.v1.list.new([ nginx.parts.deployment.withServerBlock(namespace, appName), nginx.parts.service(namespace, appName), - nginx.parts.serverBlockConfigMap(namespace, appName), + nginx.parts.serverBlockConfigMap(namespace, appName, serverBlockConfig), ]) diff --git a/incubator/nginx/prototypes/nginx-simple.jsonnet b/incubator/nginx/prototypes/nginx-simple.jsonnet index 562248b..e85d5ad 100644 --- a/incubator/nginx/prototypes/nginx-simple.jsonnet +++ b/incubator/nginx/prototypes/nginx-simple.jsonnet @@ -1,11 +1,10 @@ // @apiVersion 0.0.1 // @name io.ksonnet.pkg.nginx-simple -// @description Deploys a simple, stateless nginx server with server blocks (roughly equivalent -// to nginx virtual hosts). The nginx container is deployed using a -// Kubernetes deployment, and is exposed to a network with a service. -// @param namespace string Namespace in which to put the application -// @param name string Name to give to each of the components - +// @description When generated and applied, this prototype deploys a stateless nginx web +// server. The nginx container is deployed using a Kubernetes deployment, and +// is exposed to a network through a service. +// @param namespace string Namespace to specify destination within cluster +// @param name string Name of app to attach as identifier to all parts local k = import 'ksonnet.beta.2/k.libsonnet'; local nginx = import 'incubator/nginx/nginx.libsonnet';