https://github.com/microdevops-com/gitlab-ci-functions
Reusable CI script functions for Kubernetes, RabbitMQ, PostgreSQL etc
https://github.com/microdevops-com/gitlab-ci-functions
docker git gitlab-ci k8s kubernetes postgresql rabbitmq rancher
Last synced: 3 months ago
JSON representation
Reusable CI script functions for Kubernetes, RabbitMQ, PostgreSQL etc
- Host: GitHub
- URL: https://github.com/microdevops-com/gitlab-ci-functions
- Owner: microdevops-com
- License: gpl-3.0
- Created: 2018-12-22T14:06:47.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2025-06-16T06:08:05.000Z (4 months ago)
- Last Synced: 2025-06-16T07:23:06.658Z (4 months ago)
- Topics: docker, git, gitlab-ci, k8s, kubernetes, postgresql, rabbitmq, rancher
- Language: Shell
- Homepage:
- Size: 183 KB
- Stars: 26
- Watchers: 3
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# About
Functions to create dynamic envs per $CI_COMMIT_REF_SLUG.
- Rancher project namespaces
- RabbitMQ virtual hosts
- Docker Registry parallel logins
- PostgreSQL databasesKubectl, rancher cli, helm calls are parallel job safe.
# Usage
## Add this repo as Git Submodule to a project```
git submodule add --name .gitlab-ci-functions -b master -- https://github.com/sysadmws/gitlab-ci-functions .gitlab-ci-functions
```P.S. You can directly fetch code from https://raw.githubusercontent.com each time pipeline runs, it is a quick way to start, but not a smart way to use permanently.
```
before_script:
- rm -f kubernetes.sh && curl -L -s -o kubernetes.sh https://raw.githubusercontent.com/sysadmws/gitlab-ci-functions/master/kubernetes.sh && . ./kubernetes.sh
- ......
after_script:
- . ./kubernetes.sh
- rancher_logout
- ...
```
## Pipeline
Add the following to `.gitlab-ci.yml` depending on needs:
```
variables:
GIT_SUBMODULE_STRATEGY: normalbefore_script:
- . .gitlab-ci-functions/kubernetes.sh
- . .gitlab-ci-functions/docker.sh
- . .gitlab-ci-functions/rabbitmq.sh
- . .gitlab-ci-functions/postgresql.sh
# this vars are available to script but not available to yml
- KUBE_NAMESPACE=$(kubernetes_namespace_sanitize $RANCHER_PROJECT-$CI_COMMIT_REF_SLUG)
- RABBITMQ_VHOST=$(rabbitmq_vhost_sanitize $RABBITMQ_VHOST_PREFIX-$CI_COMMIT_REF_SLUG)
- registry_login
- rancher_login
- helm_cluster_loginafter_script:
- . .gitlab-ci-functions/kubernetes.sh
- rancher_logout
- helm_cluster_logout...
prepare_rabbitmq_vhost:
stage: prerequisites
script:
- rabbitmq_create_vhost $RABBITMQ_VHOST
- rabbitmq_add_permission $RABBITMQ_VHOST $RABBITMQ_USERprepare_postgresql_db:
stage: prerequisites
script:
- postgresql_create_db $POSTGRESQL_DB_PREFIX-$CI_COMMIT_REF_SLUG
prepare_rancher_namespace:
stage: prerequisites
script:
- rancher_namespace
- namespace_secret_project_registry
- namespace_secret_rabbitmq rabbitmq
- helm_init_namespacemy-app:
stage: app_deploy
script:
- helm_deploy my-app $CI_COMMIT_REF_SLUG
#- helm_deploy my-app $CI_COMMIT_REF_SLUG "--set env=dev"
```
## Envs
Required envs for CI:
```
RANCHER_PROJECT=ProjectRABBITMQ_HOST=rabbitmq.example.com
RABBITMQ_PORT=5672
RABBITMQ_MANAGEMENT_PORT=15672
RABBITMQ_USER=project-user
RABBITMQ_PASS=PASS1
RABBITMQ_MANAGEMENT_USER=project-admin
RABBITMQ_MANAGEMENT_PASS=PASS2
RABBITMQ_VHOST_PREFIX=project
POSTGRESQL_HOST=postgresql.example.com
POSTGRESQL_PORT=5432
POSTGRESQL_USER=project-user
POSTGRESQL_PASS=PASS2
POSTGRESQL_DB_PREFIX=projectKUBE_SERVER=https://rancher.example.com/k8s/clusters/local
KUBE_TOKEN=kubeconfig-u-xxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ADMIN_EMAIL=admin@example.com
```