Gitlab CI - Deploy Docker Helm Charts

Deploy Docker Helm charts to Kubernetes using Gitlab CI. This guide provides a comprehensive example of a Gitlab CI configuration for building and deploying Docker images with Helm.

Gitlab CI Docker Helm Deployment

This example demonstrates a Gitlab CI pipeline for deploying a Dockerized application using Helm to a Kubernetes cluster.

Pipeline Stages

Build Stage

This stage builds the Docker image and pushes it to a registry.

Deploy Stage

This stage deploys the application to Kubernetes using Helm.

Gitlab CI Configuration

image: docker:latest
services:
  - docker:dind

stages:
  - build
  - deploy

variables:
  CONTAINER_IMAGE: anaisurlichs/react-example-app:${CI_COMMIT_SHORT_SHA}

build:
  stage: build
  script:
    - docker login -u ${DOCKER_USER} -p ${DOCKER_PASSWORD}
    - docker build -t ${CONTAINER_IMAGE} .
    - docker tag ${CONTAINER_IMAGE} ${CONTAINER_IMAGE}
    - docker tag ${CONTAINER_IMAGE} anaisurlichs/react-example-app:latest
    - docker push ${CONTAINER_IMAGE}

deploy:
  stage: deploy
  image: dtzar/helm-kubectl
  script:
    - kubectl config set-cluster example-cluster --server="${SERVER}"
    - kubectl config set-cluster example-cluster --embed-certs --certificate-authority=${CERTIFICATE_AUTHORITY_DATA}
    - kubectl config set-credentials gitlab --token="${USER_TOKEN}"
    - kubectl config set-context default --cluster=example-cluster --user=gitlab
    - kubectl config use-context default
    - sed -i "s/<VERSION>/${CI_COMMIT_SHORT_SHA}/g" manifests/deployment.yaml
    - kubectl apply -f manifests/deployment.yaml

Further Considerations

This is a basic example. Consider adding more robust error handling, environment variables for configuration, and integration with other tools for monitoring and logging.

Refer to the Helm documentation and Gitlab CI documentation for more advanced configurations.