Skip to content

Commit

Permalink
feat: Make images adaptable to support both Postgres and MongoDB uris (
Browse files Browse the repository at this point in the history
…#36424)

## Description
PR to make the release tag adaptable to work with both MongoDB and
PostgreSQL uris.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced a new script to automate the preparation of server
artifacts, improving the build process.
- Added SQL files to the indentation configuration for consistent code
formatting.

- **Improvements**
- Enhanced error handling in the Docker build process to ensure
essential files are present before execution.
- Updated service configuration logic to prevent misconfiguration based
on the environment.
- Added a new job step in the build workflow to prepare server artifacts
after the build process.
- Implemented conditional logic in the run script to dynamically adapt
to different database configurations.

- **Bug Fixes**
- Adjusted the initialization process to focus on MongoDB, improving
reliability in various environments.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

/test Sanity

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10940528231>
> Commit: 32731e8
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10940528231&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity`
> Spec:
> <hr>Thu, 19 Sep 2024 12:21:54 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No
  • Loading branch information
abhvsn authored Sep 19, 2024
1 parent c76e6c0 commit 6ca9ef5
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 16 deletions.
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"

0 comments on commit 6ca9ef5

Please sign in to comment.