mirror of https://github.com/zhufuyi/sponge
feat: the make run command supports specifying configuration file
This commit is contained in:
parent
ef814cf96a
commit
5c6f31aca7
8
Makefile
8
Makefile
|
@ -95,15 +95,15 @@ image-build-sponge:
|
|||
# delete the templates code end
|
||||
|
||||
.PHONY: run
|
||||
# Build and run service
|
||||
# Build and run service, you can specify the configuration file, e.g. make run Config=configs/dev.yml
|
||||
run:
|
||||
@bash scripts/run.sh
|
||||
@bash scripts/run.sh $(Config)
|
||||
|
||||
|
||||
.PHONY: run-nohup
|
||||
# Run service with nohup in local, if you want to stop the server, pass the parameter stop, e.g. make run-nohup CMD=stop
|
||||
# Run service with nohup in local, you can specify the configuration file, e.g. make run-nohup Config=configs/dev.yml, if you want to stop the server, pass the parameter stop, e.g. make run-nohup CMD=stop
|
||||
run-nohup:
|
||||
@bash scripts/run-nohup.sh $(CMD)
|
||||
@bash scripts/run-nohup.sh $(Config) $(CMD)
|
||||
|
||||
|
||||
.PHONY: run-docker
|
||||
|
|
|
@ -49,15 +49,15 @@ build:
|
|||
|
||||
|
||||
.PHONY: run
|
||||
# Build and run service
|
||||
# Build and run service, you can specify the configuration file, e.g. make run Config=configs/dev.yml
|
||||
run:
|
||||
@bash scripts/run.sh
|
||||
@bash scripts/run.sh $(Config)
|
||||
|
||||
|
||||
.PHONY: run-nohup
|
||||
# Run service with nohup in local, if you want to stop the server, pass the parameter stop, e.g. make run-nohup CMD=stop
|
||||
# Run service with nohup in local, you can specify the configuration file, e.g. make run-nohup Config=configs/dev.yml, if you want to stop the server, pass the parameter stop, e.g. make run-nohup CMD=stop
|
||||
run-nohup:
|
||||
@bash scripts/run-nohup.sh $(CMD)
|
||||
@bash scripts/run-nohup.sh $(Config) $(CMD)
|
||||
|
||||
|
||||
.PHONY: run-docker
|
||||
|
|
|
@ -93,17 +93,24 @@ function handlePbGoFiles(){
|
|||
cd ..
|
||||
}
|
||||
|
||||
function patchTypesPbFile() {
|
||||
for file in $allProtoFiles; do
|
||||
if [ "$file" = "api/types/types.proto" ]; then
|
||||
return
|
||||
fi
|
||||
if grep -q "api/types/types.proto" "$file"; then
|
||||
allProtoFiles=$allProtoFiles" api/types/types.proto"
|
||||
bash scripts/patch.sh types-pb
|
||||
return
|
||||
autoDetectTypesProto() {
|
||||
local target="api/types/types.proto"
|
||||
for file in "$@"; do
|
||||
if [ "$file" = "$target" ]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
for file in "$@"; do
|
||||
if grep -q "$target" "$file"; then
|
||||
allProtoFiles=$allProtoFiles" $target"
|
||||
sponge patch gen-types-pb --out=. > /dev/null 2>&1
|
||||
# Note: If the project uses mono-repo type, please manually move "api/types" directory to "../api/types"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
function autoDetectInitDbFile() {
|
||||
|
@ -118,7 +125,7 @@ function generateByAllProto(){
|
|||
allProtoFiles=$specifiedProtoFilePaths
|
||||
fi
|
||||
|
||||
patchTypesPbFile
|
||||
autoDetectTypesProto $allProtoFiles
|
||||
autoDetectInitDbFile
|
||||
|
||||
if [ "$allProtoFiles"x = x ];then
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
serverName="serverNameExample_mixExample"
|
||||
cmdStr="cmd/${serverName}/${serverName}"
|
||||
|
||||
configFile=$1
|
||||
|
||||
function checkResult() {
|
||||
result=$1
|
||||
|
@ -37,7 +37,13 @@ startService() {
|
|||
go build -o ${cmdStr} cmd/${NAME}/main.go
|
||||
checkResult $?
|
||||
|
||||
nohup ${cmdStr} > ${NAME}.log 2>&1 &
|
||||
# running server
|
||||
if test -f "$configFile"; then
|
||||
echo "Using config file: $configFile"
|
||||
nohup ${cmdStr} -c $configFile > ${NAME}.log 2>&1 &
|
||||
else
|
||||
nohup ${cmdStr} > ${NAME}.log 2>&1 &
|
||||
fi
|
||||
sleep 1
|
||||
|
||||
ID=`ps -ef | grep "$NAME" | grep -v "$0" | grep -v "grep" | awk '{print $2}'`
|
||||
|
@ -47,10 +53,9 @@ startService() {
|
|||
echo "Failed to start ${NAME} service"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
stopService ${serverName}
|
||||
if [ "$1"x != "stop"x ] ;then
|
||||
sleep 1
|
||||
|
|
|
@ -4,6 +4,8 @@ serverName="serverNameExample_mixExample"
|
|||
|
||||
binaryFile="cmd/${serverName}/${serverName}"
|
||||
|
||||
configFile=$1
|
||||
|
||||
osType=$(uname -s)
|
||||
if [ "${osType%%_*}"x = "MINGW64"x ];then
|
||||
binaryFile="${binaryFile}.exe"
|
||||
|
@ -26,4 +28,8 @@ go build -o ${binaryFile} cmd/${serverName}/main.go
|
|||
checkResult $?
|
||||
|
||||
# running server
|
||||
./${binaryFile}
|
||||
if test -f "$configFile"; then
|
||||
./${binaryFile} -c $configFile
|
||||
else
|
||||
./${binaryFile}
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue