Speed up CI builds by introducing dependency caching (#1874)
Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
@@ -105,13 +105,14 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
|
cache: 'gradle'
|
||||||
|
|
||||||
- name: Run Backend Tests
|
- name: Run Backend Tests
|
||||||
id: backend_tests
|
id: backend_tests
|
||||||
working-directory: ./booklore-api
|
working-directory: ./booklore-api
|
||||||
run: |
|
run: |
|
||||||
echo "Running backend tests with testcontainers..."
|
echo "Running backend tests with testcontainers..."
|
||||||
./gradlew test
|
./gradlew test --no-daemon --parallel --build-cache
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
- name: Publish Test Results
|
- name: Publish Test Results
|
||||||
@@ -204,42 +205,36 @@ jobs:
|
|||||||
echo "bump=$bump" >> $GITHUB_ENV
|
echo "bump=$bump" >> $GITHUB_ENV
|
||||||
echo "new_tag=$next_version" >> $GITHUB_ENV
|
echo "new_tag=$next_version" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Generate Image Tag
|
- name: Docker meta
|
||||||
id: set_image_tag
|
id: meta
|
||||||
run: |
|
uses: docker/metadata-action@v5
|
||||||
branch="${GITHUB_REF#refs/heads/}"
|
with:
|
||||||
if [[ "$branch" == "master" ]]; then
|
images: |
|
||||||
image_tag="${{ env.new_tag }}"
|
booklore/booklore
|
||||||
elif [[ "$branch" == "develop" ]]; then
|
ghcr.io/booklore-app/booklore
|
||||||
short_sha=$(git rev-parse --short HEAD)
|
tags: |
|
||||||
image_tag="${{ env.latest_tag }}-develop-${short_sha}"
|
type=sha,enable=${{ github.ref != github.event.repository.default_branch }}
|
||||||
else
|
type=raw,value={{branch}}-{{sha_short}},enable=${{ github.ref_name == 'develop' }}
|
||||||
short_sha=$(git rev-parse --short HEAD)
|
type=raw,value=${{ env.new_tag }},enable=${{ github.ref_name == 'master' }}
|
||||||
image_tag="${short_sha}"
|
type=raw,value=latest,enable=${{ github.ref_name == 'master' }}
|
||||||
fi
|
|
||||||
echo "image_tag=$image_tag" >> $GITHUB_ENV
|
|
||||||
echo "Image tag: $image_tag"
|
|
||||||
|
|
||||||
- name: Build and Push Docker Image
|
- name: Build and push Docker image
|
||||||
run: |
|
uses: docker/build-push-action@v6
|
||||||
docker buildx create --use
|
with:
|
||||||
docker buildx build \
|
context: .
|
||||||
--platform linux/amd64,linux/arm64 \
|
platforms: linux/amd64,linux/arm64
|
||||||
--build-arg APP_VERSION=${{ env.image_tag }} \
|
push: true
|
||||||
--build-arg APP_REVISION=${{ github.sha }} \
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
--tag booklore/booklore:${{ env.image_tag }} \
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
--tag ghcr.io/booklore-app/booklore:${{ env.image_tag }} \
|
build-args: |
|
||||||
--push .
|
APP_VERSION=${{ steps.meta.outputs.version }}
|
||||||
|
APP_REVISION=${{ github.sha }}
|
||||||
- name: Push Latest Tag (Only for Master)
|
cache-from: |
|
||||||
if: github.ref == 'refs/heads/master'
|
type=gha
|
||||||
run: |
|
type=registry,ref=ghcr.io/booklore-app/booklore:buildcache
|
||||||
docker buildx build \
|
cache-to: |
|
||||||
--platform linux/amd64,linux/arm64 \
|
type=gha,mode=max
|
||||||
--build-arg APP_VERSION=${{ env.new_tag }} \
|
type=registry,ref=ghcr.io/booklore-app/booklore:buildcache,mode=max
|
||||||
--tag booklore/booklore:latest \
|
|
||||||
--tag ghcr.io/booklore-app/booklore:latest \
|
|
||||||
--push .
|
|
||||||
|
|
||||||
- name: Update Release Draft (Only for Master)
|
- name: Update Release Draft (Only for Master)
|
||||||
if: github.ref == 'refs/heads/master'
|
if: github.ref == 'refs/heads/master'
|
||||||
|
|||||||
+12
-6
@@ -4,11 +4,10 @@ FROM node:22-alpine AS angular-build
|
|||||||
WORKDIR /angular-app
|
WORKDIR /angular-app
|
||||||
|
|
||||||
COPY ./booklore-ui/package.json ./booklore-ui/package-lock.json ./
|
COPY ./booklore-ui/package.json ./booklore-ui/package-lock.json ./
|
||||||
RUN npm config set registry http://registry.npmjs.org/ \
|
RUN --mount=type=cache,target=/root/.npm \
|
||||||
&& npm config set fetch-retries 5 \
|
npm config set registry http://registry.npmjs.org/ \
|
||||||
&& npm config set fetch-retry-mintimeout 20000 \
|
&& npm ci --force
|
||||||
&& npm config set fetch-retry-maxtimeout 120000 \
|
|
||||||
&& npm install --force
|
|
||||||
COPY ./booklore-ui /angular-app/
|
COPY ./booklore-ui /angular-app/
|
||||||
|
|
||||||
RUN npm run build --configuration=production
|
RUN npm run build --configuration=production
|
||||||
@@ -18,7 +17,13 @@ FROM gradle:8.14.3-jdk21-alpine AS springboot-build
|
|||||||
|
|
||||||
WORKDIR /springboot-app
|
WORKDIR /springboot-app
|
||||||
|
|
||||||
|
# Copy only build files first to cache dependencies
|
||||||
COPY ./booklore-api/build.gradle ./booklore-api/settings.gradle /springboot-app/
|
COPY ./booklore-api/build.gradle ./booklore-api/settings.gradle /springboot-app/
|
||||||
|
|
||||||
|
# Download dependencies (cached layer)
|
||||||
|
RUN --mount=type=cache,target=/home/gradle/.gradle \
|
||||||
|
gradle dependencies --no-daemon
|
||||||
|
|
||||||
COPY ./booklore-api/src /springboot-app/src
|
COPY ./booklore-api/src /springboot-app/src
|
||||||
|
|
||||||
# Inject version into application.yaml using yq
|
# Inject version into application.yaml using yq
|
||||||
@@ -26,7 +31,8 @@ ARG APP_VERSION
|
|||||||
RUN apk add --no-cache yq && \
|
RUN apk add --no-cache yq && \
|
||||||
yq eval '.app.version = strenv(APP_VERSION)' -i /springboot-app/src/main/resources/application.yaml
|
yq eval '.app.version = strenv(APP_VERSION)' -i /springboot-app/src/main/resources/application.yaml
|
||||||
|
|
||||||
RUN gradle clean build -x test
|
RUN --mount=type=cache,target=/home/gradle/.gradle \
|
||||||
|
gradle clean build -x test --no-daemon --parallel
|
||||||
|
|
||||||
# Stage 3: Final image
|
# Stage 3: Final image
|
||||||
FROM eclipse-temurin:21.0.9_10-jre-alpine
|
FROM eclipse-temurin:21.0.9_10-jre-alpine
|
||||||
|
|||||||
Reference in New Issue
Block a user