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"
Standard @socialgouv pipeline using @socialgouv/helm-charts/app for deployment.
This pipeline produces review deployments on branches and production deployment when you merge on master.
include:
- project: SocialGouv/gitlab-ci-yml
file: /autodevops_simple_app.yml
ref: v16.2.0
variables:
PROJECT: "sample-next-app"
PORT: 8080
VALUES_FILE: ./.k8s/app.values.yml # Your values
ENABLE_AZURE_POSTGRES: 1
Customize app.values.yml
with the default helm chart values.yml.
You can also set these in gitlab-ci.yml variables
:
var | usage |
---|---|
ENABLE_AZURE_POSTGRES | enable Azure PG database using azure-db |
TEST_DISABLED | disable test job |
CODE_QUALITY_DISABLED | disable lint job |
NOTIFY_DISABLED | disable GitHub environment notifications |
RANCHER_PROJECT_ID | set Rancher project id based on environment. ex: c-gsm8d:p-pwpk6 |
If you ENABLE_AZURE_POSTGRES
, you need a secret azure-pg-admin-user
in your cluster namespace [app.name]-secret
. this user will create fresh databases and users for features-branches.
All gitlab jobs are overridable. You can or extend them or completely replace them.
All autodevops jobs are using a .autodevops_*
definition you can extend.
include:
- project: SocialGouv/gitlab-ci-yml
file: /autodevops_simple_app.yml
ref: v16.2.0
variables:
PORT: 8080
VALUES_FILE: ./.k8s.app.values.yml
# Same name as the "Build" job defined in the autodevops_simple_app file
# Override https://github.com/SocialGouv/gitlab-ci-yml/blob/v14.0.0/autodevops_simple_app.yml#L50
Build:
extends:
- .autodevops_build
script:
- yarn build
- yarn export
artifacts:
expire_in: 1 day
paths:
- out
# Same name as the "Deploy app (prod)" job defined in the autodevops_simple_app file
# Override https://github.com/SocialGouv/gitlab-ci-yml/blob/v14.0.0/autodevops_simple_app.yml#L137
Deploy app (prod):
extends:
- .autodevops_deploy_app_prod
before_script:
- envsubst < ./.k8s.app.values.prod.yaml > /tmp/values.prod.yaml
variables:
HELM_RENDER_ARGS: >-
--values /tmp/values.prod.yaml
As the gitlab yaml parser is working, defining a job with the same name will replace the last defined one. You can replace any autodevops jobs by naming it :
include:
- project: SocialGouv/gitlab-ci-yml
file: /autodevops_simple_app.yml
ref: v16.2.0
variables:
PORT: 8080
VALUES_FILE: ./.k8s.app.values.yml
# Same name as the "Build" job defined in the autodevops_simple_app file
# Override https://github.com/SocialGouv/gitlab-ci-yml/blob/v14.0.0/autodevops_simple_app.yml#L50
Build:
extends:
- .base_yarn_build_next
dependencies:
- Install
needs:
- Install
variables:
VERSION: ${CI_COMMIT_SHORT_SHA}
MY_API_URL: "%%MY_API_URL%%"
script:
- yarn build
- yarn export
artifacts:
expire_in: 1 day
paths:
- out
include:
- project: SocialGouv/gitlab-ci-yml
file: /base_docker_kubectl_image_stage.yml
ref: v16.2.0
- project: SocialGouv/gitlab-ci-yml
file: /base_create_namespace_stage.yml
ref: v16.2.0
#
Create namespace:
extends: .base_create_namespace_stage
variables:
# The rancher project where the namespaces will be created
RANCHER_PROJECT_ID: <rancher_project_id>
# Optional
REMOTE_URL: "https://github.com/${CI_PROJECT_PATH}.git"
before_script:
- K8S_NAMESPACE=my-namespace
# (re)create to ensure a new namespaces will be created
# - kubectl delete namespaces ${K8S_NAMESPACE} || true
include:
- project: SocialGouv/gitlab-ci-yml
file: /base_delete_useless_k8s_ns_stage.yml
ref: v16.2.0
#
Delete useless k8s namespaces:
extends: .base_delete_useless_k8s_ns_stage
variables:
# Optional
# Filter the namespaces to check for suppression
K8S_NAMESPACE_PREFIX: "${PROJECT}-${CI_PROJECT_ID}-review"
include:
- project: SocialGouv/gitlab-ci-yml
file: /base_docker_helm_image_stage.yml
ref: v16.2.0
- project: SocialGouv/gitlab-ci-yml
file: /base_deploy_app_chart_stage.yml
ref: v16.2.0
#
.deploy_myapp_stage:
dependencies: []
stage: Deploy
extends:
- .base_deploy_app_chart_stage
variables:
CONTEXT: app
VALUES_FILE: ./.k8s/app.values.yml
# optional
HELM_RENDER_ARGS: "--set deployment.port 8080"
#
Deploy myapp (dev):
extends:
- .deploy_myapp_stage
except:
- master
variables:
HOST: ${CI_ENVIRONMENT_SLUG}-${CI_PROJECT_NAME}.${KUBE_INGRESS_BASE_DOMAIN}
environment:
name: ${CI_COMMIT_REF_NAME}-dev
url: https://${CI_ENVIRONMENT_SLUG}-${CI_PROJECT_NAME}.${KUBE_INGRESS_BASE_DOMAIN}
Deploy app (prod):
extends:
- .deploy_myapp_stage
only:
- master
variables:
HOST: ${CI_PROJECT_NAME}.${KUBE_INGRESS_BASE_DOMAIN}
K8S_NAMESPACE: ${CI_PROJECT_NAME}
PRODUCTION: "true"
environment:
name: prod
url: https://${CI_PROJECT_NAME}.${KUBE_INGRESS_BASE_DOMAIN}
include:
- project: SocialGouv/gitlab-ci-yml
file: /base_docker_kubectl_image_stage.yml
ref: v16.2.0
- project: SocialGouv/gitlab-ci-yml
file: /base_docker_helm_image_stage.yml
ref: v16.2.0
#
Helm job:
extends: .base_docker_helm_image_stage
script:
- helm version --client
include:
- project: SocialGouv/gitlab-ci-yml
file: /base_docker_kubectl_image_stage.yml
ref: v16.2.0
#
Kubectl job:
extends: .base_docker_kubectl_image_stage
script:
- kubectl version --client
Send a mattermost notification on pipeline success/failure
You'll need a MATTERMOST_WEBHOOK
variable in your CI.
include:
- project: SocialGouv/gitlab-ci-yml
file: /base_notify_mattermost.yml
ref: v16.2.0
Notify fail:
extends: .base_notify_fail_mattermost
variables:
MATTERMOST_CHANNEL: notifications
Notify success:
extends: .base_notify_success_mattermost
variables:
MATTERMOST_CHANNEL: notifications
This will run the two following scripts for feature-branches deployments :
- yarn run migrate:latest
- yarn run seed:run
include:
- project: SocialGouv/gitlab-ci-yml
file: /base_migrate_azure_db.yml
ref: v16.2.0
include:
- project: SocialGouv/gitlab-ci-yml
file: /base_register_stage.yml
ref: v16.2.0
Register myapp image:
extends: .base_register_stage
variables:
CONTEXT: . # The folder where the Dockerfile is
IMAGE_NAME: $CI_REGISTRY_IMAGE # The image name
# optional
DOCKER_BUILD_ARGS: "--build-arg SENTRY_DSN=https://sentry"
include:
- project: SocialGouv/gitlab-ci-yml
file: /base_semantic_release_stage.yml
ref: v16.2.0
#
Release:
extends: .base_semantic_release_stage
# or
Release:
extends: .base_semantic_release_stage
variables:
SEMANTIC_RELEASE_PLUGINS: "@semantic-release/changelog @semantic-release/git"
A manual job to run a trivy security scan on the main repo docker image.
include:
- project: SocialGouv/gitlab-ci-yml
file: /base_trivy_scan.yml
ref: v16.2.0
Trivy Scan:
extends: .base_trivy_scan