Improve Drone CI with BuildKit, Gradle cache, and traceable image builds
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Enhanced `.drone.yml` to enable Docker BuildKit for efficient builds and added support for Gradle cache persistence across runs. Introduced OCI-compliant image labels for traceability. Updated `.dockerignore` to exclude unnecessary files from Docker context.
This commit is contained in:
8
.dockerignore
Normal file
8
.dockerignore
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
.git
|
||||||
|
.idea
|
||||||
|
.gradle
|
||||||
|
build
|
||||||
|
out
|
||||||
|
**/*.iml
|
||||||
|
node_modules
|
||||||
|
tmp
|
||||||
52
.drone.yml
52
.drone.yml
@ -2,30 +2,45 @@ kind: pipeline
|
|||||||
type: docker
|
type: docker
|
||||||
name: ci
|
name: ci
|
||||||
|
|
||||||
steps:
|
# Enable BuildKit globally (docker plugin will pick this up)
|
||||||
- name: test
|
environment:
|
||||||
image: gradle:8.10.2-jdk21
|
DOCKER_BUILDKIT: 1
|
||||||
commands:
|
|
||||||
- gradle --no-daemon clean test
|
|
||||||
|
|
||||||
- name: build-jar
|
steps:
|
||||||
|
- name: test-and-jar
|
||||||
image: gradle:8.10.2-jdk21
|
image: gradle:8.10.2-jdk21
|
||||||
|
environment:
|
||||||
|
# Put the Gradle cache on a mounted volume
|
||||||
|
GRADLE_USER_HOME: /drone/.gradle
|
||||||
|
volumes:
|
||||||
|
- name: gradle-cache
|
||||||
|
path: /drone/.gradle
|
||||||
commands:
|
commands:
|
||||||
- gradle --no-daemon bootJar
|
- gradle --version
|
||||||
|
# Single invocation -> one dependency resolution, better cache reuse
|
||||||
|
- gradle --no-daemon clean test bootJar
|
||||||
|
|
||||||
- name: build-image
|
- name: build-image
|
||||||
image: plugins/docker
|
image: plugins/docker
|
||||||
settings:
|
settings:
|
||||||
registry: rubble.se:5000
|
registry: rubble.se:5000
|
||||||
repo: rubble.se:5000/hemhub/api
|
repo: rubble.se:5000/hemhub/api
|
||||||
tags:
|
|
||||||
- ${DRONE_BRANCH/\//-}-${DRONE_COMMIT_SHA:0:7}
|
|
||||||
- latest
|
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
username:
|
username:
|
||||||
from_secret: docker_username
|
from_secret: docker_username
|
||||||
password:
|
password:
|
||||||
from_secret: docker_password
|
from_secret: docker_password
|
||||||
|
# Keep your tags as-is
|
||||||
|
tags:
|
||||||
|
- ${DRONE_BRANCH/\//-}-${DRONE_COMMIT_SHA:0:7}
|
||||||
|
- latest
|
||||||
|
# Enable BuildKit and add traceability labels (OCI standard)
|
||||||
|
buildkit: true
|
||||||
|
labels:
|
||||||
|
org.opencontainers.image.source: ${DRONE_GIT_HTTP_URL}
|
||||||
|
org.opencontainers.image.revision: ${DRONE_COMMIT_SHA}
|
||||||
|
org.opencontainers.image.created: ${DRONE_BUILD_FINISHED}
|
||||||
|
org.opencontainers.image.version: ${DRONE_TAG:-${DRONE_COMMIT_SHA:0:7}}
|
||||||
when:
|
when:
|
||||||
branch:
|
branch:
|
||||||
include: [ main, develop ]
|
include: [ main, develop ]
|
||||||
@ -37,13 +52,20 @@ steps:
|
|||||||
settings:
|
settings:
|
||||||
registry: rubble.se:5000
|
registry: rubble.se:5000
|
||||||
repo: rubble.se:5000/hemhub/api
|
repo: rubble.se:5000/hemhub/api
|
||||||
tags:
|
|
||||||
- ${DRONE_TAG}
|
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
username:
|
username:
|
||||||
from_secret: docker_username
|
from_secret: docker_username
|
||||||
password:
|
password:
|
||||||
from_secret: docker_password
|
from_secret: docker_password
|
||||||
|
# Tag builds get a clean semver tag
|
||||||
|
tags:
|
||||||
|
- ${DRONE_TAG}
|
||||||
|
buildkit: true
|
||||||
|
labels:
|
||||||
|
org.opencontainers.image.source: ${DRONE_GIT_HTTP_URL}
|
||||||
|
org.opencontainers.image.revision: ${DRONE_COMMIT_SHA}
|
||||||
|
org.opencontainers.image.created: ${DRONE_BUILD_FINISHED}
|
||||||
|
org.opencontainers.image.version: ${DRONE_TAG}
|
||||||
when:
|
when:
|
||||||
event:
|
event:
|
||||||
include: [ tag ]
|
include: [ tag ]
|
||||||
@ -53,3 +75,9 @@ trigger:
|
|||||||
- push
|
- push
|
||||||
- pull_request
|
- pull_request
|
||||||
- tag
|
- tag
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
# Host (or tmp) volume to persist Gradle cache between builds
|
||||||
|
- name: gradle-cache
|
||||||
|
host:
|
||||||
|
path: /tmp/drone/gradle-cache
|
||||||
|
|||||||
Reference in New Issue
Block a user