Skip to content

Commit 67b3ec6

Browse files
Dependency cache and build cache
1 parent 19da739 commit 67b3ec6

File tree

2 files changed

+41
-19
lines changed

2 files changed

+41
-19
lines changed

.gitlab-ci.yml

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,35 @@ stages:
2020
variables:
2121
REGISTRY: 486234852809.dkr.ecr.us-east-1.amazonaws.com
2222
BUILD_JOB_NAME: "build"
23+
SONATYPE_USERNAME: robot-sonatype-apm-java
24+
DEPENDENCY_CACHE_POLICY: pull
25+
BUILD_CACHE_POLICY: pull
26+
GRADLE_VERSION: "8.4" # must match gradle-wrapper.properties
2327

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

2731
.gradle_build: &gradle_build
28-
<<: *common
2932
image: ghcr.io/datadog/dd-trace-java-docker-build:v23.10-base
3033
variables:
3134
GRADLE_OPTS: "-Dorg.gradle.jvmargs='-Xmx2560M -Xms2560M'"
3235
GRADLE_ARGS: " -PskipTests --build-cache --stacktrace --no-daemon --parallel --max-workers=8"
3336
KUBERNETES_CPU_REQUEST: 8
3437
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
38+
cache:
39+
- key: '$CI_SERVER_VERSION-v2' # Dependencies cache. Reset the cache every time gitlab is upgraded. ~Every couple months
40+
paths:
41+
# Cached dependencies and wrappers for gradle
42+
- .gradle/wrapper
43+
- .gradle/caches
44+
- .gradle/notifications
45+
policy: $DEPENDENCY_CACHE_POLICY
46+
- key: $CI_PIPELINE_ID # Incremental build cache. Shared by all jobs in the pipeline
47+
paths:
48+
- .gradle/caches/$GRADLE_VERSION
49+
- .gradle/$GRADLE_VERSION/executionHistory
50+
- workspace
51+
policy: $BUILD_CACHE_POLICY
4152
before_script:
4253
- export GRADLE_USER_HOME=`pwd`/.gradle
4354
# for weird reasons, gradle will always "chmod 700" the .gradle folder
@@ -49,9 +60,12 @@ variables:
4960
- mv .gradle-copy .gradle
5061
- ls -la
5162

52-
build: &build
53-
<<: *gradle_build
63+
build:
64+
extends: .gradle_build
5465
stage: build
66+
variables:
67+
BUILD_CACHE_POLICY: push
68+
DEPENDENCY_CACHE_POLICY: pull
5569
script:
5670
- ./gradlew clean :dd-java-agent:shadowJar :dd-trace-api:jar :dd-trace-ot:shadowJar $GRADLE_ARGS
5771
- echo UPSTREAM_TRACER_VERSION=$(java -jar workspace/dd-java-agent/build/libs/*.jar) >> upstream.env
@@ -66,16 +80,26 @@ build: &build
6680
reports:
6781
dotenv: build.env
6882

83+
build_again:
84+
extends: .gradle_build
85+
stage: build
86+
needs: [ build ]
87+
script:
88+
- ls -la .gradle
89+
- ls -la .gradle/$GRADLE_VERSION
90+
- ls -laR workspace/
91+
- ./gradlew :dd-java-agent:shadowJar :dd-trace-api:jar :dd-trace-ot:shadowJar $GRADLE_ARGS
92+
6993
build_with_cache:
70-
<<: *build
94+
extends: build
95+
variables:
96+
BUILD_CACHE_POLICY: push
97+
DEPENDENCY_CACHE_POLICY: push
7198
rules:
7299
- if: '$POPULATE_CACHE'
73100
when: on_success
74101
- when: manual
75102
allow_failure: true
76-
cache:
77-
<<: *default_cache
78-
policy: push
79103

80104
deploy_to_profiling_backend:
81105
stage: publish
@@ -149,7 +173,7 @@ deploy_to_di_backend:manual:
149173
UPSTREAM_COMMIT_SHORT_SHA: $CI_COMMIT_SHORT_SHA
150174

151175
deploy_to_sonatype:
152-
<<: *gradle_build
176+
extends: .gradle_build
153177
stage: publish
154178
needs: [ build ]
155179
rules:
@@ -177,7 +201,6 @@ deploy_to_sonatype:
177201
deploy_artifacts_to_github:
178202
stage: publish
179203
image: registry.ddbuild.io/github-cli:v27480869-eafb11d-2.43.0
180-
tags: [ "arch:amd64" ]
181204
rules:
182205
- if: '$POPULATE_CACHE'
183206
when: never
@@ -234,7 +257,6 @@ create_key:
234257
stage: generate-signing-key
235258
when: manual
236259
needs: [ ]
237-
tags: [ "arch:amd64", "size:large" ]
238260
variables:
239261
PROJECT_NAME: "dd-trace-java"
240262
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)