Kubernetes Nginx ingress setup for Strapi with x-forwarded headers

If you’re using Strapi and you’re trying to figure out how to setup Nginx Ingress for Kubernetes or you are trying to solve one of the following issues:
https://github.com/strapi/strapi/issues/3462
https://github.com/strapi/strapi/issues/2424

Here’s the ingress configuration, and your nginx ingress helm chart value you should be editing:

#1 Provide use-forwarded-headers in your helm chart’s controller config params

# values.yaml
controller:
  config:
    use-forwarded-headers: "true"

#2 My ingress config

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/proxy-body-size: 200m
    nginx.ingress.kubernetes.io/enable-cors: "true"
    nginx.ingress.kubernetes.io/cors-allow-origin: "*"
    nginx.ingress.kubernetes.io/cors-allow-headers: "*"
    nginx.ingress.kubernetes.io/cors-allow-credentials: "true"
    nginx.ingress.kubernetes.io/cors-allow-methods: "*"
    nginx.ingress.kubernetes.io/proxy-connect-timeout: "30s"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "20s"
    nginx.ingress.kubernetes.io/client-body-buffer-size: "50m"
    kubernetes.io/ingress.class: nginx
  name: strapi-ingress
spec:
  rules:
  - host: mydomain.com
    http:
      paths:
      - path: /
        backend:
          serviceName: angular-ui
          servicePort: 80
      # Depends on the plugins you use
      - path: /(admin|plugins|email|settings-manager|documentation|content-type-builder|upload|users-permissions|users|content-manager|auth)/?.*$
        backend:
          serviceName: strapi
          servicePort: 1337

#3 Custom nginx ingress installation

You might want to create a custom configmap to us within your nginx ingress installation like the following:

apiVersion: v1
data:
  use-forwarded-headers: "true"
kind: ConfigMap
metadata:
  name: nginx-configuration

#4 Digital Ocean k8s

or if you are running your k8s in Digital Ocean you need to add few more config params, but I’d suggest you read this full blog post:

https://www.digitalocean.com/community/questions/how-to-set-up-nginx-ingress-for-load-balancers-with-proxy-protocol-support?answer=50313

#5 Nginx map directive

If you are simply using Nginx as a load balancer, you might want to setup the map directive outside your server block like the solution provided in this comment: https://github.com/strapi/strapi/issues/2424#issuecomment-445964719

CircleCI notifications in RocketChat

There is no official CircleCI integration for RocketChat, therefore this has to be done a little manually.

Below is an example of how I use it.

.circleci/config.yml

version: 2
jobs:
  build-development:
    docker:
      - image: debian:stretch
    steps:
        - checkout
        - run: 
            command: apt-get update && apt-get install -y curl
        - run:
            name: Greeting from hello
            command: echo "Hello, world from hello."
        - run:
            name: Notifiation Failed
            command: bash .circleci/notify "failed"
            when: on_fail
        - run:
            name: Notification Sucess
            command: bash ./circleci/notify "success"
            when: on_success
        
workflows:
  version: 2
  build-deploy:
    jobs:
      - build-development
          filters:
            branches:
              only:
                - develop

Note that on_fail will only execute if one of the above will fail, same with on_success, it only executes if all of the above are successful.

.circleci/notify


#!/bin/bash
set -euo pipefail

payload=$(
cat <<EOM
{
    "status": "$1",
    "job": "$CIRCLE_JOB",
    "build_num": "$CIRCLE_BUILD_NUM",
    "project_reponame": "$CIRCLE_PROJECT_REPONAME",
    "branch": "$CIRCLE_BRANCH",
    "build_url": "$CIRCLE_BUILD_URL",
    "compare_url": "$CIRCLE_COMPARE_URL",
    "sha1": "$CIRCLE_SHA1"
}
EOM
)

curl -X POST -H 'Content-Type: application/json' --data "$payload" https://YOUR-ROCKETCHAT/hooks/INCOMING-WEBHOOK-INTEGRATION-URL

RocketChat Incoming WebHook Integration

class Script {
  
  process_incoming_request({ request }) {
     
    var alertColor = "warning";
    
    let status = request.content.status;
    let job = request.content.job;
    let build_num = request.content.build_num;
    let project_reponame = request.content.project_reponame;
    let branch = request.content.branch;
    let build_url = request.content.build_url;
    let sha1 = request.content.sha1;
      
    if (status == "success") {
    	alertColor = "good";
    } else if (status == "failed") {
    	alertColor = "danger";
    }

    let textMessage = (status == "failed" ? "@all\n" : "");
        
    let title = status == "failed" ? " build failed!" : " was built successfully!"
    
    textMessage = textMessage + "*Build no*: " + build_num + "\n*Project*: " + project_reponame + "\n*Branch*: " + branch + "\n*Commit*: " + sha1

    return {
    	content: {
	    username: "CircleCI",
            attachments: [{
		text: textMessage,
                color: alertColor,
                title: job + title,
                title_link: build_url
            }]
        }
    };

    return {
    	error: {
        	success: false
        }
    };
  }
}

Windows vs. Mac OS X vs. Linux: The Operating System Battle

Windows, Mac OS X, or Linux? That has been the age-old dilemma that is now gaining more and more attention as each operating system is progressing at a record pace. This summary will give you a comprehensive and thorough examination of each operating system, their advantages, disadvantages, and a final summary of which one is better. Please note that all conclusions are self-drawn opinions that are supported by facts. However, it does not guarantee that these thoughts are truths. Continue reading “Windows vs. Mac OS X vs. Linux: The Operating System Battle”

Open source wars: WordPress vs Drupal vs Joomla

Every IT person, developer, and programmer has an opinion when it comes to the various open source content management systems out there. It often comes down to functionality and ease of use, but even then the lines are often blurred and there is rarely a clear-cut victor. WordPress vs Drupal vs Joomla – which is really the king of open source CMS? Continue reading “Open source wars: WordPress vs Drupal vs Joomla”