Skip to content

This is a repo for Docker image creation using Packer and CICD build for docker image using Jenkins on Google Cloud Platform

Notifications You must be signed in to change notification settings

sahanasj/ulta-gcp-docker-image-with-packer

Repository files navigation

GCP Docker/Container Image Management and Hardening through CICD Pipeline

This is a repo for Docker image creation using Packer and CICD build for docker image using Jenkins on Google Cloud Platform

1. Build a Docker base image using Dockerfile

Config-file Description
Dockerfile
To create a Docker agent/base image with OpenJDK, packer package & SSH for Jenkins Slave/agent node configuration
Build-Base-Docker-Image-cmds
Commands to build a Docker agent/base image and push to your Docker hub account for publicly available

2. Manually Build a Ulta Golden Docker image and upload an artifact to Google container registry using Packer Script

Config-file Description
Packer.json
To create/build a Golden Docker base image with ulta's quazi packages
  • Commands to manually build GKE - Golden Docker image using packer

Step 1: Make sure, you have Team Libraries( install-package.sh shell script) and Python packages( python_requirements.txt) are specified under "teams" folder.

Step 2: cat packer.json

Step 3: To validate packer script
$ ./packer validate packer.json

Step 2: To build using packer script
$ ./packer build -var "image_name=<your_image_type>" -var "team_name=<quazi_or_ccp>" -var "project_id=<your_project_id>" -var "gcp_container_reg_name=<name_for_gcp_container_reg>" -var "docker_hub_id=<your_docker_hub_id>" -var "docker_hub_password=<your_docker_hub_password>" packer.json

Example outputs from Packer script

alt text

alt text

alt text

3. Automate CICD pipeline to build a Ulta Golden Docker image using Jenkins:

Config-file Description
Packer.josn
Automate CICD to create/build a Golden Docker base image with ulta's quazi packages
configure-docker-host
On docker host, to expose docker’s TCP port so DockerPlugin can access docker host and create build slave container
  • Step 1: Integrate/Configure Jenkins with Github repo and Google cloud platform.
  • Step 2: Configure Jenkins with required plugins
  • Step 3: Configure Jenkins slave/agent node
  • Step 4: Create a GCP firewall rule for Docker TCP port
  • Setp 5: Create a jenkins job to build process for docker golden image

GCP Firewall Rule to docker’s TCP port:

alt text

  • Command to build GKE - Golden Docker image using automation

$ packer build -var "build_number=$BUILD_NUMBER" -var "job_name=$JOB_NAME" -var "team_name=quazi" packer.json

alt text

4. CICD for creation of Docker image and upload to Google container registry.

Verification on Google Container Registry

alt text

alt text

Multi Team Automated Image Creation Usage:

For Quazi Team:

$ packer build -var "team_name=quazi" -var "build_number=$BUILD_NUMBER" -var "job_name=$JOB_NAME" -var "image_name=<your_image_type>" -var "project_id=<your_project_id>" -var "gcp_container_reg_name=<name_for_gcp_container_reg>" -var "docker_hub_id=<your_docker_hub_id>" -var "docker_hub_password=<your_docker_hub_password>" packer.json

For CCP Team:

$ packer build -var "team_name=ccp" -var "build_number=$BUILD_NUMBER" -var "job_name=$JOB_NAME" -var "image_name=<your_image_type>" -var "project_id=<your_project_id>" -var "gcp_container_reg_name=<name_for_gcp_container_reg>" -var "docker_hub_id=<your_docker_hub_id>" -var "docker_hub_password=<your_docker_hub_password>" packer.json

About

This is a repo for Docker image creation using Packer and CICD build for docker image using Jenkins on Google Cloud Platform

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published