From d78cdef4f9517f30a4053d1527ad4662de2e2a0a Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Mon, 26 Feb 2024 17:02:46 -0600 Subject: [PATCH] Support pnpm --- .../cerc-nextjs-base/Dockerfile | 5 +++++ .../scripts/apply-runtime-env.sh | 10 +++++---- .../cerc-nextjs-base/scripts/build-app.sh | 4 +++- .../scripts/start-serving-app.sh | 6 ++++-- .../cerc-webapp-base/Dockerfile | 4 ++++ .../cerc-webapp-base/Dockerfile.webapp | 3 ++- .../cerc-webapp-base/scripts/build-app.sh | 21 +++++++++++++++---- 7 files changed, 41 insertions(+), 12 deletions(-) diff --git a/stack_orchestrator/data/container-build/cerc-nextjs-base/Dockerfile b/stack_orchestrator/data/container-build/cerc-nextjs-base/Dockerfile index 5f9548ee..d3ae8237 100644 --- a/stack_orchestrator/data/container-build/cerc-nextjs-base/Dockerfile +++ b/stack_orchestrator/data/container-build/cerc-nextjs-base/Dockerfile @@ -26,6 +26,8 @@ RUN \ && su ${USERNAME} -c "umask 0002 && npm install -g eslint" \ # Install semver && su ${USERNAME} -c "umask 0002 && npm install -g semver" \ + # Install pnpm + && su ${USERNAME} -c "umask 0002 && npm install -g pnpm" \ && npm cache clean --force > /dev/null 2>&1 # [Optional] Uncomment this section to install additional OS packages. @@ -35,6 +37,9 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ # [Optional] Uncomment if you want to install more global node modules # RUN su node -c "npm install -g " +# We do this to get a yq binary from the published container, for the correct architecture we're building here +COPY --from=docker.io/mikefarah/yq:latest /usr/bin/yq /usr/local/bin/yq + # Expose port for http EXPOSE 80 diff --git a/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/apply-runtime-env.sh b/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/apply-runtime-env.sh index a662ae02..737c90e7 100755 --- a/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/apply-runtime-env.sh +++ b/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/apply-runtime-env.sh @@ -10,12 +10,14 @@ TRG_DIR="${3:-.next-r}" CERC_BUILD_TOOL="${CERC_BUILD_TOOL}" if [ -z "$CERC_BUILD_TOOL" ]; then - if [ -f "yarn.lock" ]; then - CERC_BUILD_TOOL=npm - else + if [ -f "pnpm-lock.yaml" ]; then + CERC_BUILD_TOOL=pnpm + elif [ -f "yarn.lock" ]; then CERC_BUILD_TOOL=yarn + else + CERC_BUILD_TOOL=npm fi -fi +f cd "${WORK_DIR}" || exit 1 diff --git a/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/build-app.sh b/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/build-app.sh index 40bcbeed..bf86265d 100755 --- a/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/build-app.sh +++ b/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/build-app.sh @@ -9,7 +9,9 @@ CERC_MIN_NEXTVER=13.4.2 CERC_NEXT_VERSION="${CERC_NEXT_VERSION:-keep}" CERC_BUILD_TOOL="${CERC_BUILD_TOOL}" if [ -z "$CERC_BUILD_TOOL" ]; then - if [ -f "yarn.lock" ]; then + if [ -f "pnpm-lock.yaml" ]; then + CERC_BUILD_TOOL=pnpm + elif [ -f "yarn.lock" ]; then CERC_BUILD_TOOL=yarn else CERC_BUILD_TOOL=npm diff --git a/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/start-serving-app.sh b/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/start-serving-app.sh index bd254572..36d550e8 100755 --- a/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/start-serving-app.sh +++ b/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/start-serving-app.sh @@ -16,12 +16,14 @@ trap ctrl_c INT CERC_BUILD_TOOL="${CERC_BUILD_TOOL}" if [ -z "$CERC_BUILD_TOOL" ]; then - if [ -f "yarn.lock" ] && [ ! -f "package-lock.json" ]; then + if [ -f "pnpm-lock.yaml" ]; then + CERC_BUILD_TOOL=pnpm + elif [ -f "yarn.lock" ]; then CERC_BUILD_TOOL=yarn else CERC_BUILD_TOOL=npm fi -fi +f CERC_WEBAPP_FILES_DIR="${CERC_WEBAPP_FILES_DIR:-/app}" cd "$CERC_WEBAPP_FILES_DIR" diff --git a/stack_orchestrator/data/container-build/cerc-webapp-base/Dockerfile b/stack_orchestrator/data/container-build/cerc-webapp-base/Dockerfile index 9ae166b0..b8319c51 100644 --- a/stack_orchestrator/data/container-build/cerc-webapp-base/Dockerfile +++ b/stack_orchestrator/data/container-build/cerc-webapp-base/Dockerfile @@ -24,6 +24,10 @@ RUN \ && su ${USERNAME} -c "npm config -g set prefix ${NPM_GLOBAL}" \ # Install eslint && su ${USERNAME} -c "umask 0002 && npm install -g eslint" \ + # Install semver + && su ${USERNAME} -c "umask 0002 && npm install -g semver" \ + # Install pnpm + && su ${USERNAME} -c "umask 0002 && npm install -g pnpm" \ && npm cache clean --force > /dev/null 2>&1 # [Optional] Uncomment this section to install additional OS packages. diff --git a/stack_orchestrator/data/container-build/cerc-webapp-base/Dockerfile.webapp b/stack_orchestrator/data/container-build/cerc-webapp-base/Dockerfile.webapp index 711eff25..118fba5f 100644 --- a/stack_orchestrator/data/container-build/cerc-webapp-base/Dockerfile.webapp +++ b/stack_orchestrator/data/container-build/cerc-webapp-base/Dockerfile.webapp @@ -1,11 +1,12 @@ FROM cerc/webapp-base:local as builder ARG CERC_BUILD_TOOL +ARG CERC_BUILD_OUTPUT_DIR WORKDIR /app COPY . . RUN rm -rf node_modules build .next* -RUN /scripts/build-app.sh /app build /data +RUN /scripts/build-app.sh /app /data FROM cerc/webapp-base:local COPY --from=builder /data /data diff --git a/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/build-app.sh b/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/build-app.sh index b515a142..3a63df84 100755 --- a/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/build-app.sh +++ b/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/build-app.sh @@ -7,9 +7,10 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then fi CERC_BUILD_TOOL="${CERC_BUILD_TOOL}" +CERC_BUILD_OUTPUT_DIR="${CERC_BUILD_OUTPUT_DIR}" + WORK_DIR="${1:-/app}" -OUTPUT_DIR="${2:-build}" -DEST_DIR="${3:-/data}" +DEST_DIR="${2:-/data}" if [ -f "${WORK_DIR}/build-webapp.sh" ]; then echo "Building webapp with ${WORK_DIR}/build-webapp.sh ..." @@ -22,7 +23,9 @@ elif [ -f "${WORK_DIR}/package.json" ]; then cd "${WORK_DIR}" || exit 1 if [ -z "$CERC_BUILD_TOOL" ]; then - if [ -f "yarn.lock" ]; then + if [ -f "pnpm-lock.yaml" ]; then + CERC_BUILD_TOOL=pnpm + elif [ -f "yarn.lock" ]; then CERC_BUILD_TOOL=yarn else CERC_BUILD_TOOL=npm @@ -33,7 +36,17 @@ elif [ -f "${WORK_DIR}/package.json" ]; then $CERC_BUILD_TOOL build || exit 1 rm -rf "${DEST_DIR}" - mv "${WORK_DIR}/${OUTPUT_DIR}" "${DEST_DIR}" + if [ -z "${CERC_BUILD_OUTPUT_DIR}" ]; then + if [ -d "${WORK_DIR}/dist" ]; then + CERC_BUILD_OUTPUT_DIR="${WORK_DIR}/dist" + elif [ -d "${WORK_DIR}/build" ]; then + CERC_BUILD_OUTPUT_DIR="${WORK_DIR}/build" + else + echo "ERROR: Unable to locate build output. Set with --extra-build-args \"--build-arg CERC_BUILD_OUTPUT_DIR=path\"" 1>&2 + exit 1 + fi + fi + mv "${CERC_BUILD_OUTPUT_DIR}" "${DEST_DIR}" else echo "Copying static app ..." mv "${WORK_DIR}" "${DEST_DIR}"