Permalink
Browse files

Merge pull request #711 from amazeeio/609-687-688-addtl-env-vars

#609 #687 #688 - env vars in configmap and x-robots-tag on autogenerated routes
  • Loading branch information...
Schnitzel committed Nov 6, 2018
2 parents d7a84cc + e54e111 commit 52bd58c42b2daa8fe5c642ff6f4bb142723abadd
@@ -1,13 +1,12 @@
# Load environment variable LAGOON_ENVIRONMENT_TYPE into nginx variable. LAGOON_ENVIRONMENT_TYPE will be replaced via envplate during docker-entrypoint
set $lagoon_environment_type '${LAGOON_ENVIRONMENT_TYPE:-development}';
# By default no x-robots-tag
set $x_robots_tag '';
# If this is an development environment do not index
if ($lagoon_environment_type = 'development') {
set $x_robots_tag 'noindex, nofollow';
# Set X-Robots-Tag to 'noindex, nofollow' for development environments and Lagoon autogenerated routes
header_filter_by_lua_block {
-- escape characters in the hostname
host = string.gsub(ngx.var.host, "%p", "%%%1")
-- check to see if we are a development environment
if string.match (os.getenv("LAGOON_ENVIRONMENT_TYPE"), 'development') then
ngx.header["X-Robots-Tag"] = 'noindex, nofollow';
-- check hostname against autogenerated routes
elseif string.match (os.getenv("LAGOON_AUTOGENERATED_ROUTES"),host) then
ngx.header["X-Robots-Tag"] = 'noindex, nofollow';
end
}
# actually add header (will not be added variable is empty)
add_header X-Robots-Tag $x_robots_tag always;
View
@@ -1,6 +1,10 @@
error_log /dev/stdout ${NGINX_ERROR_LOG_LEVEL:-warn};
# Establish some environment variables for later use
env LAGOON_AUTOGENERATED_ROUTES;
env LAGOON_ENVIRONMENT_TYPE;
events {
worker_connections 1024;
multi_accept on;
@@ -362,6 +362,9 @@ fi
# Load all routes with correct schema and comma separated
ROUTES=$(oc --insecure-skip-tls-verify -n ${OPENSHIFT_PROJECT} get routes -o=go-template --template='{{range $index, $route := .items}}{{if $index}},{{end}}{{if $route.spec.tls.termination}}https://{{else}}http://{{end}}{{$route.spec.host}}{{end}}')
# Get list of autogenerated routes
AUTOGENERATED_ROUTES=$(oc --insecure-skip-tls-verify -n ${OPENSHIFT_PROJECT} get routes -l "lagoon/autogenerated=true" -o=go-template --template='{{range $index, $route := .items}}{{if $index}},{{end}}{{if $route.spec.tls.termination}}https://{{else}}http://{{end}}{{$route.spec.host}}{{end}}')
# If no MONITORING_URLS were specified, fall back to the ROUTE of the project
if [ -z "$MONITORING_URLS"]; then
echo "No monitoring_urls provided, using ROUTE"
@@ -381,6 +384,8 @@ oc process --local --insecure-skip-tls-verify \
-p ROUTE="${ROUTE}" \
-p ROUTES="${ROUTES}" \
-p MONITORING_URLS="${MONITORING_URLS}" \
-p OPENSHIFT_NAME="${OPENSHIFT_NAME}" \
-p AUTOGENERATED_ROUTES="${AUTOGENERATED_ROUTES}" \
| oc apply --insecure-skip-tls-verify -n ${OPENSHIFT_PROJECT} -f -
# Add environment variables from lagoon API
@@ -19,6 +19,9 @@ parameters:
- name: PROJECT
description: Which project this belongs to, original value
required: true
- name: OPENSHIFT_NAME
description: The name of the openshift cluster this project is running on
required: true
- name: ENVIRONMENT_TYPE
description: Which environment type this project is
value: development
@@ -31,6 +34,9 @@ parameters:
- name: MONITORING_URLS
description: The routes specified for monitoring the production environment of this project
value: ""
- name: AUTOGENERATED_ROUTES
description: Routes which were automatically generated by Lagoon
value: ""
objects:
- kind: ConfigMap
apiVersion: v1
@@ -45,3 +51,5 @@ objects:
LAGOON_ROUTE: ${ROUTE}
LAGOON_ROUTES: ${ROUTES}
LAGOON_MONITORING_URLS: ${MONITORING_URLS}
LAGOON_OPENSHIFT_NAME: ${OPENSHIFT_NAME}
LAGOON_AUTOGENERATED_ROUTES: ${AUTOGENERATED_ROUTES}
@@ -45,6 +45,7 @@ objects:
service: ${SERVICE_NAME}
branch: ${SAFE_BRANCH}
project: ${SAFE_PROJECT}
lagoon/autogenerated: "true"
name: ${SERVICE_NAME}
spec:
host: ${SERVICE_ROUTER_URL}
@@ -45,6 +45,7 @@ objects:
service: ${SERVICE_NAME}
branch: ${SAFE_BRANCH}
project: ${SAFE_PROJECT}
lagoon/autogenerated: "true"
name: ${SERVICE_NAME}
spec:
host: ${SERVICE_ROUTER_URL}
@@ -45,6 +45,7 @@ objects:
service: ${SERVICE_NAME}
branch: ${SAFE_BRANCH}
project: ${SAFE_PROJECT}
lagoon/autogenerated: "true"
name: ${SERVICE_NAME}
spec:
host: ${SERVICE_ROUTER_URL}
@@ -45,6 +45,7 @@ objects:
service: ${SERVICE_NAME}
branch: ${SAFE_BRANCH}
project: ${SAFE_PROJECT}
lagoon/autogenerated: "true"
name: ${SERVICE_NAME}
spec:
host: ${SERVICE_ROUTER_URL}
@@ -45,6 +45,7 @@ objects:
service: ${SERVICE_NAME}
branch: ${SAFE_BRANCH}
project: ${SAFE_PROJECT}
lagoon/autogenerated: "true"
name: ${SERVICE_NAME}
spec:
host: ${SERVICE_ROUTER_URL}
@@ -45,6 +45,7 @@ objects:
service: ${SERVICE_NAME}
branch: ${SAFE_BRANCH}
project: ${SAFE_PROJECT}
lagoon/autogenerated: "true"
name: ${SERVICE_NAME}
spec:
host: ${SERVICE_ROUTER_URL}
@@ -49,6 +49,7 @@ objects:
labels:
branch: ${SAFE_BRANCH}
project: ${SAFE_PROJECT}
lagoon/autogenerated: "false"
name: ${ROUTE_DOMAIN}
spec:
host: ${ROUTE_DOMAIN}
@@ -45,6 +45,7 @@ objects:
service: ${SERVICE_NAME}
branch: ${SAFE_BRANCH}
project: ${SAFE_PROJECT}
lagoon/autogenerated: "true"
name: ${SERVICE_NAME}
spec:
host: ${SERVICE_ROUTER_URL}
@@ -19,4 +19,4 @@ else
-p ROUTE_INSECURE="${ROUTE_INSECURE}" \
-p ROUTE_HSTS="${ROUTE_HSTS}" \
| outputToYaml
fi
fi
@@ -698,6 +698,7 @@ const getOpenShiftInfoForProject = (project: string): Promise<Object> =>
project:projectByName(name: "${project}"){
id
openshift {
name
consoleUrl
token
projectUser
@@ -46,6 +46,7 @@ const messageConsumer = async msg => {
var openshiftConsole = projectOpenShift.openshift.consoleUrl.replace(/\/$/, "");
var openshiftToken = projectOpenShift.openshift.token || ""
var openshiftProject = projectOpenShift.openshiftProjectPattern ? projectOpenShift.openshiftProjectPattern.replace('${branch}',safeBranchName).replace('${project}', safeProjectName) : `${safeProjectName}-${safeBranchName}`
var openshiftName = projectOpenShift.openshift.name
var openshiftProjectUser = projectOpenShift.openshift.projectUser || ""
var deployPrivateKey = projectOpenShift.customer.privateKey
var gitUrl = projectOpenShift.gitUrl
@@ -174,6 +175,10 @@ const messageConsumer = async msg => {
{
"name": "ENVIRONMENT_TYPE",
"value": environmentType
},
{
"name": "OPENSHIFT_NAME",
"value": openshiftName
}
],
"forcePull": true,

0 comments on commit 52bd58c

Please sign in to comment.