2022-07-14 12:17:00 +00:00
#!/usr/bin/env bash
set -o errexit
display_help( )
{
echo "---------------------------------------------------------------------------------------"
echo "Use this script to run a local instance of Appsmith on port 80."
echo "The script will build all the artefacts required for a fat Docker container to come up."
echo "If no argument is given, the build defaults to release branch."
2022-09-27 15:40:17 +00:00
echo "If --local or -l is passed, it will build with local changes"
2022-07-14 12:17:00 +00:00
echo "---------------------------------------------------------------------------------------"
echo
2024-12-06 05:19:27 +00:00
echo " Syntax: $0 [-h] [-l] [-r [remote_url]] [branch_name] [tag] [cs_url] "
2022-07-14 12:17:00 +00:00
echo "options:"
2022-11-16 00:11:05 +00:00
echo "-h Print this help"
echo "-l or --local Use the local codebase and not git"
echo "-r or --remote Use the branch from a remote repository"
echo "For more info please check: https://www.notion.so/appsmith/Test-an-Appsmith-branch-locally-c39ad68aea0d42bf94a149ea22e86820#9cee16c7e2054b5980513ec6f351ace2"
2022-07-14 12:17:00 +00:00
echo
}
pretty_print( )
{
echo "----------------"
echo $1
echo "----------------"
echo
}
# Check whether user had supplied -h or --help. If yes display usage
if [ [ ( $@ = = "--help" ) || $@ = = "-h" ] ]
2023-08-02 06:16:28 +00:00
then
2022-07-14 12:17:00 +00:00
display_help
exit 0
2022-09-27 15:40:17 +00:00
fi
LOCAL = false
2023-08-02 06:16:28 +00:00
if [ [ ( $1 = = "--local" || $1 = = "-l" ) ] ]
2022-09-27 15:40:17 +00:00
then
LOCAL = true
fi
2022-07-14 12:17:00 +00:00
2022-11-16 00:11:05 +00:00
REMOTE = false
if [ [ ( $1 = = "--remote" || $1 = = "-r" ) ] ]
then
REMOTE = true
fi
2022-07-14 12:17:00 +00:00
2022-09-27 15:40:17 +00:00
if [ [ ( $LOCAL = = true ) ] ]
then
pretty_print "Setting up instance with local changes"
2022-11-16 00:11:05 +00:00
BRANCH = release
2024-12-06 05:19:27 +00:00
tag = $2
cs_url = $3
2022-11-16 00:11:05 +00:00
elif [ [ ( $REMOTE = = true ) ] ]
then
2023-08-02 06:16:28 +00:00
pretty_print "Setting up instance with remote repository branch ..."
2022-11-16 00:11:05 +00:00
REMOTE_REPOSITORY_URL = $2
REMOTE_BRANCH = $3
2024-12-06 05:19:27 +00:00
tag = $4
2023-08-02 06:16:28 +00:00
pretty_print "Please ignore if the following error occurs: remote remote_origin_for_local_test already exists."
2022-11-16 00:11:05 +00:00
git remote add remote_origin_for_local_test $REMOTE_REPOSITORY_URL || git remote set-url remote_origin_for_local_test $REMOTE_REPOSITORY_URL
2023-08-02 06:16:28 +00:00
git fetch remote_origin_for_local_test
2022-11-16 00:11:05 +00:00
git checkout $REMOTE_BRANCH
git pull remote_origin_for_local_test $REMOTE_BRANCH
2022-09-27 15:40:17 +00:00
else
2022-11-16 00:11:05 +00:00
BRANCH = $1
2024-12-06 05:19:27 +00:00
tag = $2
cs_url = $3
2022-09-27 15:40:17 +00:00
pretty_print " Setting up instance to run on branch: $BRANCH "
cd " $( dirname " $0 " ) " /..
git fetch origin $BRANCH
git checkout $BRANCH
git pull origin $BRANCH
pretty_print "Local branch is now up to date. Starting server build ..."
fi
2024-12-06 05:19:27 +00:00
if [ [ -z " $tag " ] ] ; then
tag = latest
fi
pretty_print " Building Appsmith with tag: $tag "
2023-10-18 14:07:42 +00:00
edition = ce
if [ [ " $( git remote get-url origin) " = = *"/appsmith-ee" * ] ] ; then
edition = ee
fi
2022-09-27 15:40:17 +00:00
pretty_print "Starting server build ..."
2022-07-14 12:17:00 +00:00
2024-06-04 11:03:40 +00:00
pushd app/server > /dev/null
if ! ./build.sh -DskipTests > /dev/null; then
echo Server build failed >& 2
exit 1
fi
2024-09-19 16:15:46 +00:00
popd
./scripts/prepare_server_artifacts.sh
2024-06-04 11:03:40 +00:00
pretty_print "Server build successful. Starting client build ..."
2022-07-14 12:17:00 +00:00
2024-06-04 11:03:40 +00:00
pushd app/client > /dev/null
yarn > /dev/null
if ! yarn build > /dev/null; then
echo Client build failed >& 2
exit 1
fi
pretty_print "Client build successful. Starting RTS build ..."
2022-07-14 12:17:00 +00:00
popd
2024-06-04 11:03:40 +00:00
pushd app/client/packages/rts/ > /dev/null
if ! ./build.sh > /dev/null; then
echo RTS build failed >& 2
exit 1
fi
pretty_print "RTS build successful. Starting Docker build ..."
2022-07-14 12:17:00 +00:00
popd
2024-06-04 11:03:40 +00:00
bash " $( dirname " $0 " ) /generate_info_json.sh "
2024-12-06 05:19:27 +00:00
docker build -t appsmith/appsmith-local-$edition :$tag \
2023-10-18 14:07:42 +00:00
--build-arg BASE = " appsmith/base- $edition :release " \
--build-arg APPSMITH_CLOUD_SERVICES_BASE_URL = " ${ cs_url :- https : //release-cs.appsmith.com } " \
. \
> /dev/null
2023-08-02 06:16:28 +00:00
pretty_print "Docker image build successful. Triggering run now ..."
2022-07-14 12:17:00 +00:00
( docker stop appsmith || true ) && ( docker rm appsmith || true )
2024-12-06 05:19:27 +00:00
docker run -d --name appsmith -p 80:80 -v " $PWD /stacks:/appsmith-stacks " appsmith/appsmith-local-$edition :$tag && sleep 15 && pretty_print "Local instance is up! Open Appsmith at http://localhost! "