Skip to content

Commit

Permalink
feat: update the project root path logic(The process is in the same s…
Browse files Browse the repository at this point in the history
…hell as the starting shell)
  • Loading branch information
WGrape committed Mar 4, 2024
1 parent e985dda commit a560048
Show file tree
Hide file tree
Showing 106 changed files with 194 additions and 215 deletions.
2 changes: 1 addition & 1 deletion .work/extra/service_example/hooks/after_start.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

# include sdk of sparrow.
source .work/include/sdk.sh
. .work/include/sdk.sh
2 changes: 1 addition & 1 deletion .work/extra/service_example/hooks/after_stop.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

# include sdk of sparrow.
source .work/include/sdk.sh
. .work/include/sdk.sh
2 changes: 1 addition & 1 deletion .work/extra/service_example/hooks/before_start.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

# include sdk of sparrow.
source .work/include/sdk.sh
. .work/include/sdk.sh
2 changes: 1 addition & 1 deletion .work/extra/service_example/hooks/before_stop.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

# include sdk of sparrow.
source .work/include/sdk.sh
. .work/include/sdk.sh
7 changes: 3 additions & 4 deletions .work/extra/service_example/make_app_image/run.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#!/bin/sh

# cd base dir of project.
CUR_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)
cd $CUR_PATH && cd ../../
BATH_PATH=$(pwd)
# the process is in the same shell as the starting shell.
cd $SPARROW_BASE_PATH

# define this service.
service_name="{{SERVICE}}"

print_stage "try to pull/build sparrow-basic-${service_name} $IMAGE_BASIC_{{SERVICE_UPPER}}_VERSION"
if pull basic $service_name $IMAGE_BASIC_{{SERVICE_UPPER}}_VERSION; then
print_info "pull success"
elif source "./${service_name}/make_basic_image/run.sh"; then
elif . "./${service_name}/make_basic_image/run.sh"; then
print_info "build success"
else
print_error "pull/build failed"
Expand Down
5 changes: 2 additions & 3 deletions .work/extra/service_example/make_basic_image/run.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/bin/sh

# cd base dir of project.
CUR_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)
cd $CUR_PATH && cd ../../
BATH_PATH=$(pwd)
# the process is in the same shell as the starting shell.
cd $SPARROW_BASE_PATH

# define this service.
service_name="{{SERVICE}}"
Expand Down
5 changes: 2 additions & 3 deletions .work/include/internal/constant.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/bin/sh

# cd base dir of project.
CUR_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)
cd $CUR_PATH && cd ../../../
BATH_PATH=$(pwd)
# the process is in the same shell as the starting shell.
cd $SPARROW_BASE_PATH

# only define variables, these variables may used defined environment variables in /env file.

Expand Down
5 changes: 2 additions & 3 deletions .work/include/internal/dockerhub.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/bin/sh

# cd base dir of project.
CUR_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)
cd $CUR_PATH && cd ../../../
BATH_PATH=$(pwd)
# the process is in the same shell as the starting shell.
cd $SPARROW_BASE_PATH

# login of $DOCKERHUB_DOMAIN.
# to be safety, never allow login with account in the command, you must login manually in your local system firstly.
Expand Down
7 changes: 3 additions & 4 deletions .work/include/internal/helper.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/bin/sh

# cd base dir of project.
CUR_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)
cd $CUR_PATH && cd ../../../
BATH_PATH=$(pwd)
# the process is in the same shell as the starting shell.
cd $SPARROW_BASE_PATH

# -----------------------define some basic helpers-----------------------

Expand Down Expand Up @@ -200,7 +199,7 @@ pull_or_build_app_image() {
version=$(eval echo "$"$version_name)
if pull app $service $version; then
print_info "pull success: pull app $service $version"
elif source "./$service/make_app_image/run.sh"; then
elif . "./$service/make_app_image/run.sh"; then
print_info "build success: run $service/make_app_image/run.sh"
else
print_error "pull and build sparrow-app-$service image error"
Expand Down
11 changes: 5 additions & 6 deletions .work/include/sdk.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#!/bin/sh

# cd base dir of project.
CUR_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)
cd $CUR_PATH && cd ../../
BATH_PATH=$(pwd)
# the process is in the same shell as the starting shell.
cd $SPARROW_BASE_PATH

# only include defined variables and functions.
# this is no side effects.
source .work/include/internal/constant.sh
source .work/include/internal/helper.sh
source .work/include/internal/dockerhub.sh
. .work/include/internal/constant.sh
. .work/include/internal/helper.sh
. .work/include/internal/dockerhub.sh

# update /env file and export env variables.
if ! upenv; then
Expand Down
2 changes: 1 addition & 1 deletion .work/tests/run.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

# include sdk of sparrow.
source .work/include/sdk.sh
. .work/include/sdk.sh

testhttp() {
if is_mac; then
Expand Down
11 changes: 7 additions & 4 deletions _install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
# To maintain consistency and facilitate management, the filenames of these scripts all use the underscore (_) prefix.
# _install.sh

# define the base path of project.
CUR_PATH=$(cd "$(dirname "$0")" && pwd)
SPARROW_BASE_PATH=$CUR_PATH

# cd base dir of project.
CUR_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)
cd $CUR_PATH
BATH_PATH=$(pwd)
# the process is in the same shell as the starting shell.
cd $SPARROW_BASE_PATH

# include sdk of sparrow.
source .work/include/sdk.sh
. .work/include/sdk.sh

# chmod files.
chmod_files() {
Expand Down
11 changes: 7 additions & 4 deletions _uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
# To maintain consistency and facilitate management, the filenames of these scripts all use the underscore (_) prefix.
# _uninstall.sh

# define the base path of project.
CUR_PATH=$(cd "$(dirname "$0")" && pwd)
SPARROW_BASE_PATH=$CUR_PATH

# cd base dir of project.
CUR_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)
cd $CUR_PATH
BATH_PATH=$(pwd)
# the process is in the same shell as the starting shell.
cd $SPARROW_BASE_PATH

# command interface.
read -p "do you want to uninstall?(input y): " confirmation
Expand All @@ -22,7 +25,7 @@ fi
# =================== choose sure ===================

# include sdk of sparrow.
source .work/include/sdk.sh
. .work/include/sdk.sh

# remove files.
remove_files() {
Expand Down
11 changes: 7 additions & 4 deletions _update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
# To maintain consistency and facilitate management, the filenames of these scripts all use the underscore (_) prefix.
# _update.sh

# define the base path of project.
CUR_PATH=$(cd "$(dirname "$0")" && pwd)
SPARROW_BASE_PATH=$CUR_PATH

# cd base dir of project.
CUR_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)
cd $CUR_PATH
BATH_PATH=$(pwd)
# the process is in the same shell as the starting shell.
cd $SPARROW_BASE_PATH

# include sdk of sparrow.
source .work/include/sdk.sh
. .work/include/sdk.sh

# update project.
update_project() {
Expand Down
2 changes: 1 addition & 1 deletion etcd/hooks/after_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# not need to include sdk of sparrow.
# because the execution of hook scripts must be within the sparrow script, sdk.sh has already been imported at this point.
# source .work/include/sdk.sh
# . .work/include/sdk.sh
2 changes: 1 addition & 1 deletion etcd/hooks/after_stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# not need to include sdk of sparrow.
# because the execution of hook scripts must be within the sparrow script, sdk.sh has already been imported at this point.
# source .work/include/sdk.sh
# . .work/include/sdk.sh
2 changes: 1 addition & 1 deletion etcd/hooks/before_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# not need to include sdk of sparrow.
# because the execution of hook scripts must be within the sparrow script, sdk.sh has already been imported at this point.
# source .work/include/sdk.sh
# . .work/include/sdk.sh
2 changes: 1 addition & 1 deletion etcd/hooks/before_stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# not need to include sdk of sparrow.
# because the execution of hook scripts must be within the sparrow script, sdk.sh has already been imported at this point.
# source .work/include/sdk.sh
# . .work/include/sdk.sh
7 changes: 3 additions & 4 deletions etcd/make_app_image/run.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#!/bin/sh

# cd base dir of project.
CUR_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)
cd $CUR_PATH && cd ../../
BATH_PATH=$(pwd)
# the process is in the same shell as the starting shell.
cd $SPARROW_BASE_PATH

# define this service.
service_name="etcd"

print_stage "try to pull/build sparrow-basic-${service_name} $IMAGE_BASIC_ETCD_VERSION"
if pull basic $service_name $IMAGE_BASIC_ETCD_VERSION; then
print_info "pull success"
elif source "./${service_name}/make_basic_image/run.sh"; then
elif . "./${service_name}/make_basic_image/run.sh"; then
print_info "build success"
else
print_error "pull/build failed"
Expand Down
5 changes: 2 additions & 3 deletions etcd/make_basic_image/run.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/bin/sh

# cd base dir of project.
CUR_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)
cd $CUR_PATH && cd ../../
BATH_PATH=$(pwd)
# the process is in the same shell as the starting shell.
cd $SPARROW_BASE_PATH

# define this service.
service_name="etcd"
Expand Down
2 changes: 1 addition & 1 deletion etcdkeeper/hooks/after_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# not need to include sdk of sparrow.
# because the execution of hook scripts must be within the sparrow script, sdk.sh has already been imported at this point.
# source .work/include/sdk.sh
# . .work/include/sdk.sh
2 changes: 1 addition & 1 deletion etcdkeeper/hooks/after_stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# not need to include sdk of sparrow.
# because the execution of hook scripts must be within the sparrow script, sdk.sh has already been imported at this point.
# source .work/include/sdk.sh
# . .work/include/sdk.sh
2 changes: 1 addition & 1 deletion etcdkeeper/hooks/before_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# not need to include sdk of sparrow.
# because the execution of hook scripts must be within the sparrow script, sdk.sh has already been imported at this point.
# source .work/include/sdk.sh
# . .work/include/sdk.sh
2 changes: 1 addition & 1 deletion etcdkeeper/hooks/before_stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# not need to include sdk of sparrow.
# because the execution of hook scripts must be within the sparrow script, sdk.sh has already been imported at this point.
# source .work/include/sdk.sh
# . .work/include/sdk.sh
7 changes: 3 additions & 4 deletions etcdkeeper/make_app_image/run.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#!/bin/sh

# cd base dir of project.
CUR_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)
cd $CUR_PATH && cd ../../
BATH_PATH=$(pwd)
# the process is in the same shell as the starting shell.
cd $SPARROW_BASE_PATH

# define this service.
service_name="etcdkeeper"

print_stage "try to pull/build sparrow-basic-${service_name} $IMAGE_BASIC_ETCDKEEPER_VERSION"
if pull basic $service_name $IMAGE_BASIC_ETCDKEEPER_VERSION; then
print_info "pull success"
elif source "./${service_name}/make_basic_image/run.sh"; then
elif . "./${service_name}/make_basic_image/run.sh"; then
print_info "build success"
else
print_error "pull/build failed"
Expand Down
5 changes: 2 additions & 3 deletions etcdkeeper/make_basic_image/run.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/bin/sh

# cd base dir of project.
CUR_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)
cd $CUR_PATH && cd ../../
BATH_PATH=$(pwd)
# the process is in the same shell as the starting shell.
cd $SPARROW_BASE_PATH

# define this service.
service_name="etcdkeeper"
Expand Down
2 changes: 1 addition & 1 deletion go/hooks/after_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# not need to include sdk of sparrow.
# because the execution of hook scripts must be within the sparrow script, sdk.sh has already been imported at this point.
# source .work/include/sdk.sh
# . .work/include/sdk.sh
2 changes: 1 addition & 1 deletion go/hooks/after_stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# not need to include sdk of sparrow.
# because the execution of hook scripts must be within the sparrow script, sdk.sh has already been imported at this point.
# source .work/include/sdk.sh
# . .work/include/sdk.sh
2 changes: 1 addition & 1 deletion go/hooks/before_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# not need to include sdk of sparrow.
# because the execution of hook scripts must be within the sparrow script, sdk.sh has already been imported at this point.
# source .work/include/sdk.sh
# . .work/include/sdk.sh

if [ ! -d "$GO_PATH" ]; then
if ! mkdir -p "$GO_PATH"; then
Expand Down
2 changes: 1 addition & 1 deletion go/hooks/before_stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# not need to include sdk of sparrow.
# because the execution of hook scripts must be within the sparrow script, sdk.sh has already been imported at this point.
# source .work/include/sdk.sh
# . .work/include/sdk.sh
7 changes: 3 additions & 4 deletions go/make_app_image/run.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#!/bin/sh

# cd base dir of project.
CUR_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)
cd $CUR_PATH && cd ../../
BATH_PATH=$(pwd)
# the process is in the same shell as the starting shell.
cd $SPARROW_BASE_PATH

# define this service.
service_name="go"

print_stage "try to pull/build sparrow-basic-${service_name} $IMAGE_BASIC_GO_VERSION"
if pull basic $service_name $IMAGE_BASIC_GO_VERSION; then
print_info "pull success"
elif source "./${service_name}/make_basic_image/run.sh"; then
elif . "./${service_name}/make_basic_image/run.sh"; then
print_info "build success"
else
print_error "pull/build failed"
Expand Down
5 changes: 2 additions & 3 deletions go/make_basic_image/run.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/bin/sh

# cd base dir of project.
CUR_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)
cd $CUR_PATH && cd ../../
BATH_PATH=$(pwd)
# the process is in the same shell as the starting shell.
cd $SPARROW_BASE_PATH

# define this service.
service_name="go"
Expand Down
2 changes: 1 addition & 1 deletion jupyter/hooks/after_start.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

# include sdk of sparrow.
source .work/include/sdk.sh
. .work/include/sdk.sh
2 changes: 1 addition & 1 deletion jupyter/hooks/after_stop.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

# include sdk of sparrow.
source .work/include/sdk.sh
. .work/include/sdk.sh
2 changes: 1 addition & 1 deletion jupyter/hooks/before_start.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

# include sdk of sparrow.
source .work/include/sdk.sh
. .work/include/sdk.sh
2 changes: 1 addition & 1 deletion jupyter/hooks/before_stop.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

# include sdk of sparrow.
source .work/include/sdk.sh
. .work/include/sdk.sh
Loading

0 comments on commit a560048

Please sign in to comment.