This commit is contained in:
aditya.chandel
2025-11-30 22:03:59 -07:00
parent 8487d3ed75
commit e4eca9280d
3 changed files with 36 additions and 23 deletions

View File

@@ -35,6 +35,7 @@ FROM eclipse-temurin:21.0.9_10-jre-alpine
ARG APP_VERSION
ARG APP_REVISION
ARG BOOKLORE_PORT=8080
# Set OCI labels
LABEL org.opencontainers.image.title="BookLore" \
@@ -47,12 +48,19 @@ LABEL org.opencontainers.image.title="BookLore" \
org.opencontainers.image.licenses="GPL-3.0" \
org.opencontainers.image.base.name="docker.io/library/eclipse-temurin:21.0.9_10-jre-alpine"
RUN apk update && apk add su-exec
ENV BOOKLORE_PORT=${BOOKLORE_PORT}
# Install su-exec (a lightweight alternative to sudo/gosu)
RUN apk add --no-cache su-exec
RUN mkdir -p /app
COPY --from=springboot-build /springboot-app/build/libs/booklore-api-0.0.1-SNAPSHOT.jar /app/app.jar
COPY start.sh /start.sh
RUN chmod +x /start.sh
EXPOSE 8080
COPY entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh
CMD ["/start.sh"]
EXPOSE ${BOOKLORE_PORT}
ENTRYPOINT ["entrypoint.sh"]
CMD ["java", "-jar", "/app/app.jar"]

23
entrypoint.sh Normal file
View File

@@ -0,0 +1,23 @@
#!/bin/sh
set -e
# Create a group and user with the provided IDs, defaulting to 1000
TARGET_UID=${USER_ID:-1000}
TARGET_GID=${GROUP_ID:-1000}
# Check if group exists, create if not
if ! getent group ${TARGET_GID} >/dev/null 2>&1; then
addgroup -g ${TARGET_GID} bookloregroup
fi
# Check if user exists, create if not
if ! getent passwd ${TARGET_UID} >/dev/null 2>&1; then
adduser -D -u ${TARGET_UID} -G bookloregroup booklore
fi
# Ensure ownership of app files
chown -R ${TARGET_UID}:${TARGET_GID} /app
# Execute the main command as the new user
exec su-exec ${TARGET_UID}:${TARGET_GID} "$@"

View File

@@ -1,18 +0,0 @@
#!/bin/sh
# Set default and export so envsubst sees it
: "${BOOKLORE_PORT:=6060}"
export BOOKLORE_PORT
# Use envsubst safely
TMP_CONF="/tmp/nginx.conf.tmp"
envsubst '${BOOKLORE_PORT}' < /etc/nginx/nginx.conf > "$TMP_CONF"
# Move to final location
mv "$TMP_CONF" /etc/nginx/nginx.conf
# Start nginx in background
nginx -g 'daemon off;' &
# Start Spring Boot in foreground
su-exec ${USER_ID:-0}:${GROUP_ID:-0} java -jar /app/app.jar