18-June-25
Performance optimization in ci/cd pipeline focus on faster build & test for example using feature like caching, and pararel jobs
Daily Quest #15: Performance Optimization
Performance optimization in ci/cd pipeline focus on faster build & test for example using feature like caching, and pararel jobs
Reference :
- https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/caching-dependencies-to-speed-up-workflows
- https://github.com/docker/build-push-action
Real world usecase : Instead to runingterraform initto re-download all provider, we can usingcachingin.terraform/plugins. An theninitonly check if update available.
Skenario : Using caching for terraform providers, node modules, docker layers and build pararel jobs in github actions for faster pipeline
- Create new workflow
.github/workflows/performance-opt.yml
name: Performance optimization
on:
push:
branches:
- main
jobs:
infra-cache:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Cache terraform providers
uses: actions/cache@v4
with:
path: .terrafrom/plugins
key: ${{ runner.os }}-terraform-${{ hashFiles('**/*.tf') }}
restore-keys: |
${{ runner.os }}-terraform-
- name: Setup terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.7.2
- name: Terraform init & Apply
run: |
terraform init
terraform plan -out=tfplan.out
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: setup buildx
uses: docker/setup-buildx-action@v3
- name: Cache node modules
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Build docker image with layer cache
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile
push: false
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ci-cd-demo:latest
- Result running


Question :
- Bagaimana caching folder
.terraform/pluginsmempercepatterraform init? - Jelaskan cara kerja opsi
cache-fromdancache-todidocker/build-push-action.
Answer :
- Dalam terraform init diperlukan caching agar tidak perlu mendownload depedency kembali ketika menjalankan terraform init. Ini akan mempersingkat waktu berjalanya workflow serta menghemat bandwith unduhan
cache-frommerupakan spesifik tempat dimana cache sebelumnya ditaruh. Dan cache-to adalah tempat dimana export build terbaru cache layer dimana mengizinkan untuk build dan menggunakan kembali cache tersebut.