Skip to content

Commit

Permalink
chore: Execute Maven build outside of Docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
guilgaly committed Apr 12, 2023
1 parent b21d29f commit a267157
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
2 changes: 0 additions & 2 deletions .dockerignore

This file was deleted.

11 changes: 4 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@ jobs:
with:
distribution: 'zulu'
java-version: '17'
cache: 'maven'

- name: Cache Maven
uses: actions/cache@v3
with:
path: |
~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
- name: Build Maven
run: mvn --batch-mode clean package

- name: Configure AWS credentials
if: github.ref == 'refs/heads/main'
Expand All @@ -66,7 +63,7 @@ jobs:
docker build \
--tag ${ECR_REGISTRY:-dummy}/$ECR_REPOSITORY:$IMAGE_VERSION \
--file Dockerfile \
.
./target
- name: Docker push
if: github.ref == 'refs/heads/main'
Expand Down
20 changes: 7 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
FROM maven:3-openjdk-17 AS builder
FROM gatlingcorp/openjdk-base:17-jre-headless AS builder

COPY ./pom.xml /build/pom.xml
COPY ./demo-store-*.jar /app/demo-store.jar

WORKDIR /build

RUN mvn --batch-mode dependency:resolve

COPY . /build

RUN mvn --batch-mode clean package

RUN chmod -R g=u /build/target/demo-store-*.jar
# Doing this modifies a lot of files, duplicating the content of /app in two layers: COPY above and RUN below,
# hence the builder image.
RUN chmod -R g=u /app

FROM gatlingcorp/openjdk-base:17-jre-headless
LABEL gatling="demostore"

COPY --from=builder --chown=1001:0 /build/target/demo-store-*.jar /app/demo-store.jar
COPY --from=builder --chown=1001:0 /app /app

WORKDIR /app
ENV HOME=/app
USER 1001

EXPOSE 8080
ENTRYPOINT ["java", "-jar", "./demo-store.jar"]
ENTRYPOINT ["java", "-jar", "/app/demo-store.jar"]
CMD []

0 comments on commit a267157

Please sign in to comment.