Use like this in your .gitlab-ci.yml
:
---
include:
- "https://raw.githubusercontent.com/SocialGouv/gitlab-ci-yml/master/github-deployments.yml"
- "https://raw.githubusercontent.com/SocialGouv/gitlab-ci-yml/master/register-stage.yml"
These jobs sends the feature-branch deployed environment url and status to GitHub API so it appears in the GitHub PR.
Stage | usage |
---|---|
Prepare | get github deployment id |
Send Url to GitHub (feature) | send deployment url |
Env var | example |
---|---|
DEV_ENVIRONMENT_NAME | gitlab environment |
An extend to build and publish some docker image.
extends .base_register_stage
Stage | usage |
---|---|
Registration | register docker image |
Env var | example |
---|---|
IMAGE_NAME | cdtn/api |
CONTEXT | packages/api |
DOCKER_BUILD_ARGS | --build-arg SENTRY_DSN=https://sentry |
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/<version>/base_docker_kubectl_image_stage.yml"
# - "https://raw.githubusercontent.com/SocialGouv/gitlab-ci-yml/<version>/base_create_namespace_stage.yml"
#
Create namespace:
extends: .base_create_namespace_stage
variables:
# The rancher project where the namespaces will be created
RANCHER_PROJECT_ID: <rancher_project_id>
before_script:
- K8S_NAMESPACE=my-namespace
# (re)create to ensure a new namespaces will be created
# - kubectl delete namespaces ${K8S_NAMESPACE} || true
include:
- "https://raw.githubusercontent.com/SocialGouv/gitlab-ci-yml/master/base_deploy_nodejs_chart_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/<version>/base_deploy_nodejs_chart_stage.yml"
# - "https://raw.githubusercontent.com/SocialGouv/gitlab-ci-yml/<version>/base_docker_helm_image_stage.yml"
#
.deploy_myapp_stage: &deploy_myapp_stage
dependencies: []
stage: Deploy
extends: .base_deploy_nodejs_chart_stage
variables:
CONTEXT: app
VALUES_FILE: ./.k8s/app.values.yml
before_script:
- K8S_NAMESPACE=my-namespace
- HOST=myapp.dev.factory.social.gouv.fr
#
- HELM_RENDER_ARGS="
--set image.tag=${IMAGE_TAG}
--set ingress.hosts[0].host=${HOST}
--set ingress.tls[0].hosts[0]=${HOST}"
# In production (if the master branch is your production)
- |
if [[ "${BRANCH_NAME}" = "master" ]]; then
HELM_RENDER_ARGS="
${HELM_RENDER_ARGS}
--set ingress.annotations.\"certmanager\.k8s\.io/cluster-issuer\"="letsencrypt-prod"
--set ingress.annotations.\"kubernetes\.io/tls-acme\"="true"
--set ingress.tls[0].secretName=${PROJECT}-certificate"
fi
#
Deploy myapp (dev):
<<: *deploy_myapp_stage
only:
- branches
except:
- master
environment:
name: $DEV_ENVIRONMENT_NAME
Deploy myapp (prod):
<<: *deploy_myapp_stage
only:
- master
environment:
name: $PROD_ENVIRONMENT_NAME
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/<version>/base_docker_kubectl_image_stage.yml"
# - "https://raw.githubusercontent.com/SocialGouv/gitlab-ci-yml/<version>/base_docker_helm_image_stage.yml"
#
Helm job:
extends: .base_docker_helm_image_stage
script:
- helm version --client-only
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/<version>/base_docker_kubectl_image_stage.yml"
#
Kubectl job:
extends: .base_docker_kubectl_image_stage
script:
- kubectl version --client
include:
- "https://raw.githubusercontent.com/SocialGouv/gitlab-ci-yml/master/base_semantic_release_stage.yml"
# or
# - "https://raw.githubusercontent.com/SocialGouv/gitlab-ci-yml/<version>/base_semantic_release_stage.yml"
#
Release:
extends: .base_semantic_release_stage
# or
Release:
extends: .base_semantic_release_stage
variables:
SEMANTIC_RELEASE_PLUGINS: "@semantic-release/changelog @semantic-release/git"