diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 4e1795a..d308e31 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -23,21 +23,9 @@ jobs: # username: ${{ secrets.DOCKERHUB_USERNAME }} # password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Set up Docker Buildx + - name: Set up Docker Build uses: docker/setup-buildx-action@v2 - - name: Setup Java 17 - uses: actions/setup-java@v2 - with: - distribution: temurin - java-version: 17 - - - name: Build with Gradle - uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 - with: - arguments: build - - name: Build docker image (no push) uses: docker/build-push-action@v3 with: diff --git a/.gitignore b/.gitignore index cb2be0d..7b14783 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ build/ .gradle/ .idea/ +.vscode/ /.classpath /.project diff --git a/Dockerfile b/Dockerfile index f7523d9..df12afe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,36 @@ -FROM openjdk:17-alpine -RUN addgroup -S spring && adduser -S spring -G spring -USER spring:spring -ARG JAR_FILE=build/libs/showcase.jar -COPY ${JAR_FILE} app.jar -ENTRYPOINT ["java","-jar","/app.jar"] \ No newline at end of file +FROM eclipse-temurin:17-jdk-jammy AS base + +# Use the base image to build a layer with the gradle wrapper. This means we dont need to +# download the wrapper every time we build the project as the gradle layer is cached by docker +FROM base as gradle + +WORKDIR /app + +COPY gradle/ gradle +COPY gradlew . +COPY settings.gradle . + +RUN ./gradlew tasks + +# Use the gradle layer built above as the basis to build the java project. This layer should only +# get build if the previous layer is build or the files COPYed in are changed +FROM gradle as builder + +WORKDIR /app + +COPY build.gradle . +COPY src/ src + +RUN ./gradlew build + +# Use the base image and copy in the jar file built in the layer above, meaning we get an image built +# using the project source code, but with just the packaged code in it. +FROM base AS runner + +WORKDIR /app + +ARG JAR_FILE=/app/build/libs/showcase.jar + +COPY --from=builder ${JAR_FILE} app.jar + +ENTRYPOINT ["java","-jar","app.jar"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7a04f8d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: '3.1' + +services: + + showcase: + build: + context: . + ports: + - 8080:8080 + - 8000:8000 + environment: + - JAVA_TOOL_OPTIONS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000 \ No newline at end of file