Git Product home page Git Product logo

gitlab-ci-yml's Introduction

.gitlab-ci.yml

✨✨✨✨✨✨✨✨

License: Apache-2.0 GitHub release (latest SemVer) Gitlab Pipeline Status





Usage

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.

Usage

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.

Override existing jobs

All gitlab jobs are overridable. You can or extend them or completely replace them.

Extends existing job

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

Replace existing job

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

Usage

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

Usage

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"

Usage

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}

Usage

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

Usage

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.

Usage

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

Usage

include:
  - project: SocialGouv/gitlab-ci-yml
    file: /base_migrate_azure_db.yml
    ref: v16.2.0

Usage

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"

Usage

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.

Usage

include:
  - project: SocialGouv/gitlab-ci-yml
    file: /base_trivy_scan.yml
    ref: v16.2.0

Trivy Scan:
  extends: .base_trivy_scan

gitlab-ci-yml's People

Contributors

renovate[bot] avatar douglasduteil avatar socialgroovybot avatar virasack avatar jebay avatar tglatt avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.