mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-03 02:42:19 +08:00
feat: add scripts format
This commit is contained in:
parent
87893dece2
commit
0b59a2205b
@ -42,7 +42,7 @@ OpenIM is a service platform specifically designed for integrating chat, audio-v
|
||||
- 🛡️ API wrapping
|
||||
- 🌐 Connection management
|
||||
|
||||
## 📚 Main Modules:
|
||||
+ 📚 Main Modules:
|
||||
|
||||
1. 🚀 Initialization and Login
|
||||
2. 👤 User Management
|
||||
@ -70,11 +70,16 @@ It is built using Golang and supports cross-platform deployment, ensuring a cons
|
||||
|
||||
## :rocket: Quick Start
|
||||
|
||||
We support many platforms. Here are the addresses for quick experience on the web side:
|
||||
|
||||
👉 **[OpenIM online web demo](https://web-enterprise.rentsoft.cn/)**
|
||||
|
||||
🤲 To facilitate user experience, we offer various deployment solutions. You can choose your deployment method from the list below:
|
||||
|
||||
+ **[Source Code Deployment Guide](https://docs.openim.io/guides/gettingStarted/imSourceCodeDeployment)**
|
||||
+ **[Docker Deployment Guide](https://docs.openim.io/guides/gettingStarted/dockerCompose)**
|
||||
+ **[Kubernetes Deployment Guide](https://docs.openim.io/guides/gettingStarted/k8s-deployment)**
|
||||
+ **[Mac Developer Deployment Guide](https://docs.openim.io/guides/gettingstarted/mac-deployment-guide)**
|
||||
|
||||
## :hammer_and_wrench: To Start Developing OpenIM
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
package flag
|
||||
|
||||
import (
|
||||
goFlag "flag"
|
||||
"flag"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
@ -29,7 +29,7 @@ func WarnWordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedNam
|
||||
// InitFlags normalizes, parses, then logs the command line flags.
|
||||
func InitFlags() {
|
||||
pflag.CommandLine.SetNormalizeFunc(WordSepNormalizeFunc)
|
||||
pflag.CommandLine.AddGoFlagSet(goFlag.CommandLine)
|
||||
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
|
||||
}
|
||||
|
||||
// PrintFlags logs the flags in the flagset.
|
||||
|
||||
173
scripts/bash_beautify.py
Executable file
173
scripts/bash_beautify.py
Executable file
@ -0,0 +1,173 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#**************************************************************************
|
||||
# Copyright (C) 2011, Paul Lutus *
|
||||
# *
|
||||
# This program is free software; you can redistribute it and/or modify *
|
||||
# it under the terms of the GNU General Public License as published by *
|
||||
# the Free Software Foundation; either version 2 of the License, or *
|
||||
# (at your option) any later version. *
|
||||
# *
|
||||
# This program is distributed in the hope that it will be useful, *
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
# GNU General Public License for more details. *
|
||||
# *
|
||||
# You should have received a copy of the GNU General Public License *
|
||||
# along with this program; if not, write to the *
|
||||
# Free Software Foundation, Inc., *
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
#**************************************************************************
|
||||
|
||||
import re
|
||||
import sys
|
||||
|
||||
PVERSION = '1.0'
|
||||
|
||||
|
||||
class BeautifyBash:
|
||||
|
||||
def __init__(self):
|
||||
self.tab_str = ' '
|
||||
self.tab_size = 2
|
||||
|
||||
def read_file(self, fp):
|
||||
with open(fp) as f:
|
||||
return f.read()
|
||||
|
||||
def write_file(self, fp, data):
|
||||
with open(fp, 'w') as f:
|
||||
f.write(data)
|
||||
|
||||
def beautify_string(self, data, path=''):
|
||||
tab = 0
|
||||
case_stack = []
|
||||
in_here_doc = False
|
||||
defer_ext_quote = False
|
||||
in_ext_quote = False
|
||||
ext_quote_string = ''
|
||||
here_string = ''
|
||||
output = []
|
||||
line = 1
|
||||
for record in re.split('\n', data):
|
||||
record = record.rstrip()
|
||||
stripped_record = record.strip()
|
||||
|
||||
# collapse multiple quotes between ' ... '
|
||||
test_record = re.sub(r'\'.*?\'', '', stripped_record)
|
||||
# collapse multiple quotes between " ... "
|
||||
test_record = re.sub(r'".*?"', '', test_record)
|
||||
# collapse multiple quotes between ` ... `
|
||||
test_record = re.sub(r'`.*?`', '', test_record)
|
||||
# collapse multiple quotes between \` ... ' (weird case)
|
||||
test_record = re.sub(r'\\`.*?\'', '', test_record)
|
||||
# strip out any escaped single characters
|
||||
test_record = re.sub(r'\\.', '', test_record)
|
||||
# remove '#' comments
|
||||
test_record = re.sub(r'(\A|\s)(#.*)', '', test_record, 1)
|
||||
if(not in_here_doc):
|
||||
if(re.search('<<-?', test_record)):
|
||||
here_string = re.sub(
|
||||
'.*<<-?\s*[\'|"]?([_|\w]+)[\'|"]?.*', '\\1', stripped_record, 1)
|
||||
in_here_doc = (len(here_string) > 0)
|
||||
if(in_here_doc): # pass on with no changes
|
||||
output.append(record)
|
||||
# now test for here-doc termination string
|
||||
if(re.search(here_string, test_record) and not re.search('<<', test_record)):
|
||||
in_here_doc = False
|
||||
else: # not in here doc
|
||||
if(in_ext_quote):
|
||||
if(re.search(ext_quote_string, test_record)):
|
||||
# provide line after quotes
|
||||
test_record = re.sub(
|
||||
'.*%s(.*)' % ext_quote_string, '\\1', test_record, 1)
|
||||
in_ext_quote = False
|
||||
else: # not in ext quote
|
||||
if(re.search(r'(\A|\s)(\'|")', test_record)):
|
||||
# apply only after this line has been processed
|
||||
defer_ext_quote = True
|
||||
ext_quote_string = re.sub(
|
||||
'.*([\'"]).*', '\\1', test_record, 1)
|
||||
# provide line before quote
|
||||
test_record = re.sub(
|
||||
'(.*)%s.*' % ext_quote_string, '\\1', test_record, 1)
|
||||
if(in_ext_quote):
|
||||
# pass on unchanged
|
||||
output.append(record)
|
||||
else: # not in ext quote
|
||||
inc = len(re.findall(
|
||||
'(\s|\A|;)(case|then|do)(;|\Z|\s)', test_record))
|
||||
inc += len(re.findall('(\{|\(|\[)', test_record))
|
||||
outc = len(re.findall(
|
||||
'(\s|\A|;)(esac|fi|done|elif)(;|\)|\||\Z|\s)', test_record))
|
||||
outc += len(re.findall('(\}|\)|\])', test_record))
|
||||
if(re.search(r'\besac\b', test_record)):
|
||||
if(len(case_stack) == 0):
|
||||
sys.stderr.write(
|
||||
'File %s: error: "esac" before "case" in line %d.\n' % (
|
||||
path, line)
|
||||
)
|
||||
else:
|
||||
outc += case_stack.pop()
|
||||
# sepcial handling for bad syntax within case ... esac
|
||||
if(len(case_stack) > 0):
|
||||
if(re.search('\A[^(]*\)', test_record)):
|
||||
# avoid overcount
|
||||
outc -= 2
|
||||
case_stack[-1] += 1
|
||||
if(re.search(';;', test_record)):
|
||||
outc += 1
|
||||
case_stack[-1] -= 1
|
||||
# an ad-hoc solution for the "else" keyword
|
||||
else_case = (
|
||||
0, -1)[re.search('^(else)', test_record) != None]
|
||||
net = inc - outc
|
||||
tab += min(net, 0)
|
||||
extab = tab + else_case
|
||||
extab = max(0, extab)
|
||||
output.append(
|
||||
(self.tab_str * self.tab_size * extab) + stripped_record)
|
||||
tab += max(net, 0)
|
||||
if(defer_ext_quote):
|
||||
in_ext_quote = True
|
||||
defer_ext_quote = False
|
||||
if(re.search(r'\bcase\b', test_record)):
|
||||
case_stack.append(0)
|
||||
line += 1
|
||||
error = (tab != 0)
|
||||
if(error):
|
||||
sys.stderr.write(
|
||||
'File %s: error: indent/outdent mismatch: %d.\n' % (path, tab))
|
||||
return '\n'.join(output), error
|
||||
|
||||
def beautify_file(self, path):
|
||||
error = False
|
||||
if(path == '-'):
|
||||
data = sys.stdin.read()
|
||||
result, error = self.beautify_string(data, '(stdin)')
|
||||
sys.stdout.write(result)
|
||||
else: # named file
|
||||
data = self.read_file(path)
|
||||
result, error = self.beautify_string(data, path)
|
||||
if(data != result):
|
||||
# make a backup copy
|
||||
self.write_file(path + '~', data)
|
||||
self.write_file(path, result)
|
||||
return error
|
||||
|
||||
def main(self):
|
||||
error = False
|
||||
sys.argv.pop(0)
|
||||
if(len(sys.argv) < 1):
|
||||
sys.stderr.write(
|
||||
'usage: shell script filenames or \"-\" for stdin.\n')
|
||||
else:
|
||||
for path in sys.argv:
|
||||
error |= self.beautify_file(path)
|
||||
sys.exit((0, 1)[error])
|
||||
|
||||
# if not called as a module
|
||||
if(__name__ == '__main__'):
|
||||
BeautifyBash().main()
|
||||
|
||||
@ -31,7 +31,7 @@ source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
||||
|
||||
# CPU core number
|
||||
pushd "${OPENIM_ROOT}/tools/ncpu" >/dev/null
|
||||
cpu_count=$(go run .)
|
||||
cpu_count=$(go run .)
|
||||
popd >/dev/null
|
||||
|
||||
openim::color::echo ${GREEN_PREFIX} "======> cpu_count=$cpu_count"
|
||||
|
||||
@ -153,7 +153,7 @@ For details on the cherry pick process, see the [cherry pick requests](https://g
|
||||
EOF
|
||||
)
|
||||
|
||||
gh pr create --title="Automated cherry pick of ${numandtitle}" --body="${prtext}" --head "${GITHUB_USER}:${NEWBRANCH}" --base "${rel}" --repo="${MAIN_REPO_ORG}/${MAIN_REPO_NAME}"
|
||||
gh pr create --title="Automated cherry pick of ${numandtitle}" --body="${prtext}" --head "${GITHUB_USER}:${NEWBRANCH}" --base "${rel}" --repo="${MAIN_REPO_ORG}/${MAIN_REPO_NAME}"
|
||||
}
|
||||
|
||||
git checkout -b "${NEWBRANCHUNIQ}" "${BRANCH}"
|
||||
@ -161,14 +161,14 @@ cleanbranch="${NEWBRANCHUNIQ}"
|
||||
|
||||
gitamcleanup=true
|
||||
for pull in "${PULLS[@]}"; do
|
||||
openim::log::status "Downloading patch to /tmp/${pull}.patch (in case you need to do this again)"
|
||||
openim::log::status "Downloading patch to /tmp/${pull}.patch (in case you need to do this again)"
|
||||
|
||||
curl -o "/tmp/${pull}.patch" -sSL "https://github.com/${MAIN_REPO_ORG}/${MAIN_REPO_NAME}/pull/${pull}.patch"
|
||||
echo
|
||||
openim::log::status "About to attempt cherry pick of PR. To reattempt:"
|
||||
echo " $ git am -3 /tmp/${pull}.patch"
|
||||
echo
|
||||
git am -3 "/tmp/${pull}.patch" || {
|
||||
curl -o "/tmp/${pull}.patch" -sSL "https://github.com/${MAIN_REPO_ORG}/${MAIN_REPO_NAME}/pull/${pull}.patch"
|
||||
echo
|
||||
openim::log::status "About to attempt cherry pick of PR. To reattempt:"
|
||||
echo " $ git am -3 /tmp/${pull}.patch"
|
||||
echo
|
||||
git am -3 "/tmp/${pull}.patch" || {
|
||||
conflicts=false
|
||||
while unmerged=$(git status --porcelain | grep ^U) && [[ -n ${unmerged} ]] \
|
||||
|| [[ -e "${REBASEMAGIC}" ]]; do
|
||||
@ -191,54 +191,54 @@ for pull in "${PULLS[@]}"; do
|
||||
echo "!!! git am failed, likely because of an in-progress 'git am' or 'git rebase'"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
# set the subject
|
||||
subject=$(grep -m 1 "^Subject" "/tmp/${pull}.patch" | sed -e 's/Subject: \[PATCH//g' | sed 's/.*] //')
|
||||
SUBJECTS+=("#${pull}: ${subject}")
|
||||
# set the subject
|
||||
subject=$(grep -m 1 "^Subject" "/tmp/${pull}.patch" | sed -e 's/Subject: \[PATCH//g' | sed 's/.*] //')
|
||||
SUBJECTS+=("#${pull}: ${subject}")
|
||||
|
||||
# remove the patch file from /tmp
|
||||
rm -f "/tmp/${pull}.patch"
|
||||
# remove the patch file from /tmp
|
||||
rm -f "/tmp/${pull}.patch"
|
||||
done
|
||||
gitamcleanup=false
|
||||
|
||||
# Re-generate docs (if needed)
|
||||
if [[ -n "${REGENERATE_DOCS}" ]]; then
|
||||
echo
|
||||
echo "Regenerating docs..."
|
||||
if ! scripts/generate-docs.sh; then
|
||||
echo
|
||||
echo "Regenerating docs..."
|
||||
if ! scripts/generate-docs.sh; then
|
||||
echo
|
||||
echo "scripts/gendoc.sh FAILED to complete."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n "${DRY_RUN}" ]]; then
|
||||
openim::log::error "!!! Skipping git push and PR creation because you set DRY_RUN."
|
||||
echo "To return to the branch you were in when you invoked this script:"
|
||||
echo
|
||||
echo " git checkout ${STARTINGBRANCH}"
|
||||
echo
|
||||
echo "To delete this branch:"
|
||||
echo
|
||||
echo " git branch -D ${NEWBRANCHUNIQ}"
|
||||
exit 0
|
||||
openim::log::error "!!! Skipping git push and PR creation because you set DRY_RUN."
|
||||
echo "To return to the branch you were in when you invoked this script:"
|
||||
echo
|
||||
echo " git checkout ${STARTINGBRANCH}"
|
||||
echo
|
||||
echo "To delete this branch:"
|
||||
echo
|
||||
echo " git branch -D ${NEWBRANCHUNIQ}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if git remote -v | grep ^"${FORK_REMOTE}" | grep "${MAIN_REPO_ORG}/${MAIN_REPO_NAME}.git"; then
|
||||
echo "!!! You have ${FORK_REMOTE} configured as your ${MAIN_REPO_ORG}/${MAIN_REPO_NAME}.git"
|
||||
echo "This isn't normal. Leaving you with push instructions:"
|
||||
echo
|
||||
openim::log::status "First manually push the branch this script created:"
|
||||
echo
|
||||
echo " git push REMOTE ${NEWBRANCHUNIQ}:${NEWBRANCH}"
|
||||
echo
|
||||
echo "where REMOTE is your personal fork (maybe ${UPSTREAM_REMOTE}? Consider swapping those.)."
|
||||
echo "OR consider setting UPSTREAM_REMOTE and FORK_REMOTE to different values."
|
||||
echo
|
||||
make-a-pr
|
||||
cleanbranch=""
|
||||
exit 0
|
||||
echo "!!! You have ${FORK_REMOTE} configured as your ${MAIN_REPO_ORG}/${MAIN_REPO_NAME}.git"
|
||||
echo "This isn't normal. Leaving you with push instructions:"
|
||||
echo
|
||||
openim::log::status "First manually push the branch this script created:"
|
||||
echo
|
||||
echo " git push REMOTE ${NEWBRANCHUNIQ}:${NEWBRANCH}"
|
||||
echo
|
||||
echo "where REMOTE is your personal fork (maybe ${UPSTREAM_REMOTE}? Consider swapping those.)."
|
||||
echo "OR consider setting UPSTREAM_REMOTE and FORK_REMOTE to different values."
|
||||
echo
|
||||
make-a-pr
|
||||
cleanbranch=""
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo
|
||||
@ -248,8 +248,8 @@ echo " git push ${FORK_REMOTE} ${NEWBRANCHUNIQ}:${NEWBRANCH}"
|
||||
echo
|
||||
read -p "+++ Proceed (anything other than 'y' aborts the cherry-pick)? [y/n] " -r
|
||||
if ! [[ "${REPLY}" =~ ^[yY]$ ]]; then
|
||||
echo "Aborting." >&2
|
||||
exit 1
|
||||
echo "Aborting." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
git push "${FORK_REMOTE}" -f "${NEWBRANCHUNIQ}:${NEWBRANCH}"
|
||||
|
||||
@ -87,13 +87,13 @@ readonly OPENIM_CONTAINER_RSYNC_PORT=8730
|
||||
#
|
||||
# $1 - server architecture
|
||||
openim::build::get_docker_wrapped_binaries() {
|
||||
local arch=$1
|
||||
local debian_base_version=v2.1.0
|
||||
local debian_iptables_version=v12.1.0
|
||||
### If you change any of these lists, please also update DOCKERIZED_BINARIES
|
||||
### in build/BUILD. And openim::golang::server_image_targets
|
||||
local arch=$1
|
||||
local debian_base_version=v2.1.0
|
||||
local debian_iptables_version=v12.1.0
|
||||
### If you change any of these lists, please also update DOCKERIZED_BINARIES
|
||||
### in build/BUILD. And openim::golang::server_image_targets
|
||||
|
||||
local targets=(
|
||||
local targets=(
|
||||
"openim-api,${OPENIM_BASE_IMAGE_REGISTRY}/debian-base-${arch}:${debian_base_version}"
|
||||
"openim-cmdutils,${OPENIM_BASE_IMAGE_REGISTRY}/debian-base-${arch}:${debian_base_version}"
|
||||
"openim-crontask,${OPENIM_BASE_IMAGE_REGISTRY}/debian-base-${arch}:${debian_base_version}"
|
||||
@ -107,8 +107,8 @@ openim::build::get_docker_wrapped_binaries() {
|
||||
"openim-rpc-msg,${OPENIM_BASE_IMAGE_REGISTRY}/debian-base-${arch}:${debian_base_version}"
|
||||
"openim-rpc-third,${OPENIM_BASE_IMAGE_REGISTRY}/debian-base-${arch}:${debian_base_version}"
|
||||
"openim-rpc-user,${OPENIM_BASE_IMAGE_REGISTRY}/debian-base-${arch}:${debian_base_version}"
|
||||
)
|
||||
echo "${targets[@]}"
|
||||
)
|
||||
echo "${targets[@]}"
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@ -133,11 +133,11 @@ openim::build::get_docker_wrapped_binaries() {
|
||||
# DOCKER_MOUNT_ARGS
|
||||
# LOCAL_OUTPUT_BUILD_CONTEXT
|
||||
function openim::build::verify_prereqs() {
|
||||
local -r require_docker=${1:-true}
|
||||
openim::log::status "Verifying Prerequisites...."
|
||||
openim::build::ensure_tar || return 1
|
||||
openim::build::ensure_rsync || return 1
|
||||
if ${require_docker}; then
|
||||
local -r require_docker=${1:-true}
|
||||
openim::log::status "Verifying Prerequisites...."
|
||||
openim::build::ensure_tar || return 1
|
||||
openim::build::ensure_rsync || return 1
|
||||
if ${require_docker}; then
|
||||
openim::build::ensure_docker_in_path || return 1
|
||||
openim::util::ensure_docker_daemon_connectivity || return 1
|
||||
|
||||
@ -145,31 +145,31 @@ function openim::build::verify_prereqs() {
|
||||
openim::log::status "Docker Version:"
|
||||
"${DOCKER[@]}" version | openim::log::info_from_stdin
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
OPENIM_GIT_BRANCH=$(git symbolic-ref --short -q HEAD 2>/dev/null || true)
|
||||
OPENIM_ROOT_HASH=$(openim::build::short_hash "${HOSTNAME:-}:"${OPENIM_ROOT}":${OPENIM_GIT_BRANCH}")
|
||||
OPENIM_BUILD_IMAGE_TAG_BASE="build-${OPENIM_ROOT_HASH}"
|
||||
#OPENIM_BUILD_IMAGE_TAG="${OPENIM_BUILD_IMAGE_TAG_BASE}-${OPENIM_BUILD_IMAGE_VERSION}"
|
||||
#OPENIM_BUILD_IMAGE="${OPENIM_BUILD_IMAGE_REPO}:${OPENIM_BUILD_IMAGE_TAG}"
|
||||
OPENIM_BUILD_CONTAINER_NAME_BASE="openim-build-${OPENIM_ROOT_HASH}"
|
||||
#OPENIM_BUILD_CONTAINER_NAME="${OPENIM_BUILD_CONTAINER_NAME_BASE}-${OPENIM_BUILD_IMAGE_VERSION}"
|
||||
OPENIM_RSYNC_CONTAINER_NAME_BASE="openim-rsync-${OPENIM_ROOT_HASH}"
|
||||
#OPENIM_RSYNC_CONTAINER_NAME="${OPENIM_RSYNC_CONTAINER_NAME_BASE}-${OPENIM_BUILD_IMAGE_VERSION}"
|
||||
OPENIM_DATA_CONTAINER_NAME_BASE="openim-build-data-${OPENIM_ROOT_HASH}"
|
||||
#OPENIM_DATA_CONTAINER_NAME="${OPENIM_DATA_CONTAINER_NAME_BASE}-${OPENIM_BUILD_IMAGE_VERSION}"
|
||||
#DOCKER_MOUNT_ARGS=(--volumes-from "${OPENIM_DATA_CONTAINER_NAME}")
|
||||
#LOCAL_OUTPUT_BUILD_CONTEXT="${LOCAL_OUTPUT_IMAGE_STAGING}/${OPENIM_BUILD_IMAGE}"
|
||||
OPENIM_GIT_BRANCH=$(git symbolic-ref --short -q HEAD 2>/dev/null || true)
|
||||
OPENIM_ROOT_HASH=$(openim::build::short_hash "${HOSTNAME:-}:"${OPENIM_ROOT}":${OPENIM_GIT_BRANCH}")
|
||||
OPENIM_BUILD_IMAGE_TAG_BASE="build-${OPENIM_ROOT_HASH}"
|
||||
#OPENIM_BUILD_IMAGE_TAG="${OPENIM_BUILD_IMAGE_TAG_BASE}-${OPENIM_BUILD_IMAGE_VERSION}"
|
||||
#OPENIM_BUILD_IMAGE="${OPENIM_BUILD_IMAGE_REPO}:${OPENIM_BUILD_IMAGE_TAG}"
|
||||
OPENIM_BUILD_CONTAINER_NAME_BASE="openim-build-${OPENIM_ROOT_HASH}"
|
||||
#OPENIM_BUILD_CONTAINER_NAME="${OPENIM_BUILD_CONTAINER_NAME_BASE}-${OPENIM_BUILD_IMAGE_VERSION}"
|
||||
OPENIM_RSYNC_CONTAINER_NAME_BASE="openim-rsync-${OPENIM_ROOT_HASH}"
|
||||
#OPENIM_RSYNC_CONTAINER_NAME="${OPENIM_RSYNC_CONTAINER_NAME_BASE}-${OPENIM_BUILD_IMAGE_VERSION}"
|
||||
OPENIM_DATA_CONTAINER_NAME_BASE="openim-build-data-${OPENIM_ROOT_HASH}"
|
||||
#OPENIM_DATA_CONTAINER_NAME="${OPENIM_DATA_CONTAINER_NAME_BASE}-${OPENIM_BUILD_IMAGE_VERSION}"
|
||||
#DOCKER_MOUNT_ARGS=(--volumes-from "${OPENIM_DATA_CONTAINER_NAME}")
|
||||
#LOCAL_OUTPUT_BUILD_CONTEXT="${LOCAL_OUTPUT_IMAGE_STAGING}/${OPENIM_BUILD_IMAGE}"
|
||||
|
||||
openim::version::get_version_vars
|
||||
#openim::version::save_version_vars "${OPENIM_ROOT}/.dockerized-openim-version-defs"
|
||||
openim::version::get_version_vars
|
||||
#openim::version::save_version_vars "${OPENIM_ROOT}/.dockerized-openim-version-defs"
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Utility functions
|
||||
|
||||
function openim::build::docker_available_on_osx() {
|
||||
if [[ -z "${DOCKER_HOST}" ]]; then
|
||||
if [[ -z "${DOCKER_HOST}" ]]; then
|
||||
if [[ -S "/var/run/docker.sock" ]]; then
|
||||
openim::log::status "Using Docker for MacOS"
|
||||
return 0
|
||||
@ -183,24 +183,24 @@ function openim::build::docker_available_on_osx() {
|
||||
elif [[ -n "$(which docker-machine)" ]]; then
|
||||
openim::build::prepare_docker_machine
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function openim::build::prepare_docker_machine() {
|
||||
openim::log::status "docker-machine was found."
|
||||
openim::log::status "docker-machine was found."
|
||||
|
||||
local available_memory_bytes
|
||||
available_memory_bytes=$(sysctl -n hw.memsize 2>/dev/null)
|
||||
local available_memory_bytes
|
||||
available_memory_bytes=$(sysctl -n hw.memsize 2>/dev/null)
|
||||
|
||||
local bytes_in_mb=1048576
|
||||
local bytes_in_mb=1048576
|
||||
|
||||
# Give virtualbox 1/2 the system memory. Its necessary to divide by 2, instead
|
||||
# of multiple by .5, because bash can only multiply by ints.
|
||||
local memory_divisor=2
|
||||
# Give virtualbox 1/2 the system memory. Its necessary to divide by 2, instead
|
||||
# of multiple by .5, because bash can only multiply by ints.
|
||||
local memory_divisor=2
|
||||
|
||||
local virtualbox_memory_mb=$(( available_memory_bytes / (bytes_in_mb * memory_divisor) ))
|
||||
local virtualbox_memory_mb=$(( available_memory_bytes / (bytes_in_mb * memory_divisor) ))
|
||||
|
||||
docker-machine inspect "${DOCKER_MACHINE_NAME}" &> /dev/null || {
|
||||
docker-machine inspect "${DOCKER_MACHINE_NAME}" &> /dev/null || {
|
||||
openim::log::status "Creating a machine to build OPENIM"
|
||||
docker-machine create --driver "${DOCKER_MACHINE_DRIVER}" \
|
||||
--virtualbox-memory "${virtualbox_memory_mb}" \
|
||||
@ -213,90 +213,90 @@ function openim::build::prepare_docker_machine() {
|
||||
openim::log::error "docker-machine create -d ${DOCKER_MACHINE_DRIVER} --virtualbox-memory ${virtualbox_memory_mb} ${DOCKER_MACHINE_NAME}"
|
||||
return 1
|
||||
}
|
||||
}
|
||||
docker-machine start "${DOCKER_MACHINE_NAME}" &> /dev/null
|
||||
# it takes `docker-machine env` a few seconds to work if the machine was just started
|
||||
local docker_machine_out
|
||||
while ! docker_machine_out=$(docker-machine env "${DOCKER_MACHINE_NAME}" 2>&1); do
|
||||
}
|
||||
docker-machine start "${DOCKER_MACHINE_NAME}" &> /dev/null
|
||||
# it takes `docker-machine env` a few seconds to work if the machine was just started
|
||||
local docker_machine_out
|
||||
while ! docker_machine_out=$(docker-machine env "${DOCKER_MACHINE_NAME}" 2>&1); do
|
||||
if [[ ${docker_machine_out} =~ "Error checking TLS connection" ]]; then
|
||||
echo "${docker_machine_out}"
|
||||
docker-machine regenerate-certs "${DOCKER_MACHINE_NAME}"
|
||||
else
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
eval "$(docker-machine env "${DOCKER_MACHINE_NAME}")"
|
||||
openim::log::status "A Docker host using docker-machine named '${DOCKER_MACHINE_NAME}' is ready to go!"
|
||||
return 0
|
||||
done
|
||||
eval "$(docker-machine env "${DOCKER_MACHINE_NAME}")"
|
||||
openim::log::status "A Docker host using docker-machine named '${DOCKER_MACHINE_NAME}' is ready to go!"
|
||||
return 0
|
||||
}
|
||||
|
||||
function openim::build::is_gnu_sed() {
|
||||
[[ $(sed --version 2>&1) == *GNU* ]]
|
||||
[[ $(sed --version 2>&1) == *GNU* ]]
|
||||
}
|
||||
|
||||
function openim::build::ensure_rsync() {
|
||||
if [[ -z "$(which rsync)" ]]; then
|
||||
if [[ -z "$(which rsync)" ]]; then
|
||||
openim::log::error "Can't find 'rsync' in PATH, please fix and retry."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function openim::build::update_dockerfile() {
|
||||
if openim::build::is_gnu_sed; then
|
||||
if openim::build::is_gnu_sed; then
|
||||
sed_opts=(-i)
|
||||
else
|
||||
else
|
||||
sed_opts=(-i '')
|
||||
fi
|
||||
sed "${sed_opts[@]}" "s/OPENIM_BUILD_IMAGE_CROSS_TAG/${OPENIM_BUILD_IMAGE_CROSS_TAG}/" "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile"
|
||||
fi
|
||||
sed "${sed_opts[@]}" "s/OPENIM_BUILD_IMAGE_CROSS_TAG/${OPENIM_BUILD_IMAGE_CROSS_TAG}/" "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile"
|
||||
}
|
||||
|
||||
function openim::build::set_proxy() {
|
||||
if [[ -n "${OPENIMRNETES_HTTPS_PROXY:-}" ]]; then
|
||||
if [[ -n "${OPENIMRNETES_HTTPS_PROXY:-}" ]]; then
|
||||
echo "ENV https_proxy $OPENIMRNETES_HTTPS_PROXY" >> "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile"
|
||||
fi
|
||||
if [[ -n "${OPENIMRNETES_HTTP_PROXY:-}" ]]; then
|
||||
fi
|
||||
if [[ -n "${OPENIMRNETES_HTTP_PROXY:-}" ]]; then
|
||||
echo "ENV http_proxy $OPENIMRNETES_HTTP_PROXY" >> "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile"
|
||||
fi
|
||||
if [[ -n "${OPENIMRNETES_NO_PROXY:-}" ]]; then
|
||||
fi
|
||||
if [[ -n "${OPENIMRNETES_NO_PROXY:-}" ]]; then
|
||||
echo "ENV no_proxy $OPENIMRNETES_NO_PROXY" >> "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function openim::build::ensure_docker_in_path() {
|
||||
if [[ -z "$(which docker)" ]]; then
|
||||
if [[ -z "$(which docker)" ]]; then
|
||||
openim::log::error "Can't find 'docker' in PATH, please fix and retry."
|
||||
openim::log::error "See https://docs.docker.com/installation/#installation for installation instructions."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function openim::build::ensure_tar() {
|
||||
if [[ -n "${TAR:-}" ]]; then
|
||||
if [[ -n "${TAR:-}" ]]; then
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
# Find gnu tar if it is available, bomb out if not.
|
||||
TAR=tar
|
||||
if which gtar &>/dev/null; then
|
||||
# Find gnu tar if it is available, bomb out if not.
|
||||
TAR=tar
|
||||
if which gtar &>/dev/null; then
|
||||
TAR=gtar
|
||||
else
|
||||
else
|
||||
if which gnutar &>/dev/null; then
|
||||
TAR=gnutar
|
||||
fi
|
||||
fi
|
||||
if ! "${TAR}" --version | grep -q GNU; then
|
||||
fi
|
||||
if ! "${TAR}" --version | grep -q GNU; then
|
||||
echo " !!! Cannot find GNU tar. Build on Linux or install GNU tar"
|
||||
echo " on Mac OS X (brew install gnu-tar)."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function openim::build::has_docker() {
|
||||
which docker &> /dev/null
|
||||
which docker &> /dev/null
|
||||
}
|
||||
|
||||
function openim::build::has_ip() {
|
||||
which ip &> /dev/null && ip -Version | grep 'iproute2' &> /dev/null
|
||||
which ip &> /dev/null && ip -Version | grep 'iproute2' &> /dev/null
|
||||
}
|
||||
|
||||
# Detect if a specific image exists
|
||||
@ -304,12 +304,12 @@ function openim::build::has_ip() {
|
||||
# $1 - image repo name
|
||||
# $2 - image tag
|
||||
function openim::build::docker_image_exists() {
|
||||
[[ -n $1 && -n $2 ]] || {
|
||||
[[ -n $1 && -n $2 ]] || {
|
||||
openim::log::error "Internal error. Image not specified in docker_image_exists."
|
||||
exit 2
|
||||
}
|
||||
}
|
||||
|
||||
[[ $("${DOCKER[@]}" images -q "${1}:${2}") ]]
|
||||
[[ $("${DOCKER[@]}" images -q "${1}:${2}") ]]
|
||||
}
|
||||
|
||||
# Delete all images that match a tag prefix except for the "current" version
|
||||
@ -318,9 +318,9 @@ function openim::build::docker_image_exists() {
|
||||
# $2: The tag base. We consider any image that matches $2*
|
||||
# $3: The current image not to delete if provided
|
||||
function openim::build::docker_delete_old_images() {
|
||||
# In Docker 1.12, we can replace this with
|
||||
# docker images "$1" --format "{{.Tag}}"
|
||||
for tag in $("${DOCKER[@]}" images "${1}" | tail -n +2 | awk '{print $2}') ; do
|
||||
# In Docker 1.12, we can replace this with
|
||||
# docker images "$1" --format "{{.Tag}}"
|
||||
for tag in $("${DOCKER[@]}" images "${1}" | tail -n +2 | awk '{print $2}') ; do
|
||||
if [[ "${tag}" != "${2}"* ]] ; then
|
||||
V=3 openim::log::status "Keeping image ${1}:${tag}"
|
||||
continue
|
||||
@ -332,7 +332,7 @@ function openim::build::docker_delete_old_images() {
|
||||
else
|
||||
V=3 openim::log::status "Keeping image ${1}:${tag}"
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# Stop and delete all containers that match a pattern
|
||||
@ -340,9 +340,9 @@ function openim::build::docker_delete_old_images() {
|
||||
# $1: The base container prefix
|
||||
# $2: The current container to keep, if provided
|
||||
function openim::build::docker_delete_old_containers() {
|
||||
# In Docker 1.12 we can replace this line with
|
||||
# docker ps -a --format="{{.Names}}"
|
||||
for container in $("${DOCKER[@]}" ps -a | tail -n +2 | awk '{print $NF}') ; do
|
||||
# In Docker 1.12 we can replace this line with
|
||||
# docker ps -a --format="{{.Names}}"
|
||||
for container in $("${DOCKER[@]}" ps -a | tail -n +2 | awk '{print $NF}') ; do
|
||||
if [[ "${container}" != "${1}"* ]] ; then
|
||||
V=3 openim::log::status "Keeping container ${container}"
|
||||
continue
|
||||
@ -353,23 +353,23 @@ function openim::build::docker_delete_old_containers() {
|
||||
else
|
||||
V=3 openim::log::status "Keeping container ${container}"
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# Takes $1 and computes a short has for it. Useful for unique tag generation
|
||||
function openim::build::short_hash() {
|
||||
[[ $# -eq 1 ]] || {
|
||||
[[ $# -eq 1 ]] || {
|
||||
openim::log::error "Internal error. No data based to short_hash."
|
||||
exit 2
|
||||
}
|
||||
}
|
||||
|
||||
local short_hash
|
||||
if which md5 >/dev/null 2>&1; then
|
||||
local short_hash
|
||||
if which md5 >/dev/null 2>&1; then
|
||||
short_hash=$(md5 -q -s "$1")
|
||||
else
|
||||
else
|
||||
short_hash=$(echo -n "$1" | md5sum)
|
||||
fi
|
||||
echo "${short_hash:0:10}"
|
||||
fi
|
||||
echo "${short_hash:0:10}"
|
||||
}
|
||||
|
||||
# Pedantically kill, wait-on and remove a container. The -f -v options
|
||||
@ -377,15 +377,15 @@ function openim::build::short_hash() {
|
||||
# container, wait to ensure it's stopped, then try the remove. This is
|
||||
# a workaround for bug https://github.com/docker/docker/issues/3968.
|
||||
function openim::build::destroy_container() {
|
||||
"${DOCKER[@]}" kill "$1" >/dev/null 2>&1 || true
|
||||
if [[ $("${DOCKER[@]}" version --format '{{.Server.Version}}') = 17.06.0* ]]; then
|
||||
"${DOCKER[@]}" kill "$1" >/dev/null 2>&1 || true
|
||||
if [[ $("${DOCKER[@]}" version --format '{{.Server.Version}}') = 17.06.0* ]]; then
|
||||
# Workaround https://github.com/moby/moby/issues/33948.
|
||||
# TODO: remove when 17.06.0 is not relevant anymore
|
||||
DOCKER_API_VERSION=v1.29 "${DOCKER[@]}" wait "$1" >/dev/null 2>&1 || true
|
||||
else
|
||||
else
|
||||
"${DOCKER[@]}" wait "$1" >/dev/null 2>&1 || true
|
||||
fi
|
||||
"${DOCKER[@]}" rm -f -v "$1" >/dev/null 2>&1 || true
|
||||
fi
|
||||
"${DOCKER[@]}" rm -f -v "$1" >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@ -393,7 +393,7 @@ function openim::build::destroy_container() {
|
||||
|
||||
|
||||
function openim::build::clean() {
|
||||
if openim::build::has_docker ; then
|
||||
if openim::build::has_docker ; then
|
||||
openim::build::docker_delete_old_containers "${OPENIM_BUILD_CONTAINER_NAME_BASE}"
|
||||
openim::build::docker_delete_old_containers "${OPENIM_RSYNC_CONTAINER_NAME_BASE}"
|
||||
openim::build::docker_delete_old_containers "${OPENIM_DATA_CONTAINER_NAME_BASE}"
|
||||
@ -401,39 +401,39 @@ function openim::build::clean() {
|
||||
|
||||
V=2 openim::log::status "Cleaning all untagged docker images"
|
||||
"${DOCKER[@]}" rmi "$("${DOCKER[@]}" images -q --filter 'dangling=true')" 2> /dev/null || true
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -d "${LOCAL_OUTPUT_ROOT}" ]]; then
|
||||
if [[ -d "${LOCAL_OUTPUT_ROOT}" ]]; then
|
||||
openim::log::status "Removing _output directory"
|
||||
rm -rf "${LOCAL_OUTPUT_ROOT}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Set up the context directory for the openim-build image and build it.
|
||||
function openim::build::build_image() {
|
||||
mkdir -p "${LOCAL_OUTPUT_BUILD_CONTEXT}"
|
||||
# Make sure the context directory owned by the right user for syncing sources to container.
|
||||
chown -R "${USER_ID}":"${GROUP_ID}" "${LOCAL_OUTPUT_BUILD_CONTEXT}"
|
||||
mkdir -p "${LOCAL_OUTPUT_BUILD_CONTEXT}"
|
||||
# Make sure the context directory owned by the right user for syncing sources to container.
|
||||
chown -R "${USER_ID}":"${GROUP_ID}" "${LOCAL_OUTPUT_BUILD_CONTEXT}"
|
||||
|
||||
cp /etc/localtime "${LOCAL_OUTPUT_BUILD_CONTEXT}/"
|
||||
cp /etc/localtime "${LOCAL_OUTPUT_BUILD_CONTEXT}/"
|
||||
|
||||
cp "${OPENIM_ROOT}/build/build-image/Dockerfile" "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile"
|
||||
cp "${OPENIM_ROOT}/build/build-image/rsyncd.sh" "${LOCAL_OUTPUT_BUILD_CONTEXT}/"
|
||||
dd if=/dev/urandom bs=512 count=1 2>/dev/null | LC_ALL=C tr -dc 'A-Za-z0-9' | dd bs=32 count=1 2>/dev/null > "${LOCAL_OUTPUT_BUILD_CONTEXT}/rsyncd.password"
|
||||
chmod go= "${LOCAL_OUTPUT_BUILD_CONTEXT}/rsyncd.password"
|
||||
cp "${OPENIM_ROOT}/build/build-image/Dockerfile" "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile"
|
||||
cp "${OPENIM_ROOT}/build/build-image/rsyncd.sh" "${LOCAL_OUTPUT_BUILD_CONTEXT}/"
|
||||
dd if=/dev/urandom bs=512 count=1 2>/dev/null | LC_ALL=C tr -dc 'A-Za-z0-9' | dd bs=32 count=1 2>/dev/null > "${LOCAL_OUTPUT_BUILD_CONTEXT}/rsyncd.password"
|
||||
chmod go= "${LOCAL_OUTPUT_BUILD_CONTEXT}/rsyncd.password"
|
||||
|
||||
openim::build::update_dockerfile
|
||||
openim::build::set_proxy
|
||||
openim::build::docker_build "${OPENIM_BUILD_IMAGE}" "${LOCAL_OUTPUT_BUILD_CONTEXT}" 'false'
|
||||
openim::build::update_dockerfile
|
||||
openim::build::set_proxy
|
||||
openim::build::docker_build "${OPENIM_BUILD_IMAGE}" "${LOCAL_OUTPUT_BUILD_CONTEXT}" 'false'
|
||||
|
||||
# Clean up old versions of everything
|
||||
openim::build::docker_delete_old_containers "${OPENIM_BUILD_CONTAINER_NAME_BASE}" "${OPENIM_BUILD_CONTAINER_NAME}"
|
||||
openim::build::docker_delete_old_containers "${OPENIM_RSYNC_CONTAINER_NAME_BASE}" "${OPENIM_RSYNC_CONTAINER_NAME}"
|
||||
openim::build::docker_delete_old_containers "${OPENIM_DATA_CONTAINER_NAME_BASE}" "${OPENIM_DATA_CONTAINER_NAME}"
|
||||
openim::build::docker_delete_old_images "${OPENIM_BUILD_IMAGE_REPO}" "${OPENIM_BUILD_IMAGE_TAG_BASE}" "${OPENIM_BUILD_IMAGE_TAG}"
|
||||
# Clean up old versions of everything
|
||||
openim::build::docker_delete_old_containers "${OPENIM_BUILD_CONTAINER_NAME_BASE}" "${OPENIM_BUILD_CONTAINER_NAME}"
|
||||
openim::build::docker_delete_old_containers "${OPENIM_RSYNC_CONTAINER_NAME_BASE}" "${OPENIM_RSYNC_CONTAINER_NAME}"
|
||||
openim::build::docker_delete_old_containers "${OPENIM_DATA_CONTAINER_NAME_BASE}" "${OPENIM_DATA_CONTAINER_NAME}"
|
||||
openim::build::docker_delete_old_images "${OPENIM_BUILD_IMAGE_REPO}" "${OPENIM_BUILD_IMAGE_TAG_BASE}" "${OPENIM_BUILD_IMAGE_TAG}"
|
||||
|
||||
openim::build::ensure_data_container
|
||||
openim::build::sync_to_container
|
||||
openim::build::ensure_data_container
|
||||
openim::build::sync_to_container
|
||||
}
|
||||
|
||||
# Build a docker image from a Dockerfile.
|
||||
@ -441,14 +441,14 @@ function openim::build::build_image() {
|
||||
# $2 is the location of the "context" directory, with the Dockerfile at the root.
|
||||
# $3 is the value to set the --pull flag for docker build; true by default
|
||||
function openim::build::docker_build() {
|
||||
local -r image=$1
|
||||
local -r context_dir=$2
|
||||
local -r pull="${3:-true}"
|
||||
local -ra build_cmd=("${DOCKER[@]}" build -t "${image}" "--pull=${pull}" "${context_dir}")
|
||||
local -r image=$1
|
||||
local -r context_dir=$2
|
||||
local -r pull="${3:-true}"
|
||||
local -ra build_cmd=("${DOCKER[@]}" build -t "${image}" "--pull=${pull}" "${context_dir}")
|
||||
|
||||
openim::log::status "Building Docker image ${image}"
|
||||
local docker_output
|
||||
docker_output=$("${build_cmd[@]}" 2>&1) || {
|
||||
openim::log::status "Building Docker image ${image}"
|
||||
local docker_output
|
||||
docker_output=$("${build_cmd[@]}" 2>&1) || {
|
||||
cat <<EOF >&2
|
||||
+++ Docker build command failed for ${image}
|
||||
|
||||
@ -460,23 +460,23 @@ ${build_cmd[*]}
|
||||
|
||||
EOF
|
||||
return 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function openim::build::ensure_data_container() {
|
||||
# If the data container exists AND exited successfully, we can use it.
|
||||
# Otherwise nuke it and start over.
|
||||
local ret=0
|
||||
local code=0
|
||||
# If the data container exists AND exited successfully, we can use it.
|
||||
# Otherwise nuke it and start over.
|
||||
local ret=0
|
||||
local code=0
|
||||
|
||||
code=$(docker inspect \
|
||||
code=$(docker inspect \
|
||||
-f '{{.State.ExitCode}}' \
|
||||
"${OPENIM_DATA_CONTAINER_NAME}" 2>/dev/null) || ret=$?
|
||||
if [[ "${ret}" == 0 && "${code}" != 0 ]]; then
|
||||
"${OPENIM_DATA_CONTAINER_NAME}" 2>/dev/null) || ret=$?
|
||||
if [[ "${ret}" == 0 && "${code}" != 0 ]]; then
|
||||
openim::build::destroy_container "${OPENIM_DATA_CONTAINER_NAME}"
|
||||
ret=1
|
||||
fi
|
||||
if [[ "${ret}" != 0 ]]; then
|
||||
fi
|
||||
if [[ "${ret}" != 0 ]]; then
|
||||
openim::log::status "Creating data container ${OPENIM_DATA_CONTAINER_NAME}"
|
||||
# We have to ensure the directory exists, or else the docker run will
|
||||
# create it as root.
|
||||
@ -509,11 +509,11 @@ function openim::build::ensure_data_container() {
|
||||
/usr/local/go/pkg/
|
||||
)
|
||||
"${docker_cmd[@]}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Build all openim commands.
|
||||
function openim::build::build_command() {
|
||||
openim::log::status "Running build command..."
|
||||
make -C "${OPENIM_ROOT}" multiarch
|
||||
openim::log::status "Running build command..."
|
||||
make -C "${OPENIM_ROOT}" multiarch
|
||||
}
|
||||
|
||||
@ -50,9 +50,9 @@ printMessage "Running the OpenIM commit-msg hook."
|
||||
# This example catches duplicate Signed-off-by lines.
|
||||
|
||||
test "" = "$(grep '^Signed-off-by: ' "$1" |
|
||||
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
|
||||
echo >&2 Duplicate Signed-off-by lines.
|
||||
exit 1
|
||||
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
|
||||
echo >&2 Duplicate Signed-off-by lines.
|
||||
exit 1
|
||||
}
|
||||
|
||||
# TODO: go-gitlint dir set
|
||||
@ -60,21 +60,21 @@ OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
|
||||
GITLINT_DIR="$OPENIM_ROOT/_output/tools/go-gitlint"
|
||||
|
||||
$GITLINT_DIR \
|
||||
--msg-file=$1 \
|
||||
--subject-regex="^(build|chore|ci|docs|feat|feature|fix|perf|refactor|revert|style|bot|test)(.*)?:\s?.*" \
|
||||
--subject-maxlen=150 \
|
||||
--subject-minlen=10 \
|
||||
--body-regex=".*" \
|
||||
--max-parents=1
|
||||
--msg-file=$1 \
|
||||
--subject-regex="^(build|chore|ci|docs|feat|feature|fix|perf|refactor|revert|style|bot|test)(.*)?:\s?.*" \
|
||||
--subject-maxlen=150 \
|
||||
--subject-minlen=10 \
|
||||
--body-regex=".*" \
|
||||
--max-parents=1
|
||||
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
if ! command -v $GITLINT_DIR &>/dev/null; then
|
||||
if ! command -v $GITLINT_DIR &>/dev/null; then
|
||||
printError "$GITLINT_DIR not found. Please run 'make tools' OR 'make tools.verify.go-gitlint' make verto install it."
|
||||
fi
|
||||
printError "Please fix your commit message to match kubecub coding standards"
|
||||
printError "https://gist.github.com/cubxxw/126b72104ac0b0ca484c9db09c3e5694#file-githook-md"
|
||||
exit 1
|
||||
fi
|
||||
printError "Please fix your commit message to match kubecub coding standards"
|
||||
printError "https://gist.github.com/cubxxw/126b72104ac0b0ca484c9db09c3e5694#file-githook-md"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
### Add Sign-off-by line to the end of the commit message
|
||||
@ -88,5 +88,5 @@ SIGNED_OFF_BY_EXISTS=$?
|
||||
|
||||
# Add "Signed-off-by" line if it doesn't exist
|
||||
if [ $SIGNED_OFF_BY_EXISTS -ne 0 ]; then
|
||||
echo -e "\nSigned-off-by: $NAME <$EMAIL>" >> "$1"
|
||||
echo -e "\nSigned-off-by: $NAME <$EMAIL>" >> "$1"
|
||||
fi
|
||||
@ -31,7 +31,7 @@ readonly ENV_FILE=${ENV_FILE:-"${OPENIM_ROOT}/scripts/install/environment.sh"}
|
||||
# Templates for configuration files
|
||||
declare -A TEMPLATES=(
|
||||
["${OPENIM_ROOT}/deployments/templates/env-template.yaml"]="${OPENIM_ROOT}/.env"
|
||||
["${OPENIM_ROOT}/deployments/templates/config.yaml"]="${OPENIM_ROOT}/config/openim.yaml"
|
||||
["${OPENIM_ROOT}/deployments/templates/config.yaml"]="${OPENIM_ROOT}/config/config.yaml"
|
||||
["${OPENIM_ROOT}/deployments/templates/prometheus.yml"]="${OPENIM_ROOT}/config/prometheus.yml"
|
||||
["${OPENIM_ROOT}/deployments/templates/alertmanager.yml"]="${OPENIM_ROOT}/config/alertmanager.yml"
|
||||
)
|
||||
@ -39,7 +39,7 @@ declare -A TEMPLATES=(
|
||||
# Templates for example files
|
||||
declare -A EXAMPLES=(
|
||||
["${OPENIM_ROOT}/deployments/templates/env-template.yaml"]="${OPENIM_ROOT}/config/templates/env.template"
|
||||
["${OPENIM_ROOT}/deployments/templates/config.yaml"]="${OPENIM_ROOT}/config/templates/openim.yaml.template"
|
||||
["${OPENIM_ROOT}/deployments/templates/config.yaml"]="${OPENIM_ROOT}/config/templates/config.yaml.template"
|
||||
["${OPENIM_ROOT}/deployments/templates/prometheus.yml"]="${OPENIM_ROOT}/config/templates/prometheus.yml.template"
|
||||
["${OPENIM_ROOT}/deployments/templates/alertmanager.yml"]="${OPENIM_ROOT}/config/templates/alertmanager.yml.template"
|
||||
)
|
||||
@ -95,6 +95,10 @@ generate_config_files() {
|
||||
# Function to generate example files
|
||||
generate_example_files() {
|
||||
env_cmd="env -i"
|
||||
|
||||
env_vars["OPENIM_IP"]="127.0.0.1"
|
||||
env_vars["LOG_STORAGE_LOCATION"]="../../"
|
||||
|
||||
for var in "${!env_vars[@]}"; do
|
||||
env_cmd+=" $var='${env_vars[$var]}'"
|
||||
done
|
||||
@ -110,7 +114,6 @@ generate_example_files() {
|
||||
local example_file="${COPY_EXAMPLES[$template]}"
|
||||
process_file "$template" "$example_file" false
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
# Function to process a single file, either by generating or copying
|
||||
@ -181,7 +184,6 @@ clean_config_files() {
|
||||
|
||||
# Function to clean example files
|
||||
clean_example_files() {
|
||||
# 合并 EXAMPLES 和 COPY_EXAMPLES 数组
|
||||
local all_examples=("${EXAMPLES[@]}" "${COPY_EXAMPLES[@]}")
|
||||
|
||||
for example_file in "${all_examples[@]}"; do
|
||||
|
||||
@ -24,66 +24,66 @@ OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
||||
|
||||
# Start MongoDB service
|
||||
docker run -d \
|
||||
--name mongo \
|
||||
-p 37017:27017 \
|
||||
-v "${DATA_DIR}/components/mongodb/data/db:/data/db" \
|
||||
-v "${DATA_DIR}/components/mongodb/data/logs:/data/logs" \
|
||||
-v "${DATA_DIR}/components/mongodb/data/conf:/etc/mongo" \
|
||||
-v "./scripts/mongo-init.sh:/docker-entrypoint-initdb.d/mongo-init.sh:ro" \
|
||||
-e TZ=Asia/Shanghai \
|
||||
-e wiredTigerCacheSizeGB=1 \
|
||||
-e MONGO_INITDB_ROOT_USERNAME=${OPENIM_USER} \
|
||||
-e MONGO_INITDB_ROOT_PASSWORD=${PASSWORD} \
|
||||
-e MONGO_INITDB_DATABASE=openim_v3 \
|
||||
-e MONGO_OPENIM_USERNAME=${OPENIM_USER} \
|
||||
-e MONGO_OPENIM_PASSWORD=${PASSWORD} \
|
||||
--restart always \
|
||||
mongo:6.0.2 --wiredTigerCacheSizeGB 1 --auth
|
||||
--name mongo \
|
||||
-p 37017:27017 \
|
||||
-v "${DATA_DIR}/components/mongodb/data/db:/data/db" \
|
||||
-v "${DATA_DIR}/components/mongodb/data/logs:/data/logs" \
|
||||
-v "${DATA_DIR}/components/mongodb/data/conf:/etc/mongo" \
|
||||
-v "./scripts/mongo-init.sh:/docker-entrypoint-initdb.d/mongo-init.sh:ro" \
|
||||
-e TZ=Asia/Shanghai \
|
||||
-e wiredTigerCacheSizeGB=1 \
|
||||
-e MONGO_INITDB_ROOT_USERNAME=${OPENIM_USER} \
|
||||
-e MONGO_INITDB_ROOT_PASSWORD=${PASSWORD} \
|
||||
-e MONGO_INITDB_DATABASE=openim_v3 \
|
||||
-e MONGO_OPENIM_USERNAME=${OPENIM_USER} \
|
||||
-e MONGO_OPENIM_PASSWORD=${PASSWORD} \
|
||||
--restart always \
|
||||
mongo:6.0.2 --wiredTigerCacheSizeGB 1 --auth
|
||||
|
||||
# Start Redis service
|
||||
docker run -d \
|
||||
--name redis \
|
||||
-p 16379:6379 \
|
||||
-v "${DATA_DIR}/components/redis/data:/data" \
|
||||
-v "${DATA_DIR}/components/redis/config/redis.conf:/usr/local/redis/config/redis.conf" \
|
||||
-e TZ=Asia/Shanghai \
|
||||
--sysctl net.core.somaxconn=1024 \
|
||||
--restart always \
|
||||
redis:7.0.0 redis-server --requirepass ${PASSWORD} --appendonly yes
|
||||
--name redis \
|
||||
-p 16379:6379 \
|
||||
-v "${DATA_DIR}/components/redis/data:/data" \
|
||||
-v "${DATA_DIR}/components/redis/config/redis.conf:/usr/local/redis/config/redis.conf" \
|
||||
-e TZ=Asia/Shanghai \
|
||||
--sysctl net.core.somaxconn=1024 \
|
||||
--restart always \
|
||||
redis:7.0.0 redis-server --requirepass ${PASSWORD} --appendonly yes
|
||||
|
||||
# Start Zookeeper service
|
||||
docker run -d \
|
||||
--name zookeeper \
|
||||
-p 2181:2181 \
|
||||
-v "/etc/localtime:/etc/localtime" \
|
||||
-e TZ=Asia/Shanghai \
|
||||
--restart always \
|
||||
wurstmeister/zookeeper
|
||||
--name zookeeper \
|
||||
-p 2181:2181 \
|
||||
-v "/etc/localtime:/etc/localtime" \
|
||||
-e TZ=Asia/Shanghai \
|
||||
--restart always \
|
||||
wurstmeister/zookeeper
|
||||
|
||||
# Start Kafka service
|
||||
docker run -d \
|
||||
--name kafka \
|
||||
-p 9092:9092 \
|
||||
-e TZ=Asia/Shanghai \
|
||||
-e KAFKA_BROKER_ID=0 \
|
||||
-e KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 \
|
||||
-e KAFKA_CREATE_TOPICS="latestMsgToRedis:8:1,msgToPush:8:1,offlineMsgToMongoMysql:8:1" \
|
||||
-e KAFKA_ADVERTISED_LISTENERS="INSIDE://127.0.0.1:9092,OUTSIDE://103.116.45.174:9092" \
|
||||
-e KAFKA_LISTENERS="INSIDE://:9092,OUTSIDE://:9093" \
|
||||
-e KAFKA_LISTENER_SECURITY_PROTOCOL_MAP="INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT" \
|
||||
-e KAFKA_INTER_BROKER_LISTENER_NAME=INSIDE \
|
||||
--restart always \
|
||||
--link zookeeper \
|
||||
wurstmeister/kafka
|
||||
--name kafka \
|
||||
-p 9092:9092 \
|
||||
-e TZ=Asia/Shanghai \
|
||||
-e KAFKA_BROKER_ID=0 \
|
||||
-e KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 \
|
||||
-e KAFKA_CREATE_TOPICS="latestMsgToRedis:8:1,msgToPush:8:1,offlineMsgToMongoMysql:8:1" \
|
||||
-e KAFKA_ADVERTISED_LISTENERS="INSIDE://127.0.0.1:9092,OUTSIDE://103.116.45.174:9092" \
|
||||
-e KAFKA_LISTENERS="INSIDE://:9092,OUTSIDE://:9093" \
|
||||
-e KAFKA_LISTENER_SECURITY_PROTOCOL_MAP="INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT" \
|
||||
-e KAFKA_INTER_BROKER_LISTENER_NAME=INSIDE \
|
||||
--restart always \
|
||||
--link zookeeper \
|
||||
wurstmeister/kafka
|
||||
|
||||
# Start MinIO service
|
||||
docker run -d \
|
||||
--name minio \
|
||||
-p 10005:9000 \
|
||||
-p 9090:9090 \
|
||||
-v "/mnt/data:/data" \
|
||||
-v "/mnt/config:/root/.minio" \
|
||||
-e MINIO_ROOT_USER=${OPENIM_USER} \
|
||||
-e MINIO_ROOT_PASSWORD=${PASSWORD} \
|
||||
--restart always \
|
||||
minio/minio server /data --console-address ':9090'
|
||||
--name minio \
|
||||
-p 10005:9000 \
|
||||
-p 9090:9090 \
|
||||
-v "/mnt/data:/data" \
|
||||
-v "/mnt/config:/root/.minio" \
|
||||
-e MINIO_ROOT_USER=${OPENIM_USER} \
|
||||
-e MINIO_ROOT_PASSWORD=${PASSWORD} \
|
||||
--restart always \
|
||||
minio/minio server /data --console-address ':9090'
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -65,14 +65,18 @@ cd "${OPENIM_ROOT}"
|
||||
# forked should be linted and fixed.
|
||||
all_shell_scripts=()
|
||||
while IFS=$'\n' read -r script;
|
||||
do git check-ignore -q "$script" || all_shell_scripts+=("$script");
|
||||
done < <(find . -name "*.sh" \
|
||||
do git check-ignore -q "$script" || all_shell_scripts+=("$script");
|
||||
done < <(find . -name "*.sh" \
|
||||
-not \( \
|
||||
-path ./_\* -o \
|
||||
-path ./.git\* -o \
|
||||
-path ./Godeps\* -o \
|
||||
-path ./_output\* -o \
|
||||
-path ./components\* -o \
|
||||
-path ./logs\* -o \
|
||||
-path ./vendor\* -o \
|
||||
\( -path ./third_party\* -a -not -path ./third_party/forked\* \) \
|
||||
\))
|
||||
\))
|
||||
|
||||
# detect if the host machine has the required shellcheck version installed
|
||||
# if so, we will use that instead.
|
||||
|
||||
@ -31,7 +31,7 @@ PATH="${GOBIN}:${PATH}"
|
||||
|
||||
# Install tools we need
|
||||
pushd "${OPENIM_ROOT}/tools" >/dev/null
|
||||
GO111MODULE=on go install github.com/client9/misspell/cmd/misspell
|
||||
GO111MODULE=on go install github.com/client9/misspell/cmd/misspell
|
||||
popd >/dev/null
|
||||
|
||||
# Spell checking
|
||||
|
||||
@ -33,7 +33,7 @@ cd "${OPENIM_ROOT}"
|
||||
ret=0
|
||||
TYPECHECK_SERIAL="${TYPECHECK_SERIAL:-false}"
|
||||
scripts/run-in-gopath.sh \
|
||||
go run test/typecheck/typecheck.go "$@" "--serial=$TYPECHECK_SERIAL" || ret=$?
|
||||
go run test/typecheck/typecheck.go "$@" "--serial=$TYPECHECK_SERIAL" || ret=$?
|
||||
if [[ $ret -ne 0 ]]; then
|
||||
openim::log::error "Type Check has failed. This may cause cross platform build failures." >&2
|
||||
openim::log::error "Please see https://github.com/openimsdk/open-im-server/tree/main/test/typecheck for more information." >&2
|
||||
|
||||
@ -34,7 +34,7 @@ openim_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
|
||||
wrkdir="${openim_root}/_output/wrk"
|
||||
jobname="openim-api"
|
||||
duration="300s"
|
||||
threads=$((3 * `grep -c processor /proc/cpuinfo`))
|
||||
threads=$((3 * $(grep -c processor /proc/cpuinfo)))
|
||||
|
||||
source "${openim_root}/scripts/lib/color.sh"
|
||||
|
||||
@ -122,7 +122,7 @@ if (s ~ "s") {
|
||||
|
||||
# Remove existing data file
|
||||
function openim::wrk::prepare() {
|
||||
rm -f ${wrkdir}/${datfile}
|
||||
rm -f "${wrkdir}"/"${datfile}"
|
||||
}
|
||||
|
||||
# Plot according to gunplot data file
|
||||
@ -216,7 +216,7 @@ openim::wrk::start_performance_test() {
|
||||
do
|
||||
wrkcmd="${cmd} -c ${c} $1"
|
||||
echo "Running wrk command: ${wrkcmd}"
|
||||
result=`eval ${wrkcmd}`
|
||||
result=$(eval "${wrkcmd}")
|
||||
openim::wrk::convert_plot_data "${result}"
|
||||
done
|
||||
|
||||
@ -241,9 +241,10 @@ while getopts "hd:n:" opt;do
|
||||
esac
|
||||
done
|
||||
|
||||
shift $(($OPTIND-1))
|
||||
shift $((OPTIND-1))
|
||||
|
||||
mkdir -p "${wrkdir}"
|
||||
|
||||
mkdir -p ${wrkdir}
|
||||
case $1 in
|
||||
"diff")
|
||||
if [ "$#" -lt 3 ];then
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user