Skip to content

Commit

Permalink
feat: Enhance Script Details and Add MacOS Compatibility with Documen…
Browse files Browse the repository at this point in the history
…tation Updates (#1794)

* feat: fix a portion of get path

* feat: optimize mac deployment scripts
  • Loading branch information
cubxxw authored Jan 21, 2024
1 parent 9071047 commit 7155d1a
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 24 deletions.
10 changes: 0 additions & 10 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@
"build": { "dockerfile": "Dockerfile" },
// Replace with uncommented line below to build your own local copy of the image
// "dockerFile": "../docker/Dockerfile-dev",
"containerEnv": {
// Uncomment to overwrite devcontainer .kube/config and .minikube certs with the localhost versions
// each time the devcontainer starts, if the respective .kube-localhost/config and .minikube-localhost
// folders respectively are bind mounted to the devcontainer.
// "SYNC_LOCALHOST_KUBECONFIG": "true"

// Uncomment to disable docker-in-docker and automatically proxy default /var/run/docker.sock to
// the localhost bind-mount /var/run/docker-host.sock.
// "BIND_LOCALHOST_DOCKER": "true"
},
"remoteEnv": {
"GO111MODULE": "on",
"GOPROXY": "https://goproxy.cn",
Expand Down
11 changes: 11 additions & 0 deletions assets/colors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Official Colors

The openim logo has an official blue color. When reproducing the logo, please use the official color, when possible.

## Pantone

When possible, the Pantone color is preferred for print material. The official Pantone color is *285C*.

## RGB

When used digitally, the official RGB color code is *#326CE5*.
22 changes: 17 additions & 5 deletions pkg/common/config/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"gopkg.in/yaml.v3"

"github.com/openimsdk/open-im-server/v3/pkg/msgprocessor"
"github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
)

//go:embed version
Expand All @@ -37,19 +38,30 @@ const (

// return absolude path join ../config/, this is k8s container config path.
func GetDefaultConfigPath() string {
b, err := filepath.Abs(os.Args[0])
executablePath, err := os.Executable()
if err != nil {
fmt.Println("filepath.Abs error,err=", err)
fmt.Println("GetDefaultConfigPath error:", err.Error())
return ""
}
return filepath.Join(filepath.Dir(b), "../config/")

configPath, err := genutil.OutDir(filepath.Join(filepath.Dir(executablePath), "../config/"))
if err != nil {
fmt.Fprintf(os.Stderr, "failed to get output directory: %v\n", err)
os.Exit(1)
}
return configPath
}

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

return filepath.Join(filepath.Dir(b), "../../../../..")
projectRoot, err := genutil.OutDir(filepath.Join(filepath.Dir(executablePath), "../../../../.."))
if err != nil {
fmt.Fprintf(os.Stderr, "failed to get output directory: %v\n", err)
os.Exit(1)
}
return projectRoot
}

func GetOptionsByNotification(cfg NotificationConf) msgprocessor.Options {
Expand Down
40 changes: 40 additions & 0 deletions pkg/util/flag/flag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package flag

import (
goFlag "flag"
"log"
"strings"

"github.com/spf13/pflag"
)

// WordSepNormalizeFunc changes all flags that contain "_" separators.
func WordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName {
if strings.Contains(name, "_") {
return pflag.NormalizedName(strings.ReplaceAll(name, "_", "-"))
}
return pflag.NormalizedName(name)
}

// WarnWordSepNormalizeFunc changes and warns for flags that contain "_" separators.
func WarnWordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName {
if strings.Contains(name, "_") {
normalizedName := strings.ReplaceAll(name, "_", "-")
log.Printf("WARNING: flag %s has been deprecated and will be removed in a future version. Use %s instead.", name, normalizedName)
return pflag.NormalizedName(normalizedName)
}
return pflag.NormalizedName(name)
}

// InitFlags normalizes, parses, then logs the command line flags.
func InitFlags() {
pflag.CommandLine.SetNormalizeFunc(WordSepNormalizeFunc)
pflag.CommandLine.AddGoFlagSet(goFlag.CommandLine)
}

// PrintFlags logs the flags in the flagset.
func PrintFlags(flags *pflag.FlagSet) {
flags.VisitAll(func(flag *pflag.Flag) {
log.Printf("FLAG: --%s=%q", flag.Name, flag.Value)
})
}
27 changes: 27 additions & 0 deletions pkg/util/genutil/genutil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package genutil

import (
"fmt"
"os"
"path/filepath"
)

// OutDir creates the absolute path name from path and checks path exists.
// Returns absolute path including trailing '/' or error if path does not exist.
func OutDir(path string) (string, error) {
outDir, err := filepath.Abs(path)
if err != nil {
return "", err
}

stat, err := os.Stat(outDir)
if err != nil {
return "", err
}

if !stat.IsDir() {
return "", fmt.Errorf("output directory %s is not a directory", outDir)
}
outDir += "/"
return outDir, nil
}
26 changes: 26 additions & 0 deletions pkg/util/genutil/genutil_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package genutil

import (
"testing"
)

func TestValidDir(t *testing.T) {
_, err := OutDir("./")
if err != nil {
t.Fatal(err)
}
}

func TestInvalidDir(t *testing.T) {
_, err := OutDir("./nondir")
if err == nil {
t.Fatal("expected an error")
}
}

func TestNotDir(t *testing.T) {
_, err := OutDir("./genutils_test.go")
if err == nil {
t.Fatal("expected an error")
}
}
2 changes: 0 additions & 2 deletions scripts/docker-start-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ openim::log::info "\n# Use Docker to start all openim service"

trap 'openim::util::onCtrlC' INT

"${OPENIM_ROOT}"/scripts/init-config.sh --skip

"${OPENIM_ROOT}"/scripts/start-all.sh

sleep 5
Expand Down
19 changes: 13 additions & 6 deletions scripts/install/openim-msgtransfer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Use:
# ./scripts/install/openim-msgtransfer.sh openim::msgtransfer::start

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

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

if [ "$NUM_PROCESSES" -eq "$OPENIM_MSGGATEWAY_NUM" ]; then
openim::log::info "Found $OPENIM_MSGGATEWAY_NUM processes named $OPENIM_OUTPUT_HOSTBIN"
for PID in $PIDS; do
ps -p $PID -o pid,cmd
done
openim::log::info "Found $OPENIM_MSGGATEWAY_NUM processes named $OPENIM_OUTPUT_HOSTBIN"
for PID in $PIDS; do
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
ps -p $PID -o pid,cmd
elif [[ "$OSTYPE" == "darwin"* ]]; then
ps -p $PID -o pid,comm
else
openim::log::error "Unsupported OS type: $OSTYPE"
fi
done
else
openim::log::error_exit "Expected $OPENIM_MSGGATEWAY_NUM openim msgtransfer processes, but found $NUM_PROCESSES msgtransfer processes."
openim::log::error_exit "Expected $OPENIM_MSGGATEWAY_NUM openim msgtransfer processes, but found $NUM_PROCESSES msgtransfer processes."
fi
}

Expand Down
3 changes: 2 additions & 1 deletion scripts/install/openim-rpc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,13 @@ function openim::rpc::start() {
for ((i = 0; i < ${#OPENIM_RPC_SERVICE_LISTARIES[*]}; i++)); do
# openim::util::stop_services_with_name ${OPENIM_RPC_SERVICE_LISTARIES
openim::util::stop_services_on_ports ${OPENIM_RPC_PORT_LISTARIES[$i]}

openim::log::info "OpenIM ${OPENIM_RPC_SERVICE_LISTARIES[$i]} config path: ${OPENIM_RPC_CONFIG}"

# Get the service and Prometheus ports.
OPENIM_RPC_SERVICE_PORTS=( $(openim::util::list-to-string ${OPENIM_RPC_PORT_LISTARIES[$i]}) )
read -a OPENIM_RPC_SERVICE_PORTS_ARRAY <<< ${OPENIM_RPC_SERVICE_PORTS}

OPENIM_RPC_PROM_PORTS=( $(openim::util::list-to-string ${OPENIM_RPC_PROM_PORT_LISTARIES[$i]}) )
read -a OPENIM_RPC_PROM_PORTS_ARRAY <<< ${OPENIM_RPC_PROM_PORTS}

Expand Down
2 changes: 2 additions & 0 deletions scripts/start-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ if [[ $? -ne 0 ]]; then
fi
set -o errexit

"${OPENIM_ROOT}"/scripts/init-config.sh --skip

echo "You need to start the following scripts in order: ${OPENIM_SERVER_SCRIPTARIES[@]}"
openim::log::install_errexit

Expand Down

0 comments on commit 7155d1a

Please sign in to comment.