Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) Allow image to use different frontend setup by modifying spa-build-config.json #777

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# syntax=docker/dockerfile:1

### Dev Stage
FROM openmrs/openmrs-core:dev as dev
FROM --platform=$BUILDPLATFORM openmrs/openmrs-core:dev as dev
WORKDIR /openmrs_distro

ARG MVN_ARGS_SETTINGS="-s /usr/share/maven/ref/settings-docker.xml -U"
Expand All @@ -25,7 +25,7 @@ RUN mvn $MVN_ARGS_SETTINGS clean

### Run Stage
# Replace 'nightly' with the exact version of openmrs-core built for production (if available)
FROM openmrs/openmrs-core:nightly
FROM --platform=$BUILDPLATFORM openmrs/openmrs-core:nightly

# Do not copy the war if using the correct openmrs-core image version
COPY --from=dev /openmrs/distribution/openmrs_core/openmrs.war /openmrs/distribution/openmrs_core/
Expand Down
26 changes: 21 additions & 5 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# syntax=docker/dockerfile:1.3
FROM --platform=$BUILDPLATFORM node:18-alpine as dev

ARG NODE_VERSION=18
ARG APP_SHELL_VERSION=next

FROM --platform=$BUILDPLATFORM node:${NODE_VERSION}-alpine as dev

RUN mkdir -p /app
WORKDIR /app

Expand All @@ -11,23 +12,38 @@ COPY spa-build-config.json .
ARG CACHE_BUST
RUN npx --legacy-peer-deps openmrs@${APP_SHELL_VERSION:-next} assemble --manifest --mode config --config spa-build-config.json --target ./spa
RUN npx --legacy-peer-deps openmrs@${APP_SHELL_VERSION:-next} build --build-config spa-build-config.json --target ./spa
RUN if [ ! -f ./spa/index.html ]; then echo 'Build failed. Please check the logs above for details. This may have happened because of an update to a library that OpenMRS depends on.'; exit 1; fi
RUN if [ ! -f ./spa/index.html ]; then echo 'Build failed. Please check the logs above for details. This may have happened because of an update to a library that OpenMRS depends on.' >&2 ; exit 1; fi

FROM nginx:1.25-alpine
FROM --platform=$BUILDPLATFORM nginx:1.25-alpine

RUN apk update && \
apk upgrade && \
# add more utils for sponge to support our startup script
apk add --no-cache moreutils
apk add --no-cache moreutils perl-utils

# clear any default files installed by nginx
RUN rm -rf /usr/share/nginx/html/*

ENV APP_SHELL_VERSION ${APP_SHELL_VERSION:-next}

# the default nginx image doesn't have Node or NPM, so we copy it from the dev image
COPY --from=dev /usr/lib /usr/lib
COPY --from=dev /usr/local/lib /usr/local/lib
COPY --from=dev /usr/local/include /usr/local/include
COPY --from=dev /usr/local/bin /usr/local/bin

COPY startup.sh /usr/local/bin/startup.sh
RUN chmod +x /usr/local/bin/startup.sh

COPY nginx.conf /etc/nginx/nginx.conf

# allow updating by overwriting spa-build-config.json
RUN mkdir -p /openmrs
COPY --from=dev /app/spa-build-config.json /openmrs/spa-build-config.json
WORKDIR /openmrs
RUN shasum -a 512 spa-build-config.json | tee spa-build-config.json.sha512sum
WORKDIR /

COPY --from=dev /app/spa /usr/share/nginx/html

CMD ["/usr/local/bin/startup.sh"]
26 changes: 26 additions & 0 deletions frontend/startup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
#!/bin/sh
set -e

rebuild_frontend() {
npx --legacy-peer-deps openmrs@${APP_SHELL_VERSION:-next} assemble --manifest --mode config --config spa-build-config.json --target ./spa
npx --legacy-peer-deps openmrs@${APP_SHELL_VERSION:-next} build --build-config spa-build-config.json --target ./spa
# we exit 0 below so that build failures do not stop the image
if [ ! -f ./spa/index.html ]; then echo 'Rebuild failed. Please check the logs above for details. This may have happened because of an update to a library that OpenMRS depends on.' >&2; popd; exit 0; fi
shasum -a 512 spa-build-config.json > spa-build-config.json.sha512sum

rm -rf /usr/share/nginx/html/*
cp -r spa/* /usr/share/nginx/html
}

if [ -d "/openmrs" ]; then
if [ -f "/openmrs/spa-build-config.json" ]; then
if [ -f "/openmrs/spa-build-config.json.sha512sum" ]; then
cd "/openmrs"
shasum -a 512 -c /openmrs/spa-build-config.json.sha512sum > /dev/null || {
echo "Checksum mismatch. Rebuilding frontend..."
rebuild_frontend
}
else
echo "Checksum file not found. Rebuilding frontend..."
rebuild_frontend
fi
fi
fi

# if we are using the $IMPORTMAP_URL environment variable, we have to make this useful,
# so we change "importmap.json" into "$IMPORTMAP_URL" allowing it to be changed by envsubst
if [ -n "${IMPORTMAP_URL}" ]; then
Expand Down
2 changes: 1 addition & 1 deletion gateway/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# syntax=docker/dockerfile:1.3
FROM nginx:1.25-alpine
FROM --platform=$BUILDPLATFORM nginx:1.25-alpine

ENV FRAME_ANCESTORS ""

Expand Down
Loading