Skip to content

Commit 7155d1a

Browse files
authored
feat: Enhance Script Details and Add MacOS Compatibility with Documentation Updates (#1794)
* feat: fix a portion of get path * feat: optimize mac deployment scripts
1 parent 9071047 commit 7155d1a

File tree

10 files changed

+138
-24
lines changed

10 files changed

+138
-24
lines changed

.devcontainer/devcontainer.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@
66
"build": { "dockerfile": "Dockerfile" },
77
// Replace with uncommented line below to build your own local copy of the image
88
// "dockerFile": "../docker/Dockerfile-dev",
9-
"containerEnv": {
10-
// Uncomment to overwrite devcontainer .kube/config and .minikube certs with the localhost versions
11-
// each time the devcontainer starts, if the respective .kube-localhost/config and .minikube-localhost
12-
// folders respectively are bind mounted to the devcontainer.
13-
// "SYNC_LOCALHOST_KUBECONFIG": "true"
14-
15-
// Uncomment to disable docker-in-docker and automatically proxy default /var/run/docker.sock to
16-
// the localhost bind-mount /var/run/docker-host.sock.
17-
// "BIND_LOCALHOST_DOCKER": "true"
18-
},
199
"remoteEnv": {
2010
"GO111MODULE": "on",
2111
"GOPROXY": "https://goproxy.cn",

assets/colors.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Official Colors
2+
3+
The openim logo has an official blue color. When reproducing the logo, please use the official color, when possible.
4+
5+
## Pantone
6+
7+
When possible, the Pantone color is preferred for print material. The official Pantone color is *285C*.
8+
9+
## RGB
10+
11+
When used digitally, the official RGB color code is *#326CE5*.

pkg/common/config/parse.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"gopkg.in/yaml.v3"
2525

2626
"github.com/openimsdk/open-im-server/v3/pkg/msgprocessor"
27+
"github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
2728
)
2829

2930
//go:embed version
@@ -37,19 +38,30 @@ const (
3738

3839
// return absolude path join ../config/, this is k8s container config path.
3940
func GetDefaultConfigPath() string {
40-
b, err := filepath.Abs(os.Args[0])
41+
executablePath, err := os.Executable()
4142
if err != nil {
42-
fmt.Println("filepath.Abs error,err=", err)
43+
fmt.Println("GetDefaultConfigPath error:", err.Error())
4344
return ""
4445
}
45-
return filepath.Join(filepath.Dir(b), "../config/")
46+
47+
configPath, err := genutil.OutDir(filepath.Join(filepath.Dir(executablePath), "../config/"))
48+
if err != nil {
49+
fmt.Fprintf(os.Stderr, "failed to get output directory: %v\n", err)
50+
os.Exit(1)
51+
}
52+
return configPath
4653
}
4754

4855
// getProjectRoot returns the absolute path of the project root directory.
4956
func GetProjectRoot() string {
50-
b, _ := filepath.Abs(os.Args[0])
57+
executablePath, _ := os.Executable()
5158

52-
return filepath.Join(filepath.Dir(b), "../../../../..")
59+
projectRoot, err := genutil.OutDir(filepath.Join(filepath.Dir(executablePath), "../../../../.."))
60+
if err != nil {
61+
fmt.Fprintf(os.Stderr, "failed to get output directory: %v\n", err)
62+
os.Exit(1)
63+
}
64+
return projectRoot
5365
}
5466

5567
func GetOptionsByNotification(cfg NotificationConf) msgprocessor.Options {

pkg/util/flag/flag.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package flag
2+
3+
import (
4+
goFlag "flag"
5+
"log"
6+
"strings"
7+
8+
"github.com/spf13/pflag"
9+
)
10+
11+
// WordSepNormalizeFunc changes all flags that contain "_" separators.
12+
func WordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName {
13+
if strings.Contains(name, "_") {
14+
return pflag.NormalizedName(strings.ReplaceAll(name, "_", "-"))
15+
}
16+
return pflag.NormalizedName(name)
17+
}
18+
19+
// WarnWordSepNormalizeFunc changes and warns for flags that contain "_" separators.
20+
func WarnWordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName {
21+
if strings.Contains(name, "_") {
22+
normalizedName := strings.ReplaceAll(name, "_", "-")
23+
log.Printf("WARNING: flag %s has been deprecated and will be removed in a future version. Use %s instead.", name, normalizedName)
24+
return pflag.NormalizedName(normalizedName)
25+
}
26+
return pflag.NormalizedName(name)
27+
}
28+
29+
// InitFlags normalizes, parses, then logs the command line flags.
30+
func InitFlags() {
31+
pflag.CommandLine.SetNormalizeFunc(WordSepNormalizeFunc)
32+
pflag.CommandLine.AddGoFlagSet(goFlag.CommandLine)
33+
}
34+
35+
// PrintFlags logs the flags in the flagset.
36+
func PrintFlags(flags *pflag.FlagSet) {
37+
flags.VisitAll(func(flag *pflag.Flag) {
38+
log.Printf("FLAG: --%s=%q", flag.Name, flag.Value)
39+
})
40+
}

pkg/util/genutil/genutil.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package genutil
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"path/filepath"
7+
)
8+
9+
// OutDir creates the absolute path name from path and checks path exists.
10+
// Returns absolute path including trailing '/' or error if path does not exist.
11+
func OutDir(path string) (string, error) {
12+
outDir, err := filepath.Abs(path)
13+
if err != nil {
14+
return "", err
15+
}
16+
17+
stat, err := os.Stat(outDir)
18+
if err != nil {
19+
return "", err
20+
}
21+
22+
if !stat.IsDir() {
23+
return "", fmt.Errorf("output directory %s is not a directory", outDir)
24+
}
25+
outDir += "/"
26+
return outDir, nil
27+
}

pkg/util/genutil/genutil_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package genutil
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestValidDir(t *testing.T) {
8+
_, err := OutDir("./")
9+
if err != nil {
10+
t.Fatal(err)
11+
}
12+
}
13+
14+
func TestInvalidDir(t *testing.T) {
15+
_, err := OutDir("./nondir")
16+
if err == nil {
17+
t.Fatal("expected an error")
18+
}
19+
}
20+
21+
func TestNotDir(t *testing.T) {
22+
_, err := OutDir("./genutils_test.go")
23+
if err == nil {
24+
t.Fatal("expected an error")
25+
}
26+
}

scripts/docker-start-all.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ openim::log::info "\n# Use Docker to start all openim service"
2828

2929
trap 'openim::util::onCtrlC' INT
3030

31-
"${OPENIM_ROOT}"/scripts/init-config.sh --skip
32-
3331
"${OPENIM_ROOT}"/scripts/start-all.sh
3432

3533
sleep 5

scripts/install/openim-msgtransfer.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15+
# Use:
16+
# ./scripts/install/openim-msgtransfer.sh openim::msgtransfer::start
1517

1618
# Common utilities, variables and checks for all build scripts.
1719
set -o errexit
@@ -64,15 +66,20 @@ function openim::msgtransfer::check() {
6466
PIDS=$(pgrep -f "${OPENIM_OUTPUT_HOSTBIN}/openim-msgtransfer")
6567

6668
NUM_PROCESSES=$(echo "$PIDS" | wc -l)
67-
# NUM_PROCESSES=$(($NUM_PROCESSES - 1))
6869

6970
if [ "$NUM_PROCESSES" -eq "$OPENIM_MSGGATEWAY_NUM" ]; then
70-
openim::log::info "Found $OPENIM_MSGGATEWAY_NUM processes named $OPENIM_OUTPUT_HOSTBIN"
71-
for PID in $PIDS; do
72-
ps -p $PID -o pid,cmd
73-
done
71+
openim::log::info "Found $OPENIM_MSGGATEWAY_NUM processes named $OPENIM_OUTPUT_HOSTBIN"
72+
for PID in $PIDS; do
73+
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
74+
ps -p $PID -o pid,cmd
75+
elif [[ "$OSTYPE" == "darwin"* ]]; then
76+
ps -p $PID -o pid,comm
77+
else
78+
openim::log::error "Unsupported OS type: $OSTYPE"
79+
fi
80+
done
7481
else
75-
openim::log::error_exit "Expected $OPENIM_MSGGATEWAY_NUM openim msgtransfer processes, but found $NUM_PROCESSES msgtransfer processes."
82+
openim::log::error_exit "Expected $OPENIM_MSGGATEWAY_NUM openim msgtransfer processes, but found $NUM_PROCESSES msgtransfer processes."
7683
fi
7784
}
7885

scripts/install/openim-rpc.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,13 @@ function openim::rpc::start() {
123123
for ((i = 0; i < ${#OPENIM_RPC_SERVICE_LISTARIES[*]}; i++)); do
124124
# openim::util::stop_services_with_name ${OPENIM_RPC_SERVICE_LISTARIES
125125
openim::util::stop_services_on_ports ${OPENIM_RPC_PORT_LISTARIES[$i]}
126+
126127
openim::log::info "OpenIM ${OPENIM_RPC_SERVICE_LISTARIES[$i]} config path: ${OPENIM_RPC_CONFIG}"
127128

128129
# Get the service and Prometheus ports.
129130
OPENIM_RPC_SERVICE_PORTS=( $(openim::util::list-to-string ${OPENIM_RPC_PORT_LISTARIES[$i]}) )
130131
read -a OPENIM_RPC_SERVICE_PORTS_ARRAY <<< ${OPENIM_RPC_SERVICE_PORTS}
131-
132+
132133
OPENIM_RPC_PROM_PORTS=( $(openim::util::list-to-string ${OPENIM_RPC_PROM_PORT_LISTARIES[$i]}) )
133134
read -a OPENIM_RPC_PROM_PORTS_ARRAY <<< ${OPENIM_RPC_PROM_PORTS}
134135

scripts/start-all.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ if [[ $? -ne 0 ]]; then
3232
fi
3333
set -o errexit
3434

35+
"${OPENIM_ROOT}"/scripts/init-config.sh --skip
36+
3537
echo "You need to start the following scripts in order: ${OPENIM_SERVER_SCRIPTARIES[@]}"
3638
openim::log::install_errexit
3739

0 commit comments

Comments
 (0)