Skip to content

Commit 396fc20

Browse files
Improve gitlab caching by adding a second cache (#8287)
* Dependency cache and build cache * 16gb memory request * reduce parallelism and memory request * remove "build_again" job
1 parent e379305 commit 396fc20

2 files changed

Lines changed: 33 additions & 22 deletions

File tree

.gitlab-ci.yml

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,34 @@ stages:
2020
variables:
2121
REGISTRY: 486234852809.dkr.ecr.us-east-1.amazonaws.com
2222
BUILD_JOB_NAME: "build"
23+
DEPENDENCY_CACHE_POLICY: pull
24+
BUILD_CACHE_POLICY: pull
25+
GRADLE_VERSION: "8.4" # must match gradle-wrapper.properties
2326

24-
.common: &common
25-
tags: [ "runner:main", "size:large" ]
27+
default:
28+
tags: [ "arch:amd64" ]
2629

2730
.gradle_build: &gradle_build
28-
<<: *common
2931
image: ghcr.io/datadog/dd-trace-java-docker-build:v23.10-base
3032
variables:
3133
GRADLE_OPTS: "-Dorg.gradle.jvmargs='-Xmx2560M -Xms2560M'"
32-
GRADLE_ARGS: " -PskipTests --build-cache --stacktrace --no-daemon --parallel --max-workers=8"
34+
GRADLE_ARGS: " -PskipTests --build-cache --stacktrace --no-daemon --parallel --max-workers=2"
3335
KUBERNETES_CPU_REQUEST: 8
34-
KUBERNETES_MEMORY_REQUEST: 4Gi
35-
cache: &default_cache
36-
key: '$CI_SERVER_VERSION' # Reset the cache every time gitlab is upgraded. ~Every couple months
37-
paths:
38-
- .gradle/wrapper
39-
- .gradle/caches
40-
policy: pull
36+
KUBERNETES_MEMORY_REQUEST: 6Gi
37+
cache:
38+
- key: '$CI_SERVER_VERSION-v2' # Dependencies cache. Reset the cache every time gitlab is upgraded. ~Every couple months
39+
paths:
40+
# Cached dependencies and wrappers for gradle
41+
- .gradle/wrapper
42+
- .gradle/caches
43+
- .gradle/notifications
44+
policy: $DEPENDENCY_CACHE_POLICY
45+
- key: $CI_PIPELINE_ID # Incremental build cache. Shared by all jobs in the pipeline
46+
paths:
47+
- .gradle/caches/$GRADLE_VERSION
48+
- .gradle/$GRADLE_VERSION/executionHistory
49+
- workspace
50+
policy: $BUILD_CACHE_POLICY
4151
before_script:
4252
- export GRADLE_USER_HOME=`pwd`/.gradle
4353
# for weird reasons, gradle will always "chmod 700" the .gradle folder
@@ -49,9 +59,12 @@ variables:
4959
- mv .gradle-copy .gradle
5060
- ls -la
5161

52-
build: &build
53-
<<: *gradle_build
62+
build:
63+
extends: .gradle_build
5464
stage: build
65+
variables:
66+
BUILD_CACHE_POLICY: push
67+
DEPENDENCY_CACHE_POLICY: pull
5568
script:
5669
- ./gradlew clean :dd-java-agent:shadowJar :dd-trace-api:jar :dd-trace-ot:shadowJar $GRADLE_ARGS
5770
- echo UPSTREAM_TRACER_VERSION=$(java -jar workspace/dd-java-agent/build/libs/*.jar) >> upstream.env
@@ -66,16 +79,16 @@ build: &build
6679
reports:
6780
dotenv: build.env
6881

69-
build_with_cache:
70-
<<: *build
82+
build_and_populate_dep_cache:
83+
extends: build
84+
variables:
85+
BUILD_CACHE_POLICY: push
86+
DEPENDENCY_CACHE_POLICY: push
7187
rules:
7288
- if: '$POPULATE_CACHE'
7389
when: on_success
7490
- when: manual
7591
allow_failure: true
76-
cache:
77-
<<: *default_cache
78-
policy: push
7992

8093
deploy_to_profiling_backend:
8194
stage: publish
@@ -149,7 +162,7 @@ deploy_to_di_backend:manual:
149162
UPSTREAM_COMMIT_SHORT_SHA: $CI_COMMIT_SHORT_SHA
150163

151164
deploy_to_sonatype:
152-
<<: *gradle_build
165+
extends: .gradle_build
153166
stage: publish
154167
needs: [ build ]
155168
rules:
@@ -177,7 +190,6 @@ deploy_to_sonatype:
177190
deploy_artifacts_to_github:
178191
stage: publish
179192
image: registry.ddbuild.io/github-cli:v27480869-eafb11d-2.43.0
180-
tags: [ "arch:amd64" ]
181193
rules:
182194
- if: '$POPULATE_CACHE'
183195
when: never
@@ -234,7 +246,6 @@ create_key:
234246
stage: generate-signing-key
235247
when: manual
236248
needs: [ ]
237-
tags: [ "arch:amd64", "size:large" ]
238249
variables:
239250
PROJECT_NAME: "dd-trace-java"
240251
EXPORT_TO_KEYSERVER: "true"

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
33
# Please note that the version specific cache directory in
4-
# .circleci/config.continue.yml.j2 needs to match this version.
4+
# .circleci/config.continue.yml.j2 and .gitlab-ci needs to match this version.
55
distributionSha256Sum=f2b9ed0faf8472cbe469255ae6c86eddb77076c75191741b4a462f33128dd419
66
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
77
networkTimeout=10000

0 commit comments

Comments
 (0)