Skip to content

Commit

Permalink
Merge pull request #133 from hackcoderr/non-root-img
Browse files Browse the repository at this point in the history
Make Non-root docker image for cat server
  • Loading branch information
abhi4578 authored Mar 21, 2022
2 parents bfff59c + d0596cb commit 9ab50bd
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 33 deletions.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ networks:
services:

cat:
image: ghcr.io/datakaveri/cat-prod:latest
image: iudx/cat-prod:latest
environment:
- CAT_URL=https://catalogue.iudx.org.in
- LOG_LEVEL=INFO
Expand All @@ -31,7 +31,7 @@ services:
command: bash -c "exec java $$CAT_JAVA_OPTS -Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.Log4j2LogDelegateFactory -jar ./fatjar.jar --host $$(hostname) -c configs/config.json"

dev:
image: ghcr.io/datakaveri/cat-dev:latest
image: iudx/cat-dev:latest
environment:
- CAT_URL=https://catalogue.iudx.org.in
- LOG_LEVEL=INFO
Expand Down
8 changes: 4 additions & 4 deletions docker/build-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ COMMIT_ID=`git log -1 --pretty=%h` # last commit-id in short form

# To be executed from project root

docker build -t dockerhub.iudx.io/iudx/cat-prod:$MAJOR_RELEASE.$MINOR_RELEASE-$COMMIT_ID -f docker/prod.dockerfile . && \
docker push dockerhub.iudx.io/iudx/cat-prod:$MAJOR_RELEASE.$MINOR_RELEASE-$COMMIT_ID
docker build -t ghcr.io/datakaveri/cat-prod:$MAJOR_RELEASE.$MINOR_RELEASE-$COMMIT_ID -f docker/prod.dockerfile . && \
docker push ghcr.io/datakaveri/cat-prod:$MAJOR_RELEASE.$MINOR_RELEASE-$COMMIT_ID

docker build -t dockerhub.iudx.io/iudx/cat-dev:$MAJOR_RELEASE.$MINOR_RELEASE-$COMMIT_ID -f docker/dev.dockerfile . && \
docker push dockerhub.iudx.io/iudx/cat-dev:$MAJOR_RELEASE.$MINOR_RELEASE-$COMMIT_ID
docker build -t ghcr.io/datakaveri/cat-dev:$MAJOR_RELEASE.$MINOR_RELEASE-$COMMIT_ID -f docker/dev.dockerfile . && \
docker push ghcr.io/datakaveri/cat-dev:$MAJOR_RELEASE.$MINOR_RELEASE-$COMMIT_ID
4 changes: 0 additions & 4 deletions docker/build-ui.sh

This file was deleted.

20 changes: 13 additions & 7 deletions docker/dev.dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
ARG VERSION="0.0.1-SNAPSHOT"

FROM maven:3-openjdk-11-slim as dependencies
# Using maven base image in builder stage to build Java code
FROM maven:3-openjdk-11-slim as builder

WORKDIR /usr/share/app
COPY pom.xml .
# Downloads all packages defined in pom.xml
RUN mvn clean package

FROM dependencies as builder

WORKDIR /usr/share/app
COPY pom.xml .
COPY src src
# Build the source code to generate the fatjar
RUN mvn clean package -Dmaven.test.skip=true


# Java Runtime as the base for final image
FROM openjdk:11-jre-slim-buster

ARG VERSION
ENV JAR="iudx.catalogue.server-dev-${VERSION}-fat.jar"

WORKDIR /usr/share/app
# Copying openapi docs
COPY docs docs
# Copying dev fatjar from builder stage to final image
COPY --from=builder /usr/share/app/target/${JAR} ./fatjar.jar
EXPOSE 8080
EXPOSE 8443
# Creating a non-root user
RUN useradd -r -u 1001 -g root catuser
# Setting non-root user to use when container starts
USER catuser
24 changes: 17 additions & 7 deletions docker/prod.dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
ARG VERSION="0.0.1-SNAPSHOT"

FROM maven:3-openjdk-11-slim as dependencies
# Maven base image for building the java code
FROM maven:3-openjdk-11-slim as builder

WORKDIR /usr/share/app
COPY pom.xml .
# Downloads packages defined in pom.xml
RUN mvn clean package

FROM dependencies as builder

WORKDIR /usr/share/app
COPY pom.xml .
COPY src src
# Build the source code to generate fat jar
RUN mvn clean package -Dmaven.test.skip=true


# Java runtime as final base image
FROM openjdk:11-jre-slim-buster

ARG VERSION
ENV JAR="iudx.catalogue.server-cluster-${VERSION}-fat.jar"

WORKDIR /usr/share/app
# Copying openapi docs
COPY docs docs
# Copying cluster fatjar from builder image stage to final image
COPY --from=builder /usr/share/app/target/${JAR} ./fatjar.jar
# HTTP cat server port
EXPOSE 8080
# HTTPS cat server port
EXPOSE 8443
# Metrics http server port
EXPOSE 9000
# creating a non-root user
RUN useradd -r -u 1001 -g root catuser
# Setting non-root user to use when container starts
USER catuser
9 changes: 0 additions & 9 deletions docker/ui.dockerfile

This file was deleted.

0 comments on commit 9ab50bd

Please sign in to comment.