Kubernetes RabbitMQ operator https://github.com/tekliner/rabbitmq-operator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Jenkinsfile 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. node {
  2. checkout scm
  3. def branch = env.BRANCH_NAME.toLowerCase()
  4. def registry = "716309063777.dkr.ecr.us-east-1.amazonaws.com"
  5. def build = env.BUILD_NUMBER
  6. def image
  7. stage("Build image") {
  8. sh 'docker build -t rabbitmq-operator .'
  9. image = docker.image("rabbitmq-operator")
  10. }
  11. stage("Push image") {
  12. docker.withRegistry("https://"+registry+"/", 'ecr:us-east-1:3c5c323b-afed-4bf0-ae1a-3b19d1c904fe') {
  13. image.push("${branch}-${build}")
  14. }
  15. }
  16. // check branch and select cluster to deploy
  17. if (branch == 'master') {
  18. stage ('Wait for confirmation of build promotion') {
  19. input message: 'Is this build ready for production?', submitter: 'tekliner'
  20. }
  21. stage ('Deploy to production') {
  22. writeFile file: 'operator.yaml', text: """
  23. ---
  24. apiVersion: apps/v1beta1
  25. kind: Deployment
  26. metadata:
  27. name: rabbitmq-operator
  28. spec:
  29. replicas: 1
  30. selector:
  31. matchLabels:
  32. app: rabbitmq-operator
  33. template:
  34. metadata:
  35. labels:
  36. app: rabbitmq-operator
  37. spec:
  38. serviceAccountName: rabbitmq-operator
  39. containers:
  40. - name: rabbitmq-operator
  41. image: 716309063777.dkr.ecr.us-east-1.amazonaws.com/rabbitmq-operator:${branch}-${build}
  42. command:
  43. - rabbitmq-operator
  44. imagePullPolicy: Always
  45. env:
  46. - name: POD_NAME
  47. valueFrom:
  48. fieldRef:
  49. fieldPath: metadata.name
  50. - name: OPERATOR_NAME
  51. value: "rabbitmq-operator"
  52. - name: WATCH_NAMESPACE
  53. value: ""
  54. """
  55. archiveArtifacts: 'operator.yaml'
  56. sh "kubectl apply -f operator.yaml -n messaging"
  57. sh "kubectl apply -f deploy/deploy-operator-default/clusterrole.yaml"
  58. }
  59. } else {
  60. // deploy PR to sandbox
  61. stage ('Deploy to sandbox') {
  62. writeFile file: 'operator.yaml', text: """
  63. ---
  64. apiVersion: apps/v1beta1
  65. kind: Deployment
  66. metadata:
  67. name: rabbitmq-operator
  68. spec:
  69. replicas: 1
  70. selector:
  71. matchLabels:
  72. app: rabbitmq-operator
  73. template:
  74. metadata:
  75. labels:
  76. app: rabbitmq-operator
  77. spec:
  78. serviceAccountName: rabbitmq-operator
  79. containers:
  80. - name: rabbitmq-operator
  81. image: 716309063777.dkr.ecr.us-east-1.amazonaws.com/rabbitmq-operator:${branch}-${build}
  82. command:
  83. - rabbitmq-operator
  84. imagePullPolicy: Always
  85. env:
  86. - name: POD_NAME
  87. valueFrom:
  88. fieldRef:
  89. fieldPath: metadata.name
  90. - name: OPERATOR_NAME
  91. value: "rabbitmq-operator"
  92. - name: WATCH_NAMESPACE
  93. value: "rabbitmq-operator-${branch}"
  94. """
  95. archiveArtifacts: 'operator.yaml'
  96. // create separated namespace and deploy operator into it
  97. sh "HOME=/root;KUBECONFIG=/root/.kube/sandbox.config kubectl create ns rabbitmq-operator-${branch} || true"
  98. sh "HOME=/root;KUBECONFIG=/root/.kube/sandbox.config kubectl apply -f deploy/deploy-operator-default/service_account.yaml -n rabbitmq-operator-${branch} || true"
  99. sh "HOME=/root;KUBECONFIG=/root/.kube/sandbox.config kubectl apply -f deploy/deploy-operator-default/role_binding.yaml -n rabbitmq-operator-${branch} || true"
  100. sh "HOME=/root;KUBECONFIG=/root/.kube/sandbox.config kubectl apply -f deploy/deploy-operator-default/role.yaml -n rabbitmq-operator-${branch} || true"
  101. sh "HOME=/root;KUBECONFIG=/root/.kube/sandbox.config kubectl apply -f deploy/deploy-operator-default/clusterrole.yaml -n rabbitmq-operator-${branch} || true"
  102. sh "HOME=/root;KUBECONFIG=/root/.kube/sandbox.config kubectl apply -f deploy/deploy-operator-default/clusterrolebinding.yaml -n rabbitmq-operator-${branch} || true"
  103. sh "HOME=/root;KUBECONFIG=/root/.kube/sandbox.config kubectl apply -f operator.yaml -n rabbitmq-operator-${branch} || true"
  104. }
  105. }
  106. }