From 726023cb8be5e3057ee6e330da3ec9cdabe11691 Mon Sep 17 00:00:00 2001 From: Douglas Duteil Date: Wed, 20 Nov 2019 16:48:54 +0100 Subject: [PATCH] feat(namespace): add create namespace stage --- README.md | 62 ++++++++++++++++++++++++++++- base_create_namespace_stage.yml | 25 ++++++++++++ base_docker_helm_image_stage.yml | 5 +++ base_docker_kubectl_image_stage.yml | 4 ++ 4 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 base_create_namespace_stage.yml create mode 100644 base_docker_helm_image_stage.yml create mode 100644 base_docker_kubectl_image_stage.yml diff --git a/README.md b/README.md index bedb0884..b4555f0e 100644 --- a/README.md +++ b/README.md @@ -54,13 +54,71 @@ An extend to build and publish some docker image. | CONTEXT | packages/api | | DOCKER_BUILD_ARGS | --build-arg SENTRY_DSN=https://sentry | -# [.base_semantic_release_stage](./base_semantic_release_stage.yml) +# [.base_create_namespace_stage](./base_create_namespace_stage.yml) ## Usage ```yaml +include: + - "https://raw.githubusercontent.com/SocialGouv/gitlab-ci-yml/master/base_docker_kubectl_image_stage.yml" + - "https://raw.githubusercontent.com/SocialGouv/gitlab-ci-yml/master/base_create_namespace_stage.yml" + # or + # - "https://raw.githubusercontent.com/SocialGouv/gitlab-ci-yml//base_docker_kubectl_image_stage.yml" + # - "https://raw.githubusercontent.com/SocialGouv/gitlab-ci-yml//base_create_namespace_stage.yml" ---- +# + +Create namespace: + extends: .base_create_namespace_stage + environment: factory-dev + script: + - echo "Namespace "${K8S_NAMESPACE}" created" + +``` + +# [.base_docker_helm_image_stage](./base_docker_helm_image_stage.yml) + +## Usage + +```yaml +include: + - "https://raw.githubusercontent.com/SocialGouv/gitlab-ci-yml/master/base_docker_kubectl_image_stage.yml" + - "https://raw.githubusercontent.com/SocialGouv/gitlab-ci-yml/master/base_docker_helm_image_stage.yml" + # or + # - "https://raw.githubusercontent.com/SocialGouv/gitlab-ci-yml//base_docker_kubectl_image_stage.yml" + # - "https://raw.githubusercontent.com/SocialGouv/gitlab-ci-yml//base_docker_helm_image_stage.yml" + +# + +Helm job: + extends: .base_docker_helm_image_stage + script: + - helm version --client-only +``` + +# [.base_docker_kubectl_image_stage](./base_docker_kubectl_image_stage.yml) + +## Usage + +```yaml +include: + - "https://raw.githubusercontent.com/SocialGouv/gitlab-ci-yml/master/base_docker_kubectl_image_stage.yml" + # or + # - "https://raw.githubusercontent.com/SocialGouv/gitlab-ci-yml//base_docker_kubectl_image_stage.yml" + +# + +Kubectl job: + extends: .base_docker_kubectl_image_stage + script: + - kubectl version --client +``` + +# [.base_semantic_release_stage](./base_semantic_release_stage.yml) + +## Usage + +```yaml include: - "https://raw.githubusercontent.com/SocialGouv/gitlab-ci-yml/master/base_sementic_release_stage.yml" # or diff --git a/base_create_namespace_stage.yml b/base_create_namespace_stage.yml new file mode 100644 index 00000000..c1c99677 --- /dev/null +++ b/base_create_namespace_stage.yml @@ -0,0 +1,25 @@ +# + +.base_create_namespace_stage: &base_create_namespace_stage + extends: .base_docker_kube_image_stage + stage: "Registration" + environment: + name: $DEV_ENVIRONMENT_NAME + script: + - echo "Namespace "${K8S_NAMESPACE}" created" + dependencies: [] + before_script: + - *resolve_env_domain + # Skip the job if the namespace exists + - "[[ $(kubectl get namespace ${K8S_NAMESPACE}) ]] && exit ${CI_JOB_SKIP_EXIT_CODE:-0}" + # Or (re)create to ensure new quota are applied + # - kubectl delete namespaces ${K8S_NAMESPACE} || true + # + - kubectl create namespace ${K8S_NAMESPACE} + - kubectl annotate namespace ${K8S_NAMESPACE} field.cattle.io/projectId=${RANCHER_PROJECT_ID} + # + # Fake rancher namespace creation + - kubectl annotate namespace ${K8S_NAMESPACE} field.cattle.io/containerDefaultResourceLimit='{}' + - kubectl annotate namespace ${K8S_NAMESPACE} field.cattle.io/creatorId=gitlab + # Link the namespace to a git branch + - kubectl annotate namespace ${K8S_NAMESPACE} git/branch=${CI_COMMIT_REF_NAME} diff --git a/base_docker_helm_image_stage.yml b/base_docker_helm_image_stage.yml new file mode 100644 index 00000000..a8cfa06e --- /dev/null +++ b/base_docker_helm_image_stage.yml @@ -0,0 +1,5 @@ +# + +.base_docker_helm_image_stage: + extends: .base_docker_kube_image_stage + image: registry.gitlab.factory.social.gouv.fr/socialgouv/docker/helm:0.13.0 diff --git a/base_docker_kubectl_image_stage.yml b/base_docker_kubectl_image_stage.yml new file mode 100644 index 00000000..676df1e9 --- /dev/null +++ b/base_docker_kubectl_image_stage.yml @@ -0,0 +1,4 @@ +# + +.base_docker_kubectl_image_stage: + image: registry.gitlab.factory.social.gouv.fr/socialgouv/docker/kubectl:0.13.0