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: Make images adaptable to support both Postgres and MongoDB uris #36424

Merged
merged 4 commits into from
Sep 19, 2024
Merged
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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[{*.java,pom.xml,*.py}]
[{*.java,pom.xml,*.py,*.sql}]
indent_size = 4
6 changes: 6 additions & 0 deletions .github/workflows/build-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ jobs:
if [[ -f scripts/generate_info_json.sh ]]; then
scripts/generate_info_json.sh
fi

- name: Place server artifacts-es
env:
EDITION: ${{ vars.EDITION }}
run: |
scripts/prepare_server_artifacts.sh

- name: Set base image tag
id: set_base_tag
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
stacks
/deploy/docker/fs/opt/appsmith/info.json

# Server artifacts
/deploy/docker/fs/opt/appsmith/server

# to ignore the node_modeules folder
node_modules
# to ignore the package-lock.json file
Expand Down Expand Up @@ -36,3 +39,5 @@ app/client/.fleet/*
# Observability related local storage
utils/observability/tempo-data/*

# Ignore the mongo data backup directory for Mongo to PG migrations
mongo-data**
20 changes: 11 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ FROM ${BASE}

ENV IN_DOCKER=1

# Add backend server - Application Layer
ARG JAR_FILE=./app/server/dist/server-*.jar
ARG PLUGIN_JARS=./app/server/dist/plugins/*.jar

ARG APPSMITH_CLOUD_SERVICES_BASE_URL
ENV APPSMITH_CLOUD_SERVICES_BASE_URL=${APPSMITH_CLOUD_SERVICES_BASE_URL}

Expand All @@ -16,7 +12,17 @@ ENV APPSMITH_SEGMENT_CE_KEY=${APPSMITH_SEGMENT_CE_KEY}
COPY deploy/docker/fs /

RUN <<END
mkdir -p ./editor ./rts ./backend/plugins
if ! [ -f info.json ]; then
echo "Missing info.json" >&2
exit 1
fi

if ! [ -f server/mongo/server.jar && -f server/pg/server.jar ]; then
echo "Missing one or both server.jar files in the right place. Are you using the build script?" >&2
exit 1
fi

mkdir -p ./editor ./rts

# Ensure all *.sh scripts are executable.
find . -name node_modules -prune -or -type f -name '*.sh' -print -exec chmod +x '{}' ';'
Expand All @@ -25,10 +31,6 @@ RUN <<END
chmod +x /opt/bin/*
END

#Add the jar to the container
COPY ${JAR_FILE} backend/server.jar
COPY ${PLUGIN_JARS} backend/plugins/

# Add client UI - Application Layer
COPY ./app/client/build editor/

Expand Down
5 changes: 1 addition & 4 deletions deploy/docker/fs/opt/appsmith/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ configure_supervisord() {

# Disable services based on configuration
if [[ -z "${DYNO}" ]]; then
if [[ $isUriLocal -eq 0 ]]; then
if [[ $isUriLocal -eq 0 && $isMongoUrl -eq 1 ]]; then
cp "$supervisord_conf_source/mongodb.conf" "$SUPERVISORD_CONF_TARGET"
fi
if [[ $APPSMITH_REDIS_URL == *"localhost"* || $APPSMITH_REDIS_URL == *"127.0.0.1"* ]]; then
Expand Down Expand Up @@ -508,9 +508,6 @@ if [[ -z "${DYNO}" ]]; then
tlog "Initializing MongoDB"
init_mongodb
init_replica_set
elif [[ $isPostgresUrl -eq 1 ]]; then
tlog "Initializing Postgres"
# init_postgres
fi
else
# These functions are used to limit heap size for Backend process when deployed on Heroku
Expand Down
8 changes: 8 additions & 0 deletions deploy/docker/fs/opt/appsmith/run-java.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ set -o pipefail
set -o nounset
set -o noglob

mode=mongo
if [[ "$APPSMITH_DB_URL" = postgresql://* ]]; then
mode=pg
fi

tlog "Running with $mode."
cd "/opt/appsmith/server/$mode"

declare -a extra_args
proxy_configured=0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[program:backend]
directory=/opt/appsmith/backend
command=/opt/appsmith/run-with-env.sh /opt/appsmith/run-java.sh
priority=20
autostart=true
Expand Down
3 changes: 2 additions & 1 deletion scripts/local_testing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ if ! ./build.sh -DskipTests > /dev/null; then
echo Server build failed >&2
exit 1
fi
popd
./scripts/prepare_server_artifacts.sh
pretty_print "Server build successful. Starting client build ..."

popd
pushd app/client > /dev/null
yarn > /dev/null
if ! yarn build > /dev/null; then
Expand Down
28 changes: 28 additions & 0 deletions scripts/prepare_server_artifacts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash -eux

cd "$(git rev-parse --show-toplevel)"

if [[ -z "${EDITION-}" ]]; then
export EDITION=ce
if [[ "$(git remote get-url origin)" == *appsmithorg/appsmith-ee* ]]; then
export EDITION=ee
fi
fi

PG_TAG="${PG_TAG-pg}"
echo "Will be copying pg server artifacts from appsmith-$EDITION:$PG_TAG"

target="deploy/docker/fs/opt/appsmith/server"
mkdir -p "$target"
rm -rf "$target"/{pg,mongo}

cp -r "app/server/dist" "$target/mongo"
mv "$target/mongo"/server-*.jar "$target/mongo/server.jar"

# Grab PostgreSQL server artifacts from Docker image.
image="appsmith/appsmith-$EDITION:$PG_TAG"
docker run --name xx --detach --entrypoint sleep "$image" infinity
docker cp xx:/opt/appsmith/server/pg "$target/pg"
docker cp xx:/opt/appsmith/info.json "$target/pg/source-info.json"
docker rm --force xx
docker image rm "$image"
Loading