diff --git a/Dockerfile b/Dockerfile index cc6732dd..60f299c6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/Makefile b/Makefile index eb8bf0c6..11759b5e 100644 --- a/Makefile +++ b/Makefile @@ -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 \