Before going in depth we need to access the problems that we can possibly face:
All these problems are correlated to one another and together they actually become so big that it becomes hard for organizations to manage.This could cause a large deal of expense in workforce and resource which may not be good for organization.
So what is the Solution?
Enters CICD.
CI/CD stands for Continuous Integration and Continuous Deployment.
CICD involves automating the process of deploying code changes to production environments, which includes running automated tests, deploying to staging environments, and then promoting the changes to production. This automation reduces the time and effort required to deploy code changes, and helps ensure that deployments are consistent and error-free.
It is a set of practices and tools that enable software development teams to deliver code changes more frequently and reliably.
How are we Solving this Problems in our Situation?
Prerequisites
You would need following knowledge to achieve this automation
Tools required for storing Springboot Docker Image on GCP:
Configuring CI/CD for Springboot application using Github actions and Google cloud/Dockerhub
Configuration of build.gradle for jib
plugins {
id 'com.google.cloud.tools.jib' version '3.3.1'
}
jib {
from {
image = 'adoptopenjdk/openjdk11'
}
to {
image = "gcr.io/${System.getenv("PROJECT_ID") ?: "starter-361011"}/starter-server:${scmVersion.version}"
.toString()
}
container {
creationTime = 'USE_CURRENT_TIMESTAMP'
ports = ['50071', '50072']
jvmFlags = [
'-Djava.security.egd=file:/dev/urandom',
'-Dcom.google.cdbg.module=starter-server',
"-Dcom.google.cdbg.version=${scmVersion.version}".toString()
]
mainClass = 'com.example.starterserver.StarterServerApplication'
}
}
NOTE: The image name in “to” section has to be changed according to the container repository is being used.
For example we are using GCP container register,
Hence image name starts by “gcr.io” followed by path of the registry
If we use Dockerhub repository then,
Image name should start by path of the docker repository
to {
image="aniketcodeprism/github-actions:${scmVersion.version}".toString()
}
The format of the image name should be like this:
image=”<path to registery>:<image tag>”
gcloud echo y | gcloud auth configure-docker
./gradelw jib.
You will notice that a image file will be uploaded in your container registry.
Getting service key for GCP
After the jib config next thing we need is to get a service key json file.this json will be used by github actions to authorize the gcp on github platform.You don't need this if you are not planning to use GCP container registry.
Configuration of github actions.
Configuration of github action is very easy.You can refer to some videos if you want to learn about all the specific commands.For now you can use below code to easily create CICD.yml file for you git actions.
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
name: Java CI with Gradle
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Install Protoc
uses: arduino/setup-protoc@v1
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Gradle createVersion
id: version-cv
run: |
version=$(./gradlew cV | grep "version =" | awk '{print $3}')
echo "::set-output name=version::$version"
- name: Gradle createVersion in Starter-api
run: |
cd starter-api/
../gradlew cV
- name: Gradle createVersion in Starter-server
run: |
cd starter-server/
../gradlew cV
- name: Gradle createRelease
id: release-cr
run: |
release=$(./gradlew cR -Prelease.disableSnapshotsCheck | grep "name =" | awk '{print $3}')
echo "::set-output name=release::$release"
# - name: Login to Docker Hub
# uses: docker/login-action@v2
# with:
# username: '${{ secrets.DOCKER_USERNAME }}'
# password: '${{ secrets.DOCKER_TOKEN }}'
- name: "GCloud Login"
id: 'auth'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v1'
- name: "gcloud auth configure-docker"
run: echo y | gcloud auth configure-docker
- name: Build and Push Docker Image
id: docker-build-image
run: ./gradlew jib
All of these commands are very simple .They are just a bunch of gradle and auth commands and their names are self explanatory.If you want to know more about them you can check git actions marketplace.
Now for the IMPORTANT PART
Configuration of the Credentials in GitHub Actions.
Github actions needs some credentials in order to run that yml file.
Some More Information about CI/CD
CICD is also made of two fundamental components:
CI(Continuous Integration):It is the practice of frequently integrating code changes into a shared repository, and then verifying that the code builds and passes automated tests. This helps catch integration errors early and ensures that the codebase is always in a stable state.
CD(Continuous Deployment):It is the practice of automating the deployment of code changes to production environments. This involves using automated testing, staging environments, and deployment pipelines to ensure that code changes are released safely and quickly.
Some Misunderstandings
Now before we move further into this ,I want you to be clear of misunderstanding to make sure you understand what this is and What is this is not.
CI/CD is just about automation: While automation is a key aspect of CI/CD, it is not the only thing that matters. CI/CD is also about creating a culture of collaboration and continuous improvement, where developers, testers, and operations teams work together to deliver high-quality software quickly and reliably.
NO Programming: There is almost no coding required for the automation, however, we do have to write configuration files required for the tasks/jobs.These configs are not in any of the traditional language so it may become tedious task for a new comer.
CI/CD is only for large organizations: While CI/CD can be complex to implement in large organizations, it can also be beneficial for small teams and startups. Even small teams can benefit from the increased efficiency, improved quality, and faster time-to-market that CI/CD can provide.
CI/CD is only for web applications: While CI/CD is often associated with web applications, it can be applied to any type of software development, including desktop applications, mobile apps, and embedded systems.
CI/CD is a silver bullet: While CI/CD can help improve software development and deployment processes, it is not a magic solution that can solve all problems. It requires careful planning, coordination, and continuous improvement to achieve the desired results.
CI/CD eliminates the need for manual testing: While CI/CD can automate many testing tasks, manual testing is still an important part of the software development process. Manual testing can help catch issues that automated tests may miss, and can provide valuable feedback on the user experience and overall quality of the software.
Overall having a CICD in your project is a good thing, but it is not Everything.
Advantages and disadvantages of CICD
CI/CD has several advantages and disadvantages:
Advantages:
Disadvantages:
Share: