Skip to content

Commit

Permalink
Docker Compose adjustments (#147)
Browse files Browse the repository at this point in the history
* Frontend up yarn installs

* Consolidate Healthchecks into Dockerfiles

* Make oracle-api depend on backend

* Unprivileged user for local frontend dev

* Use default values for healthchecks

* Formatting, slight logic tweak

* Let local frontend use user:root
  • Loading branch information
DerekRoberts committed May 14, 2024
1 parent 691be78 commit c36f6bf
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 67 deletions.
14 changes: 8 additions & 6 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
FROM maven:3.8.7-eclipse-temurin-17 AS build

# User
RUN addgroup --system spring && adduser --system spring --ingroup spring
USER spring:spring

# App
WORKDIR /home/spring
COPY src /home/spring/src
COPY pom.xml /home/spring

WORKDIR /home/spring
RUN mvn --no-transfer-progress --update-snapshots -P prod clean package

FROM eclipse-temurin:17.0.7_7-jre-jammy
LABEL maintainer="Ricardo Montania Prado de Campos <ricardo.campos@encora.com>"
FROM eclipse-temurin:17.0.7_7-jre-jammy AS deploy

ENV LANG en_CA.UTF-8
ENV LANGUAGE en_CA.UTF-8
ENV LC_ALL en_CA.UTF-8

# App
WORKDIR /usr/share/service/
COPY --from=build /home/spring/target/nr-spar-backend.jar /usr/share/service/service.jar
COPY dockerfile-entrypoint.sh /usr/share/service/dockerfile-entrypoint.sh

EXPOSE 8090
# User, port and healthcheck
USER 1001
HEALTHCHECK --interval=35s --timeout=4s CMD wget --no-verbose --tries=1 --spider http://localhost:8090/actuator/health
EXPOSE 8090
HEALTHCHECK CMD curl -f http://localhost:8090/actuator/health | grep '"status":"UP"'
ENTRYPOINT ["/usr/share/service/dockerfile-entrypoint.sh"]
5 changes: 3 additions & 2 deletions database/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# RedHat UBI 8 with nodejs 14
FROM postgis/postgis:13-master

# Enable pgcrypto extension on startup
RUN sed -i '/EXISTS postgis_tiger_geocoder;*/a CREATE EXTENSION IF NOT EXISTS pgcrypto;' \
/docker-entrypoint-initdb.d/10_postgis.sh

# Non-privileged user
# User, port and Healthcheck
USER postgres
EXPOSE 5432
HEALTHCHECK CMD [ "pg_isready", "-U", "postgres"]
29 changes: 4 additions & 25 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ services:
- /pgdata
build:
context: ./database
healthcheck:
test: [ "CMD", "pg_isready", "-U", "postgres"]
interval: 5s
timeout: 5s
retries: 5
start_period: 30s

backend:
container_name: backend
Expand All @@ -40,19 +34,16 @@ services:
POSTGRESQL_PASSWORD: *POSTGRES_PASSWORD
FORESTCLIENTAPI_ADDRESS: https://nr-forest-client-api-prod.api.gov.bc.ca/api
FORESTCLIENTAPI_KEY: "${FORESTCLIENTAPI_KEY}"
healthcheck:
test: [ "CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8090/actuator/health" ]
interval: 5s
timeout: 5s
retries: 5
start_period: 30s
ports:
- "8090:8090"
build:
context: ./backend

oracle-api:
container_name: oracle-api
depends_on:
backend:
condition: service_healthy
environment:
NR_SPAR_ORACLE_API_VERSION: "dev"
SERVER_PORT: "8091"
Expand All @@ -62,12 +53,6 @@ services:
DATABASE_USER: proxy_fsa_spar_read_only_user
DATABASE_PASSWORD: "${DATABASE_PASSWORD}"
KEYCLOAK_REALM_URL: "https://test.loginproxy.gov.bc.ca/auth/realms/standard"
healthcheck:
test: [ "CMD", "java", "HealthCheck" ]
interval: 5s
timeout: 5s
retries: 5
start_period: 45s
ports:
- "8091:8091"
build:
Expand All @@ -92,12 +77,6 @@ services:
build:
context: ./frontend
dockerfile: Dockerfile.dev
user: root
volumes:
- ./frontend:/app:z
- /app/node_modules
healthcheck:
test: [ "CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/" ]
interval: 5s
timeout: 5s
retries: 5
start_period: 30s
22 changes: 11 additions & 11 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# Build
FROM node:16.19.1-alpine3.17 AS build

# Copy and build
# Build
WORKDIR /app
COPY . .
RUN apk add --no-cache python3 g++ make &&\
yarn install --frozen-lockfile --prefer-offline
RUN yarn build:production
RUN rm -rf node_modules
RUN apk add --no-cache python3 g++ make && \
yarn install --frozen-lockfile --prefer-offline && \
yarn build:production && \
rm -rf node_modules

# Deploy
FROM node:16.19.1-alpine3.17
FROM node:16.19.1-alpine3.17 AS deploy

# Copy and prep app
WORKDIR /app
COPY --from=build /app/build/ .
RUN yarn global add serve@14.2.0 react-inject-env@2.1.0 && \
chmod -R g+w .

# User and startup
EXPOSE 3000
# User, port and healthcheck
USER 1001
HEALTHCHECK --interval=30s --timeout=3s CMD wget --no-verbose --tries=1 --spider http://localhost:3000/
EXPOSE 3000
HEALTHCHECK CMD wget --no-verbose --tries=1 --spider http://localhost:3000 || exit 1

# Startup
CMD react-inject-env set -d . && \
serve --no-clipboard --single .
22 changes: 12 additions & 10 deletions frontend/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Build
FROM node:16.19.1-alpine3.17 AS dev-build
FROM node:16.19.1-alpine3.17
ENV PORT=3000

# Copy and build
WORKDIR /app
COPY . .
RUN apk add --no-cache python3 g++ make &&\
yarn install --frozen-lockfile --prefer-offline
# Packages
RUN apk add --no-cache python3 g++ make

# User, port and Healthcheck
USER 1001
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost:3000/
CMD yarn start
EXPOSE ${PORT}
HEALTHCHECK CMD wget --no-verbose --tries=1 --spider http://localhost:${PORT} || exit 1

# Start
WORKDIR /app
CMD ["sh", "-c", "yarn install --frozen-lockfile --prefer-offline && yarn start"]
24 changes: 11 additions & 13 deletions oracle-api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
# Build container
FROM openjdk:17.0.2 AS build

# Build package/archive
# Build
WORKDIR /app
COPY . ./
RUN ./mvnw --no-transfer-progress --update-snapshots clean package -Dtests.skip=true -Dskip.unit.tests=true
RUN javac HealthCheck.java InstallCert.java
RUN ./mvnw --no-transfer-progress --update-snapshots clean package -Dtests.skip=true -Dskip.unit.tests=true && \
javac HealthCheck.java InstallCert.java

# Deploy container
FROM eclipse-temurin:17.0.7_7-jdk-jammy AS deploy

# Java vars
ENV LANG en_CA.UTF-8
ENV LANGUAGE en_CA.UTF-8
ENV LC_ALL en_CA.UTF-8

# Setup package/archive and supporting files
WORKDIR /usr/share/service/
COPY --from=build /app/target/*.jar \
/app/HealthCheck.class \
/app/InstallCert.class \
/app/InstallCert\$SavingTrustManager.class \
./artifacts/
COPY --from=build /app/target/*.jar /app/*.class ./artifacts/
COPY dockerfile-entrypoint.sh ./
RUN mkdir config dump public && \
chmod -R g+w . && \
chmod g+x dockerfile-entrypoint.sh && \
chmod g+w ${JAVA_HOME}/lib/security/cacerts

# Port, user and entrypoint
EXPOSE 8090
# User, port and healthcheck
USER 1001
HEALTHCHECK --interval=35s --timeout=4s CMD java -cp /usr/share/service/artifacts/ HealthCheck
EXPOSE 8090
HEALTHCHECK CMD curl -f http://localhost:8090/actuator/health | grep '"status":"UP"'

# Start
ENTRYPOINT ["/usr/share/service/dockerfile-entrypoint.sh"]

0 comments on commit c36f6bf

Please sign in to comment.