Skip to content

build: Enable caching for Docker build layers in CI workflow #342

build: Enable caching for Docker build layers in CI workflow

build: Enable caching for Docker build layers in CI workflow #342

Workflow file for this run

name: Continuous Integration
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
on:
push:
branches:
- main
- feat/k8s
tags:
- production*
- staging*
paths-ignore:
- 'k8s/**'
jobs:
version:
runs-on: ubuntu-latest
steps:
- name: 🛎️ Checkout
uses: actions/checkout@v3
- name: 📦 Cache npm dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
run: |
git fetch
git checkout main
git pull origin main
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
if [[ $GITHUB_REF == refs/tags/production* ]]; then
npm version major
elif [[ $GITHUB_REF == refs/tags/staging* ]]; then
npm version minor
else
npm version patch
fi
git fetch --all
git push origin main
ci:
runs-on: ubuntu-latest
needs: version
steps:
- name: 🛎️ Checkout
uses: actions/checkout@v3
- id: imagename
uses: ASzc/change-string-case-action@v2
with:
string: ${{ github.repository }}
- run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
if [[ $GITHUB_REF == refs/tags/production* ]]; then
npm version major
elif [[ $GITHUB_REF == refs/tags/staging* ]]; then
npm version minor
else
npm version patch
fi
- name: 📝 Get Current Version
id: package-version
uses: martinbeentjes/npm-get-version-action@main
- name: 🔐 Login to Docker Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 🔧 Build and push Docker Image
uses: docker/build-push-action@v4
with:
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
${{ env.REGISTRY }}/${{ steps.imagename.outputs.lowercase }}:${{ steps.package-version.outputs.current-version}}