Skip to content

Commit

Permalink
Build complete application in Dockerfile.
Browse files Browse the repository at this point in the history
This ensures container building process is build-environment agnostic.
  • Loading branch information
mluypaert committed Jan 26, 2024
1 parent 8a7d6b5 commit bb678e9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 7 deletions.
54 changes: 50 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,55 @@
FROM openjdk:8-jre-alpine
ARG WORKDIR=/wb_names
ARG APPJAR_BUILDPATH=build/wb-names-app.jar

ARG uberjar_path=
ADD $uberjar_path /srv/app.jar
### Stage 1: build UI
FROM node:12 AS BUILD_UI_STAGE

ARG WORKDIR

WORKDIR $WORKDIR
COPY Makefile ./
COPY client/ ./client/
COPY scripts/ ./scripts/

RUN --mount=type=secret,id=make-secrets-file,required=true \
make build-ui SECRETS_SRC=/run/secrets/make-secrets-file APP_PROFILE=prod

### Stage 2: build API (and include UI components)
FROM clojure:temurin-8-tools-deps-jammy as BUILD_API_STAGE

ARG WORKDIR
ARG APPJAR_BUILDPATH

RUN apt update && apt upgrade -y && apt install -y maven unzip

#Install clojure manually (com.datomic/datomic-pro 1.0.6165 is not stored on maven central)
COPY build/datomic-pro-1.0.6165.zip datomic-pro-1.0.6165.zip
RUN unzip datomic-pro-1.0.6165.zip \
&& cd datomic-pro-1.0.6165/ \
&& bin/maven-install

WORKDIR $WORKDIR
COPY Makefile ./
COPY src/wormbase/ src/wormbase/
COPY resources/ ./resources/
COPY deps.edn ./
COPY project.clj ./
COPY scripts/ ./scripts/
COPY --from=BUILD_UI_STAGE $WORKDIR/client/ $WORKDIR/client/

RUN make build-app-jar APP_JAR_PATH=$APPJAR_BUILDPATH

### Stage 3: build final application image
FROM openjdk:8-jre-alpine as APPLICATION_IMAGE_STAGE

ARG WORKDIR
ARG APPJAR_BUILDPATH

RUN apk update && apk upgrade

COPY --from=BUILD_API_STAGE $WORKDIR/$APPJAR_BUILDPATH /srv/wb-names-app.jar

# Expose necessary ports
EXPOSE 3000

CMD ["java", "-cp", "/srv/app.jar", "clojure.main", "-m", "wormbase.names.service"]
CMD ["java", "-cp", "/srv/wb-names-app.jar", "clojure.main", "-m", "wormbase.names.service"]
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,14 @@ build/:
mkdir build/

.PHONY: build
build: ENV.VERSION_TAG clean build/ ui-build build/${DEPLOY_JAR} \
build: build/ ENV.VERSION_TAG ${STORE_SECRETS_FILE} \
$(call print-help,build,\
Build the docker images from using the current git revision.)
Build the docker images from the current git revision.)
@aws s3 cp s3://wormbase/datomic-pro/distro/datomic-pro-1.0.6165.zip build/
@docker build -t ${ECR_REPO_NAME}:${VERSION_TAG} \
--build-arg uberjar_path=build/${DEPLOY_JAR} .
--secret id=make-secrets-file,src=${STORE_SECRETS_FILE} \
.
@rm ${STORE_SECRETS_FILE}

.PHONY: build-ui
build-ui: ENV.GOOGLE_OAUTH_CLIENT_ID \
Expand Down

0 comments on commit bb678e9

Please sign in to comment.