?? Ultimate Guide to Deployment with GitLab CI/CD ??
Abatan Taiwo
DevOps | DevSecOps | CloudOps | SRE | Linux | AWS | Azure | Docker | Terraform | Kubernetes | Prometheus | Jenkins | Ansible | SonarQube
I'm thrilled to share a detailed GitLab CI/CD pipeline configuration designed for seamless updates. This setup not only ensures continuous delivery but also maintains high availability and zero downtime for applications. Below is a step-by-step guide through the configuration:
Name: Deployment
stages:
- deploy
variables:
DOCKER_HUB_IMAGE: <name>/<name>
before_script:
- echo "--- welcome to app-deployment: ---"
- apt-get update && apt-get install -y jq
app-deployment:
stage: deploy
image: ubuntu:latest
services:
- docker:dind
script:
### Step 1: Checkout Repository
- echo "Checking out repository"
- git clone https://$CI_REPOSITORY_URL .
### Step 2: Generate a Random Version Number
- echo "Creating version number"
- export VERSION_NUMBER=$(shuf -i 1000-9999 -n 1)
- echo "VERSION_NUMBER=${VERSION_NUMBER}"
### Step 3: Build Docker Image
- echo "Building Docker image"
- docker build -t ${DOCKER_HUB_IMAGE}:${VERSION_NUMBER} .
### Step 4: Log into Docker Hub
- echo "Logging into Docker Hub"
- echo "$DOCKER_HUB_ACCESS_TOKEN" | docker login -u "$DOCKER_HUB_USERNAME" --password-stdin
### Step 5: Push Docker Image to Docker Hub
- echo "Pushing Docker image"
- docker push ${DOCKER_HUB_IMAGE}:${VERSION_NUMBER}
### Step 6: Install kubectl
- echo "Installing kubectl"
- curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
- chmod +x ./kubectl
- mv ./kubectl /usr/local/bin/kubectl
### Step 7: Set Up AWS Credentials
- echo "Setting up AWS credentials"
- mkdir -p ~/.aws
- echo "[default]" > ~/.aws/credentials
- echo "aws_access_key_id = $AWS_ACCESS_KEY" >> ~/..aws/credentials
- echo "aws_secret_access_key = $AWS_SECRET_KEY" >> ~/..aws/credentials
### Step 8: Connect to the EKS Cluster
- echo "Connecting to EKS cluster"
- aws eks update-kubeconfig --region us-east-1 --name <name>
### Step 9: Install Helm
- echo "Installing Helm"
- curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
### Step 10: Use Helm to Install/Upgrade Charts
- echo "Using Helm to install charts"
- helm upgrade --install <name> <helm chart path> --set image.tag=${VERSION_NUMBER} --set replicaCount=2
### Step 11: Announce the Latest Version
- echo "Announcing the latest version"
- apt-get update && apt-get install -y ssmtp
- echo "root=$EMAIL" >> /etc/ssmtp/ssmtp.conf
- echo "mailhub=smtp.gmail.com:465" >> /etc/ssmtp/ssmtp.conf
- echo "AuthUser=$EMAIL" >> /etc/ssmtp/ssmtp.conf
- echo "AuthPass=$EMAIL" >> /etc/ssmtp/ssmtp.conf
- echo "UseTLS=YES" >> /etc/ssmtp/ssmtp.conf
- echo "UseSTARTTLS=YES" >> /etc/ssmtp/ssmtp.conf
- echo "New Docker Image Version for Blogging Web App - app-deployment" | ssmtp -v <recipient emails>
only:
- master
Detailed Breakdown:
领英推荐
This CI/CD pipeline is designed to automate and streamline the deployment process, reducing downtime and ensuring efficient updates. Feel free to reach out if you have any questions or need further assistance with your CI/CD pipelines.
#DevOps #CICD #GitLab #Kubernetes #AWS #Docker #Helm #ContinuousDelivery #RollingUpdate