Skip to content

Commit febe0db

Browse files
committed
build(gradle): bump gradle version
1 parent 872ce9f commit febe0db

File tree

3 files changed

+56
-27
lines changed

3 files changed

+56
-27
lines changed

.github/workflows/pipeline.yml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ jobs:
162162
docker-build-scan-push:
163163
# if: github.ref == 'refs/heads/main'
164164
runs-on: ubuntu-latest
165+
env:
166+
BASE_IMAGE: abhisheksr01/companieshouse
165167
# needs:
166168
# - unit-test
167169
# - mutation-test
@@ -189,19 +191,19 @@ jobs:
189191
# echo "is-version-bumped: ${{ steps.bump-version.outputs.is-version-bumped }}"
190192
# echo "is-dryrun-version-bumped: ${{ steps.bump-version.outputs.is-dryrun-version-bumped }}"
191193
# shell: bash
192-
# - name: Login to Docker Hub
193-
# uses: docker/login-action@v3
194-
# with:
195-
# username: ${{ vars.DOCKERHUB_USERNAME }}
196-
# password: ${{ secrets.DOCKERHUB_TOKEN }}
194+
- name: Login to Docker Hub
195+
uses: docker/login-action@v3
196+
with:
197+
username: ${{ vars.DOCKERHUB_USERNAME }}
198+
password: ${{ secrets.DOCKERHUB_TOKEN }}
197199
- name: Set up Docker Buildx
198200
uses: docker/setup-buildx-action@v3
199201
- name: Docker meta
200202
# if: ${{ steps.bump-version.outputs.is-dryrun-version-bumped == 'true' }}
201203
id: meta
202204
uses: docker/metadata-action@v5
203205
with:
204-
images: abhisheksr01/companieshouse
206+
images: ${{ env.BASE_IMAGE }}
205207
context: git
206208
tags: |
207209
type=ref,event=pr
@@ -222,27 +224,24 @@ jobs:
222224
load: true
223225
tags: ${{ steps.meta.outputs.tags }}
224226
labels: ${{ steps.meta.outputs.labels }}
225-
- name: Convert Image to Tar
226-
run: |
227-
docker images
228-
tags="${{ steps.meta.outputs.tags }}"
229-
tags="${tags//,/ }" # replace commas with spaces
230-
echo "Saving images: $tags"
231227
- name: Scan Image
232228
uses: aquasecurity/[email protected]
233229
with:
230+
versin: 0.66
234231
image-ref: ${{ steps.meta.outputs.tags }}
235232
format: 'table'
236233
exit-code: '1'
237234
ignore-unfixed: true
238235
vuln-type: 'os,library'
239-
scanners: 'vuln,secret,misconfig,license'
236+
scanners: 'vuln,secret,misconfig'
240237
- name: Re-Build & Push Image
241238
uses: docker/build-push-action@v6
242239
with:
243240
push: true
244241
tags: ${{ steps.meta.outputs.tags }}
245242
labels: ${{ steps.meta.outputs.labels }}
243+
cache-to: type=registry,ref=${{ env.BASE_IMAGE }}:cache
244+
cache-from: type=registry,ref=${{ env.BASE_IMAGE }}:cache,mode=max
246245
sbom: true
247246
provenance: true
248247

Dockerfile

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,55 @@
11
# Stage 1: Build the jar
2-
FROM gradle:8.12-jdk21 AS build
3-
# Copy source code into the container and set the ownership to 'gradle' user
2+
FROM gradle:8.14.3-jdk21-jammy AS build
3+
4+
# Update system packages
5+
RUN apt-get update && \
6+
apt-get upgrade -y && \
7+
apt-get clean && \
8+
rm -rf /var/lib/apt/lists/*
9+
10+
# Copy source code and build
411
COPY --chown=gradle:gradle . /home/gradle/src
512
WORKDIR /home/gradle/src
613
RUN gradle build -x test --no-daemon
714

815
# Stage 2: Production image
9-
FROM openjdk:21-slim AS production
16+
FROM openjdk:21-slim-bookworm AS production
1017
EXPOSE 8080
1118

12-
# Create a non-root user and group (using 'appuser' as an example)
13-
RUN groupadd -r appgroup && useradd -r -g appgroup -m appuser
19+
# Update system packages and install fixed versions
20+
RUN apt-get update && \
21+
apt-get upgrade -y && \
22+
apt-get install -y --no-install-recommends \
23+
libc6 \
24+
util-linux \
25+
&& apt-get clean && \
26+
rm -rf /var/lib/apt/lists/*
27+
28+
# Create non-root user with fixed UID/GID
29+
RUN groupadd -r appgroup -g 10001 && \
30+
useradd -r -g appgroup -u 10001 appuser && \
31+
mkdir /app && \
32+
chown 10001:10001 /app
33+
34+
# Copy jar with specific name
35+
COPY --from=build --chown=10001:10001 /home/gradle/src/build/libs/*.jar /app/companieshouse.jar
1436

15-
# Create the /app directory and set permissions
16-
RUN mkdir /app && chown appuser:appgroup /app
37+
WORKDIR /app
38+
USER 10001
1739

18-
# Copy the jar file from the build stage into the production image
19-
COPY --from=build /home/gradle/src/build/libs/*.jar /app/companieshouse-*.jar
40+
# Security-focused Java options
41+
ENV JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom \
42+
-Djava.awt.headless=true \
43+
-Dfile.encoding=UTF-8 \
44+
-XX:+ExitOnOutOfMemoryError \
45+
-XX:+UseContainerSupport \
46+
-XX:MaxRAMPercentage=75.0 \
47+
-Dspring.profiles.active=production \
48+
-Dserver.tomcat.accesslog.enabled=true"
2049

21-
# Change to non-root user
22-
USER appuser
50+
# Add healthcheck
51+
HEALTHCHECK --interval=30s --timeout=3s \
52+
CMD curl -f http://localhost:8080/companieshouse/actuator/health || exit 1
2353

24-
# Set the entrypoint to run the Java application
25-
ENTRYPOINT ["java", "-jar", "/app/companieshouse-*.jar"]
54+
# Use specific jar name in entrypoint
55+
ENTRYPOINT ["java", "-jar", "/app/companieshouse.jar"]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)