Skip to content

Commit

Permalink
Refactored dockerfiles into one file
Browse files Browse the repository at this point in the history
  • Loading branch information
sschnabe committed Dec 5, 2023
1 parent 029730e commit 8efa76f
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 174 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,11 @@ jobs:

dockerfile:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
context: [base, temurin, temurin-import, distroless, distroless-import]
steps:
- uses: actions/checkout@v4
- uses: hadolint/[email protected]
with:
dockerfile: src/main/docker/${{ matrix.context }}/Dockerfile
dockerfile: src/main/docker/Dockerfile

verify:
runs-on: ubuntu-latest
Expand Down
44 changes: 14 additions & 30 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@
<artifactId>keycloak-quarkus-dist</artifactId>
<version>${version.org.keycloak}</version>
<type>tar.gz</type>
<outputDirectory>${project.build.directory}/docker/base</outputDirectory>
<outputDirectory>${project.build.directory}/docker</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>io.kokuwa.keycloak</groupId>
<artifactId>keycloak-event-metrics</artifactId>
<version>${version.io.kokuwa.keycloak.metrics}</version>
<outputDirectory>${project.build.directory}/docker/temurin</outputDirectory>
<outputDirectory>${project.build.directory}/docker</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
Expand Down Expand Up @@ -246,21 +246,6 @@
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>docker-base</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>build</argument>
<argument>--tag</argument>
<argument>${image.name}:${image.tag}-base</argument>
<argument>base</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>docker-temurin</id>
<phase>package</phase>
Expand All @@ -270,9 +255,9 @@
<configuration>
<arguments>
<argument>build</argument>
<argument>--tag</argument>
<argument>${image.name}:${image.tag}-temurin</argument>
<argument>temurin</argument>
<argument>${project.build.directory}/docker</argument>
<argument>--tag=${image.name}:${image.tag}-temurin</argument>
<argument>--target=temurin</argument>
</arguments>
</configuration>
</execution>
Expand All @@ -285,9 +270,9 @@
<configuration>
<arguments>
<argument>build</argument>
<argument>--tag</argument>
<argument>${image.name}:${image.tag}-temurin-import</argument>
<argument>temurin-import</argument>
<argument>${project.build.directory}/docker</argument>
<argument>--tag=${image.name}:${image.tag}-temurin-import</argument>
<argument>--target=temurin-import</argument>
</arguments>
</configuration>
</execution>
Expand All @@ -300,9 +285,9 @@
<configuration>
<arguments>
<argument>build</argument>
<argument>--tag</argument>
<argument>${image.name}:${image.tag}-distroless</argument>
<argument>distroless</argument>
<argument>${project.build.directory}/docker</argument>
<argument>--tag=${image.name}:${image.tag}-distroless</argument>
<argument>--target=distroless</argument>
</arguments>
</configuration>
</execution>
Expand All @@ -315,16 +300,15 @@
<configuration>
<arguments>
<argument>build</argument>
<argument>--tag</argument>
<argument>${image.name}:${image.tag}-distroless-import</argument>
<argument>distroless-import</argument>
<argument>${project.build.directory}/docker</argument>
<argument>--tag=${image.name}:${image.tag}-distroless-import</argument>
<argument>--target=distroless-import</argument>
</arguments>
</configuration>
</execution>
</executions>
<configuration>
<executable>docker</executable>
<workingDirectory>${project.build.directory}/docker</workingDirectory>
</configuration>
</plugin>

Expand Down
164 changes: 164 additions & 0 deletions src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
FROM docker.io/library/debian:stable-slim AS keycloak
ARG VERSION=${version.org.keycloak}
ADD keycloak-quarkus-dist-$VERSION.tar.gz /tmp
RUN mv "/tmp/keycloak-${version.org.keycloak}" /app && rm -rf /app/bin/client /app/bin/*.bat

Check failure on line 4 in src/main/docker/Dockerfile

View workflow job for this annotation

GitHub Actions / dockerfile

SC2154 warning: version is referenced but not assigned (did you mean 'VERSION'?).

FROM docker.io/eclipse-temurin:${maven.compiler.target}-jre AS keycloak-runtime
# https://www.keycloak.org/server/all-config
ENV \
KC_DB=postgres \
KC_CACHE=ispn \
KC_CACHE_STACK=kubernetes \
KC_CACHE_DNS=keycloak-headless \
KC_CACHE_OWNERS=2 \
KC_HEALTH_ENABLED=true \
KC_METRICS_ENABLED=true \
KC_METRICS_EVENT_REPLACE_IDS=true \
KC_METRICS_STATS_ENABLED=true \
URI_METRICS_ENABLED=false \
URI_METRICS_DETAILED=false \
KC_PROXY=edge \
KC_LOG_CONSOLE_OUTPUT=json
COPY --from=keycloak /app /app
COPY cache-ispn.xml /app/conf/cache-ispn.xml
COPY keycloak-event-metrics-${version.io.kokuwa.keycloak.metrics}.jar /app/providers/metrics-spi.jar
RUN java -Dkc.home.dir=/app -jar /app/lib/quarkus-run.jar build

FROM docker.io/eclipse-temurin:${maven.compiler.target}-jre AS keycloak-import
ENV KC_DB=postgres KC_CACHE=local KC_LOG_CONSOLE_OUTPUT=json
COPY --from=keycloak /app /app
RUN java -Dkc.home.dir=/app -jar /app/lib/quarkus-run.jar build

###
### Temurin
###

FROM docker.io/eclipse-temurin:${maven.compiler.target}-jre AS temurin

# https://github.com/opencontainers/image-spec/blob/main/annotations.md
LABEL org.opencontainers.image.title ${project.name}
LABEL org.opencontainers.image.description ${project.description}
LABEL org.opencontainers.image.url ${project.url}
LABEL org.opencontainers.image.source ${project.url}/src/main/docker/Dockerfile
LABEL org.opencontainers.image.vendor ${project.organization.name}
LABEL org.opencontainers.image.authors https://github.com/orgs/kokuwaio/people
LABEL org.opencontainers.image.licenses Apache-2.0
LABEL org.opencontainers.image.version ${version.org.keycloak}
LABEL org.opencontainers.image.created ${git.build.time}
LABEL org.opencontainers.image.revision ${git.commit.id}
LABEL org.opencontainers.image.ref.name ${image.tag}-temurin
LABEL org.opencontainers.image.base.name docker.io/eclipse-temurin:${maven.compiler.target}-jre

# https://www.keycloak.org/server/all-config
ENV \
KC_DB=postgres \
KC_CACHE=ispn \
KC_CACHE_STACK=kubernetes \
KC_CACHE_DNS=keycloak-headless \
KC_CACHE_OWNERS=2 \
KC_HEALTH_ENABLED=true \
KC_METRICS_ENABLED=true \
KC_METRICS_EVENT_REPLACE_IDS=true \
KC_METRICS_STATS_ENABLED=true \
URI_METRICS_ENABLED=false \
URI_METRICS_DETAILED=false \
KC_PROXY=edge \
KC_LOG_CONSOLE_OUTPUT=json

COPY --from=keycloak-runtime /app /app
ENTRYPOINT ["java", "-XX:+ExitOnOutOfMemoryError", "-Dkc.home.dir=/app", "-Djgroups.dns.query=${KC_CACHE_DNS}", "-jar", "/app/lib/quarkus-run.jar"]
CMD ["start", "--optimized"]

###
### Temurin Import
###

FROM docker.io/eclipse-temurin:${maven.compiler.target}-jre AS temurin-import

# https://github.com/opencontainers/image-spec/blob/main/annotations.md
LABEL org.opencontainers.image.title ${project.name}
LABEL org.opencontainers.image.description ${project.description}
LABEL org.opencontainers.image.url ${project.url}
LABEL org.opencontainers.image.source ${project.url}/src/main/docker/Dockerfile
LABEL org.opencontainers.image.vendor ${project.organization.name}
LABEL org.opencontainers.image.authors https://github.com/orgs/kokuwaio/people
LABEL org.opencontainers.image.licenses Apache-2.0
LABEL org.opencontainers.image.version ${version.org.keycloak}
LABEL org.opencontainers.image.created ${git.build.time}
LABEL org.opencontainers.image.revision ${git.commit.id}
LABEL org.opencontainers.image.ref.name ${image.tag}-temurin-import
LABEL org.opencontainers.image.base.name docker.io/eclipse-temurin:${maven.compiler.target}-jre

# https://www.keycloak.org/server/all-config
ENV KC_DB=postgres KC_CACHE=local KC_LOG_CONSOLE_OUTPUT=json

COPY --from=keycloak-import /app /app
ENTRYPOINT ["java", "-XX:+ExitOnOutOfMemoryError", "-Dkc.home.dir=/app", "-jar", "/app/lib/quarkus-run.jar"]
CMD ["import", "--dir=/realms"]

###
### Distroless
###

FROM gcr.io/distroless/java${maven.compiler.target}:nonroot AS distroless

# https://github.com/opencontainers/image-spec/blob/main/annotations.md
LABEL org.opencontainers.image.title ${project.name}
LABEL org.opencontainers.image.description ${project.description}
LABEL org.opencontainers.image.url ${project.url}
LABEL org.opencontainers.image.source ${project.url}/src/main/docker/Dockerfile
LABEL org.opencontainers.image.vendor ${project.organization.name}
LABEL org.opencontainers.image.authors https://github.com/orgs/kokuwaio/people
LABEL org.opencontainers.image.licenses Apache-2.0
LABEL org.opencontainers.image.version ${version.org.keycloak}
LABEL org.opencontainers.image.created ${git.build.time}
LABEL org.opencontainers.image.revision ${git.commit.id}
LABEL org.opencontainers.image.ref.name ${image.tag}-distroless
LABEL org.opencontainers.image.base.name gcr.io/distroless/java${maven.compiler.target}:nonroot

# https://www.keycloak.org/server/all-config
ENV \
KC_DB=postgres \
KC_CACHE=ispn \
KC_CACHE_STACK=kubernetes \
KC_CACHE_DNS=keycloak-headless \
KC_CACHE_OWNERS=2 \
KC_HEALTH_ENABLED=true \
KC_METRICS_ENABLED=true \
KC_METRICS_EVENT_REPLACE_IDS=true \
KC_METRICS_STATS_ENABLED=true \
URI_METRICS_ENABLED=false \
URI_METRICS_DETAILED=false \
KC_PROXY=edge \
KC_LOG_CONSOLE_OUTPUT=json

COPY --from=keycloak-runtime /app /app
ENTRYPOINT ["java", "-XX:+ExitOnOutOfMemoryError", "-Dkc.home.dir=/app", "-Djgroups.dns.query=${KC_CACHE_DNS}", "-jar", "/app/lib/quarkus-run.jar"]
CMD ["start", "--optimized"]

###
### Distroless Import
###

FROM gcr.io/distroless/java${maven.compiler.target}:nonroot AS distroless-import

# https://github.com/opencontainers/image-spec/blob/main/annotations.md
LABEL org.opencontainers.image.title ${project.name}
LABEL org.opencontainers.image.description ${project.description}
LABEL org.opencontainers.image.url ${project.url}
LABEL org.opencontainers.image.source ${project.url}/src/main/docker/Dockerfile
LABEL org.opencontainers.image.vendor ${project.organization.name}
LABEL org.opencontainers.image.authors https://github.com/orgs/kokuwaio/people
LABEL org.opencontainers.image.licenses Apache-2.0
LABEL org.opencontainers.image.version ${version.org.keycloak}
LABEL org.opencontainers.image.created ${git.build.time}
LABEL org.opencontainers.image.revision ${git.commit.id}
LABEL org.opencontainers.image.ref.name ${image.tag}-distroless-import
LABEL org.opencontainers.image.base.name gcr.io/distroless/java${maven.compiler.target}:nonroot

# https://www.keycloak.org/server/all-config
ENV KC_DB=postgres KC_CACHE=local KC_LOG_CONSOLE_OUTPUT=json

COPY --from=keycloak-import /app /app
ENTRYPOINT ["java", "-XX:+ExitOnOutOfMemoryError", "-Dkc.home.dir=/app", "-jar", "/app/lib/quarkus-run.jar"]
CMD ["import", "--dir=/realms"]
9 changes: 0 additions & 9 deletions src/main/docker/base/Dockerfile

This file was deleted.

File renamed without changes.
27 changes: 0 additions & 27 deletions src/main/docker/distroless-import/Dockerfile

This file was deleted.

37 changes: 0 additions & 37 deletions src/main/docker/distroless/Dockerfile

This file was deleted.

26 changes: 0 additions & 26 deletions src/main/docker/temurin-import/Dockerfile

This file was deleted.

Loading

0 comments on commit 8efa76f

Please sign in to comment.