From db4986dcc65aa4e8b6500babc7030e47824d7026 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Wed, 21 Feb 2024 04:45:46 +0000 Subject: [PATCH] snowballtool-base backend stack (#751) This adds a stack for the backend from snowball/snowballtools-base. Reviewed-on: https://git.vdb.to/cerc-io/stack-orchestrator/pulls/751 Co-authored-by: Thomas E Lackey Co-committed-by: Thomas E Lackey --- ...ker-compose-snowballtools-base-backend.yml | 13 ++++++++++ .../Dockerfile | 6 +++++ .../Dockerfile-base | 26 +++++++++++++++++++ .../cerc-snowballtools-base-backend/build.sh | 10 +++++++ .../cerc-snowballtools-base-backend/run.sh | 19 ++++++++++++++ .../cerc-webapp-base/Dockerfile | 1 - .../cerc-webapp-base/config.yml | 1 - .../scripts/start-serving-app.sh | 14 +++++++++- .../snowballtools-base-backend/stack.yml | 10 +++++++ 9 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 stack_orchestrator/data/compose/docker-compose-snowballtools-base-backend.yml create mode 100644 stack_orchestrator/data/container-build/cerc-snowballtools-base-backend/Dockerfile create mode 100644 stack_orchestrator/data/container-build/cerc-snowballtools-base-backend/Dockerfile-base create mode 100755 stack_orchestrator/data/container-build/cerc-snowballtools-base-backend/build.sh create mode 100755 stack_orchestrator/data/container-build/cerc-snowballtools-base-backend/run.sh delete mode 100644 stack_orchestrator/data/container-build/cerc-webapp-base/config.yml create mode 100644 stack_orchestrator/data/stacks/snowballtools-base-backend/stack.yml diff --git a/stack_orchestrator/data/compose/docker-compose-snowballtools-base-backend.yml b/stack_orchestrator/data/compose/docker-compose-snowballtools-base-backend.yml new file mode 100644 index 00000000..3445ed9d --- /dev/null +++ b/stack_orchestrator/data/compose/docker-compose-snowballtools-base-backend.yml @@ -0,0 +1,13 @@ +services: + snowballtools-base-backend: + image: cerc/snowballtools-base-backend:local + restart: always + volumes: + - data:/data + - config:/config:ro + ports: + - 8000 + +volumes: + data: + config: diff --git a/stack_orchestrator/data/container-build/cerc-snowballtools-base-backend/Dockerfile b/stack_orchestrator/data/container-build/cerc-snowballtools-base-backend/Dockerfile new file mode 100644 index 00000000..ca5c4586 --- /dev/null +++ b/stack_orchestrator/data/container-build/cerc-snowballtools-base-backend/Dockerfile @@ -0,0 +1,6 @@ +FROM cerc/snowballtools-base-backend-base:local + +WORKDIR /app/packages/backend +COPY run.sh . + +ENTRYPOINT ["./run.sh"] diff --git a/stack_orchestrator/data/container-build/cerc-snowballtools-base-backend/Dockerfile-base b/stack_orchestrator/data/container-build/cerc-snowballtools-base-backend/Dockerfile-base new file mode 100644 index 00000000..7a264ca3 --- /dev/null +++ b/stack_orchestrator/data/container-build/cerc-snowballtools-base-backend/Dockerfile-base @@ -0,0 +1,26 @@ +FROM ubuntu:22.04 as builder + +RUN apt update && \ + apt install -y --no-install-recommends --no-install-suggests \ + ca-certificates curl gnupg + +# Node +ARG NODE_MAJOR=20 +RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \ + echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \ + apt update && apt install -y nodejs + +# npm setup +RUN npm config set @cerc-io:registry https://git.vdb.to/api/packages/cerc-io/npm/ && npm install -g yarn + +COPY . /app/ +WORKDIR /app/ + +RUN find . -name 'node_modules' | xargs -n1 rm -rf +RUN yarn && yarn build --ignore frontend + +FROM cerc/webapp-base:local + +COPY --from=builder /app /app + +WORKDIR /app/packages/backend diff --git a/stack_orchestrator/data/container-build/cerc-snowballtools-base-backend/build.sh b/stack_orchestrator/data/container-build/cerc-snowballtools-base-backend/build.sh new file mode 100755 index 00000000..4f7c7cdc --- /dev/null +++ b/stack_orchestrator/data/container-build/cerc-snowballtools-base-backend/build.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# Build cerc/webapp-deployer-backend + +source ${CERC_CONTAINER_BASE_DIR}/build-base.sh + +# See: https://stackoverflow.com/a/246128/1701505 +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +docker build -t cerc/snowballtools-base-backend-base:local ${build_command_args} -f ${SCRIPT_DIR}/Dockerfile-base ${CERC_REPO_BASE_DIR}/snowballtools-base +docker build -t cerc/snowballtools-base-backend:local ${build_command_args} ${SCRIPT_DIR} diff --git a/stack_orchestrator/data/container-build/cerc-snowballtools-base-backend/run.sh b/stack_orchestrator/data/container-build/cerc-snowballtools-base-backend/run.sh new file mode 100755 index 00000000..ae14ed19 --- /dev/null +++ b/stack_orchestrator/data/container-build/cerc-snowballtools-base-backend/run.sh @@ -0,0 +1,19 @@ +#!/bin/bash + + +LACONIC_HOSTED_CONFIG_FILE=${LACONIC_HOSTED_CONFIG_FILE} +if [ -z "${LACONIC_HOSTED_CONFIG_FILE}" ]; then + if [ -f "/config/laconic-hosted-config.yml" ]; then + LACONIC_HOSTED_CONFIG_FILE="/config/laconic-hosted-config.yml" + elif [ -f "/config/config.yml" ]; then + LACONIC_HOSTED_CONFIG_FILE="/config/config.yml" + fi +fi + +if [ -f "${LACONIC_HOSTED_CONFIG_FILE}" ]; then + /scripts/apply-webapp-config.sh $LACONIC_HOSTED_CONFIG_FILE "`pwd`/dist" +fi + +/scripts/apply-runtime-env.sh "`pwd`/dist" + +yarn start diff --git a/stack_orchestrator/data/container-build/cerc-webapp-base/Dockerfile b/stack_orchestrator/data/container-build/cerc-webapp-base/Dockerfile index 331e04a1..9ae166b0 100644 --- a/stack_orchestrator/data/container-build/cerc-webapp-base/Dockerfile +++ b/stack_orchestrator/data/container-build/cerc-webapp-base/Dockerfile @@ -43,7 +43,6 @@ COPY scripts /scripts # RUN su node -c "npm install -g " RUN mkdir -p /config -COPY ./config.yml /config # Install simple web server for now (use nginx perhaps later) RUN yarn global add http-server diff --git a/stack_orchestrator/data/container-build/cerc-webapp-base/config.yml b/stack_orchestrator/data/container-build/cerc-webapp-base/config.yml deleted file mode 100644 index c69b6752..00000000 --- a/stack_orchestrator/data/container-build/cerc-webapp-base/config.yml +++ /dev/null @@ -1 +0,0 @@ -# Put config here. diff --git a/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/start-serving-app.sh b/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/start-serving-app.sh index 365d05fb..f9aa2c33 100755 --- a/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/start-serving-app.sh +++ b/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/start-serving-app.sh @@ -10,6 +10,18 @@ if [ "true" == "$CERC_ENABLE_CORS" ]; then CERC_HTTP_EXTRA_ARGS="$CERC_HTTP_EXTRA_ARGS --cors" fi -/scripts/apply-webapp-config.sh /config/config.yml ${CERC_WEBAPP_FILES_DIR} +LACONIC_HOSTED_CONFIG_FILE=${LACONIC_HOSTED_CONFIG_FILE} +if [ -z "${LACONIC_HOSTED_CONFIG_FILE}" ]; then + if [ -f "/config/laconic-hosted-config.yml" ]; then + LACONIC_HOSTED_CONFIG_FILE="/config/laconic-hosted-config.yml" + elif [ -f "/config/config.yml" ]; then + LACONIC_HOSTED_CONFIG_FILE="/config/config.yml" + fi +fi + +if [ -f "${LACONIC_HOSTED_CONFIG_FILE}" ]; then + /scripts/apply-webapp-config.sh $LACONIC_HOSTED_CONFIG_FILE ${CERC_WEBAPP_FILES_DIR} +fi + /scripts/apply-runtime-env.sh ${CERC_WEBAPP_FILES_DIR} http-server $CERC_HTTP_EXTRA_ARGS -p ${CERC_LISTEN_PORT:-80} ${CERC_WEBAPP_FILES_DIR} diff --git a/stack_orchestrator/data/stacks/snowballtools-base-backend/stack.yml b/stack_orchestrator/data/stacks/snowballtools-base-backend/stack.yml new file mode 100644 index 00000000..3ee19b05 --- /dev/null +++ b/stack_orchestrator/data/stacks/snowballtools-base-backend/stack.yml @@ -0,0 +1,10 @@ +version: "1.0" +name: snowballtools-base-backend +description: "snowballtools-base-backend" +repos: + - github.com/snowball-tools/snowballtools-base +containers: + - cerc/webapp-base + - cerc/snowballtools-base-backend +pods: + - snowballtools-base-backend