Mono repo -> Master (#22553)
Combines the following repositories into one: https://github.com/mattermost/mattermost-server https://github.com/mattermost/mattermost-webapp https://github.com/mattermost/focalboard https://github.com/mattermost/mattermost-plugin-playbooks
Этот коммит содержится в:
46
server/scripts/config_generator/main.go
Обычный файл
46
server/scripts/config_generator/main.go
Обычный файл
@@ -0,0 +1,46 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
)
|
||||
|
||||
// generateDefaultConfig writes default config to outputFile.
|
||||
func generateDefaultConfig(outputFile *os.File) error {
|
||||
defaultCfg := &model.Config{}
|
||||
defaultCfg.SetDefaults()
|
||||
if data, err := json.MarshalIndent(defaultCfg, "", " "); err != nil {
|
||||
return err
|
||||
} else if _, err := outputFile.Write(data); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
outputFile := os.Getenv("OUTPUT_CONFIG")
|
||||
if outputFile == "" {
|
||||
fmt.Println("Output file name is missing. Please set OUTPUT_CONFIG env variable to absolute path")
|
||||
os.Exit(2)
|
||||
}
|
||||
if _, err := os.Stat(outputFile); !os.IsNotExist(err) {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "File %s already exists. Not overwriting!\n", outputFile)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
if file, err := os.Create(outputFile); err == nil {
|
||||
err = generateDefaultConfig(file)
|
||||
_ = file.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
39
server/scripts/config_generator/main_test.go
Обычный файл
39
server/scripts/config_generator/main_test.go
Обычный файл
@@ -0,0 +1,39 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestDefaultsGenerator(t *testing.T) {
|
||||
tmpFile, err := os.CreateTemp("", "tempconfig")
|
||||
defer os.Remove(tmpFile.Name())
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, generateDefaultConfig(tmpFile))
|
||||
_ = tmpFile.Close()
|
||||
var config model.Config
|
||||
|
||||
b, err := os.ReadFile(tmpFile.Name())
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, json.Unmarshal(b, &config))
|
||||
require.Equal(t, *config.SqlSettings.AtRestEncryptKey, "")
|
||||
require.Equal(t, *config.FileSettings.PublicLinkSalt, "")
|
||||
|
||||
require.Equal(t, *config.Office365Settings.Scope, model.Office365SettingsDefaultScope)
|
||||
require.Equal(t, *config.Office365Settings.AuthEndpoint, model.Office365SettingsDefaultAuthEndpoint)
|
||||
require.Equal(t, *config.Office365Settings.UserAPIEndpoint, model.Office365SettingsDefaultUserAPIEndpoint)
|
||||
require.Equal(t, *config.Office365Settings.TokenEndpoint, model.Office365SettingsDefaultTokenEndpoint)
|
||||
|
||||
require.Equal(t, *config.GoogleSettings.Scope, model.GoogleSettingsDefaultScope)
|
||||
require.Equal(t, *config.GoogleSettings.AuthEndpoint, model.GoogleSettingsDefaultAuthEndpoint)
|
||||
require.Equal(t, *config.GoogleSettings.UserAPIEndpoint, model.GoogleSettingsDefaultUserAPIEndpoint)
|
||||
require.Equal(t, *config.GoogleSettings.TokenEndpoint, model.GoogleSettingsDefaultTokenEndpoint)
|
||||
}
|
||||
47
server/scripts/diff-config.sh
Исполняемый файл
47
server/scripts/diff-config.sh
Исполняемый файл
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
./jq-dep-check.sh
|
||||
|
||||
if [ -z "$FROM" ]
|
||||
then
|
||||
echo "Missing FROM version. Usage: make diff-config FROM=1.1.1 TO=2.2.2"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$TO" ]
|
||||
then
|
||||
echo "Missing TO version. Usage: make diff-config FROM=1.1.1 TO=2.2.2"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Returns the config file for a specific release
|
||||
fetch_config() {
|
||||
local url="https://releases.mattermost.com/$1/mattermost-$1-linux-amd64.tar.gz"
|
||||
curl -sf "$url" | tar -xzOf - mattermost/config/config.json | jq -S .
|
||||
}
|
||||
|
||||
echo Fetching config files
|
||||
from_config="$(fetch_config "$FROM")"
|
||||
if [ -z "$from_config" ]
|
||||
then
|
||||
echo Invalid version "$FROM"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
to_config=$(fetch_config "$TO")
|
||||
if [ -z "$to_config" ]
|
||||
then
|
||||
echo Invalid version "$TO"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo Comparing config files
|
||||
diff -y <(echo "$from_config") <(echo "$to_config")
|
||||
|
||||
# We ignore exits with 1 since it just means there's a difference, which is fine for us.
|
||||
diff_exit=$?
|
||||
if [ $diff_exit -eq 1 ]; then
|
||||
exit 0
|
||||
else
|
||||
exit $diff_exit
|
||||
fi
|
||||
11
server/scripts/diff-email-templates.sh
Исполняемый файл
11
server/scripts/diff-email-templates.sh
Исполняемый файл
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
make build-templates
|
||||
|
||||
if [[ `git status templates/ --porcelain` ]]; then
|
||||
echo "mjml templates have changed; Please compile and include compiled files"
|
||||
git diff templates/ # show diffs as part of error message
|
||||
exit 1
|
||||
else
|
||||
echo "PASS"
|
||||
fi
|
||||
62
server/scripts/download_mmctl_release.sh
Исполняемый файл
62
server/scripts/download_mmctl_release.sh
Исполняемый файл
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env bash
|
||||
# $1 - version to download
|
||||
|
||||
if [[ "$OS" = "Windows_NT" ]]
|
||||
then
|
||||
PLATFORM="Windows"
|
||||
else
|
||||
PLATFORM=$(uname)-$(uname -m)
|
||||
fi
|
||||
|
||||
if [[ ! -z "$1" ]];
|
||||
then
|
||||
OVERRIDE_OS=$1
|
||||
fi
|
||||
|
||||
BIN_PATH=${2:-bin}
|
||||
|
||||
# strip whitespace
|
||||
THIS_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||
if [[ "$THIS_BRANCH" =~ 'release-'[0-9] ]];
|
||||
then
|
||||
RELEASE_TO_DOWNLOAD=$(echo $THIS_BRANCH | grep -Eo 'release-([0-9](\.){0,1})\.([0-9](\.){0,1})')
|
||||
else
|
||||
RELEASE_TO_DOWNLOAD=master
|
||||
fi
|
||||
|
||||
echo "Downloading prepackaged binary: https://releases.mattermost.com/mmctl/$RELEASE_TO_DOWNLOAD";
|
||||
|
||||
# When packaging we need to download different platforms
|
||||
# Values need to match the case statement below
|
||||
if [[ ! -z "$OVERRIDE_OS" ]];
|
||||
then
|
||||
PLATFORM="$OVERRIDE_OS"
|
||||
fi
|
||||
|
||||
case "$PLATFORM" in
|
||||
|
||||
Linux-x86_64)
|
||||
MMCTL_FILE="linux_amd64.tar" && curl -f -O -L https://releases.mattermost.com/mmctl/"$RELEASE_TO_DOWNLOAD"/"$MMCTL_FILE" && tar -xvf "$MMCTL_FILE" -C "$BIN_PATH" && rm "$MMCTL_FILE";
|
||||
;;
|
||||
|
||||
Linux-aarch64)
|
||||
MMCTL_FILE="linux_arm64.tar" && curl -f -O -L https://releases.mattermost.com/mmctl/"$RELEASE_TO_DOWNLOAD"/"$MMCTL_FILE" && tar -xvf "$MMCTL_FILE" -C "$BIN_PATH" && rm "$MMCTL_FILE";
|
||||
;;
|
||||
|
||||
Darwin-x86_64)
|
||||
MMCTL_FILE="darwin_amd64.tar" && curl -f -O -L https://releases.mattermost.com/mmctl/"$RELEASE_TO_DOWNLOAD"/"$MMCTL_FILE" && tar -xvf "$MMCTL_FILE" -C "$BIN_PATH" && rm "$MMCTL_FILE";
|
||||
;;
|
||||
|
||||
Darwin-arm64)
|
||||
MMCTL_FILE="darwin_arm64.tar" && curl -f -O -L https://releases.mattermost.com/mmctl/"$RELEASE_TO_DOWNLOAD"/"$MMCTL_FILE" && tar -xvf "$MMCTL_FILE" -C "$BIN_PATH" && rm "$MMCTL_FILE";
|
||||
;;
|
||||
|
||||
Windows)
|
||||
MMCTL_FILE="windows_amd64.zip" && curl -f -O -L https://releases.mattermost.com/mmctl/"$RELEASE_TO_DOWNLOAD"/"$MMCTL_FILE" && unzip -o "$MMCTL_FILE" -d "$BIN_PATH" && rm "$MMCTL_FILE";
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "error downloading mmctl: can't detect OS";
|
||||
;;
|
||||
|
||||
esac
|
||||
57
server/scripts/get_latest_release.sh
Исполняемый файл
57
server/scripts/get_latest_release.sh
Исполняемый файл
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
# $1 - repo to check against
|
||||
# $2 - release branch pattern to match
|
||||
# This script will check if the current repo has version pattern $2 ('release-5.20') in the branch name.
|
||||
# If it does it will check for a matching release version in the $1 repo and if found check for the newest dot version.
|
||||
# If the branch pattern isn't found than it will default to the newest release available in $1.
|
||||
REPO_TO_USE=$1
|
||||
BRANCH_TO_USE=$2
|
||||
|
||||
BASIC_AUTH=""
|
||||
|
||||
# If we find a github username and token, we use that.
|
||||
# In CI, these variables are available and useful to avoid rate limits which is
|
||||
# much more strict for unauthenticated requests.
|
||||
if [[ ! -z "$GITHUB_USERNAME" && ! -z "$GITHUB_TOKEN" ]];
|
||||
then
|
||||
BASIC_AUTH="--user $GITHUB_USERNAME:$GITHUB_TOKEN"
|
||||
fi
|
||||
|
||||
LATEST_RELEASE=$(curl \
|
||||
--silent \
|
||||
$BASIC_AUTH \
|
||||
"https://api.github.com/repos/$REPO_TO_USE/releases/latest")
|
||||
|
||||
RELEASES=$(curl \
|
||||
--silent \
|
||||
$BASIC_AUTH \
|
||||
"https://api.github.com/repos/$REPO_TO_USE/releases")
|
||||
|
||||
LATEST_REL=$(echo "$LATEST_RELEASE" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
|
||||
|
||||
DRAFT=$(echo "$LATEST_RELEASE" | grep '"draft":' | sed -E 's/.*: ([^,]+).*/\1/')
|
||||
|
||||
PRERELEASE=$(echo "$RELEASES" | grep '"prerelease":' | sed -E 's/.*: ([^,]+).*/\1/')
|
||||
|
||||
# Check if this is a release branch
|
||||
THIS_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||
#THIS_BRANCH="release-5.27"# - Used to test release logic on a non release branch
|
||||
|
||||
if [[ "$THIS_BRANCH" =~ $BRANCH_TO_USE || $DRAFT =~ "true" ]]; then
|
||||
VERSION_REL=${THIS_BRANCH//$BRANCH_TO_USE/v}
|
||||
REL_TO_USE=$(echo "$RELEASES" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' | sed -n "/$VERSION_REL/p" | sort -rV | head -n 1)
|
||||
elif [[ "$THIS_BRANCH" =~ "master" ]]; then
|
||||
# Get the latest release even if its a pre-release
|
||||
REL_TO_USE=$(echo "$RELEASES" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' | sort -rV | head -n 1)
|
||||
else
|
||||
REL_TO_USE=$LATEST_REL
|
||||
fi
|
||||
|
||||
if [[ -z "$REL_TO_USE" ]]
|
||||
then
|
||||
echo "An error has occurred trying to get the latest mmctl release. Aborting. Perhaps api.github.com is down, or you are being rate-limited.";
|
||||
echo "Set the GITHUB_USERNAME and GITHUB_TOKEN environment variables to the appropriate values to work around GitHub rate-limiting.";
|
||||
exit 1;
|
||||
else
|
||||
echo "$REL_TO_USE"
|
||||
fi
|
||||
9
server/scripts/jq-dep-check.sh
Исполняемый файл
9
server/scripts/jq-dep-check.sh
Исполняемый файл
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
jq_cmd=jq
|
||||
[[ $(type -P "$jq_cmd") ]] || {
|
||||
echo "'$jq_cmd' command line JSON processor not found";
|
||||
echo "Please install on linux with 'sudo apt-get install jq'"
|
||||
echo "Please install on mac with 'brew install jq'"
|
||||
exit 1;
|
||||
}
|
||||
83
server/scripts/ldap-check.sh
Исполняемый файл
83
server/scripts/ldap-check.sh
Исполняемый файл
@@ -0,0 +1,83 @@
|
||||
#!/bin/bash
|
||||
|
||||
./jq-dep-check.sh
|
||||
|
||||
ldapsearch_cmd=ldapsearch
|
||||
[[ $(type -P "$ldapsearch_cmd") ]] || {
|
||||
echo "'$ldapsearch_cmd' shell accessible interface to ldap not found";
|
||||
echo "Please install on linux with 'sudo apt-get install ldap-utils'"
|
||||
exit 1;
|
||||
}
|
||||
|
||||
if [[ -z ${1} ]]; then
|
||||
echo "We could not find a username";
|
||||
echo "usage: ./ldap-check.sh -u/-g [username/groupname]"
|
||||
echo "example: ./ldap-check.sh -u john"
|
||||
echo "example: ./ldap-check.sh -g admin-staff"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
echo "Looking for config.json"
|
||||
|
||||
config_file=
|
||||
if [[ -e "./config.json" ]]; then
|
||||
config_file="./config.json"
|
||||
echo "Found config at $config_file";
|
||||
fi
|
||||
|
||||
if [[ -z ${config_file} && -e "./config/config.json" ]]; then
|
||||
config_file="./config/config.json"
|
||||
echo "Found config at $config_file";
|
||||
fi
|
||||
|
||||
if [[ -z ${config_file} && -e "../config/config.json" ]]; then
|
||||
config_file="../config/config.json"
|
||||
echo "Found config at $config_file";
|
||||
fi
|
||||
|
||||
if [[ -z ${config_file} ]]; then
|
||||
echo "We could not find config.json";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
LdapServer=`cat $config_file | jq -r .LdapSettings.LdapServer`
|
||||
LdapPort=`cat $config_file | jq -r .LdapSettings.LdapPort`
|
||||
BindUsername=`cat $config_file | jq -r .LdapSettings.BindUsername`
|
||||
BindPassword=`cat $config_file | jq -r .LdapSettings.BindPassword`
|
||||
BaseDN=`cat $config_file | jq -r .LdapSettings.BaseDN`
|
||||
UserFilter=`cat $config_file | jq -r .LdapSettings.UserFilter`
|
||||
EmailAttribute=`cat $config_file | jq -r .LdapSettings.EmailAttribute`
|
||||
UsernameAttribute=`cat $config_file | jq -r .LdapSettings.UsernameAttribute`
|
||||
IdAttribute=`cat $config_file | jq -r .LdapSettings.IdAttribute`
|
||||
GroupFilter=`cat $config_file | jq -r .LdapSettings.GroupFilter`
|
||||
GroupIdAttribute=`cat $config_file | jq -r .LdapSettings.GroupIdAttribute`
|
||||
|
||||
if [[ -z ${UserFilter} ]]; then
|
||||
UserFilter="($IdAttribute=$2)"
|
||||
else
|
||||
UserFilter="(&($IdAttribute=$2)$UserFilter)"
|
||||
fi
|
||||
|
||||
if [[ -z ${GroupFilter} ]]; then
|
||||
GroupFilter="($GroupIdAttribute=$2)"
|
||||
else
|
||||
GroupFilter="(&($GroupIdAttribute=$2)$GroupFilter)"
|
||||
fi
|
||||
|
||||
if [[ $1 == '-u' ]]; then
|
||||
|
||||
cmd_to_run="$ldapsearch_cmd -LLL -x -h $LdapServer -p $LdapPort -D \"$BindUsername\" -w \"$BindPassword\" -b \"$BaseDN\" \"$UserFilter\" $IdAttribute $UsernameAttribute $EmailAttribute"
|
||||
echo $cmd_to_run
|
||||
echo "-------------------------"
|
||||
eval $cmd_to_run
|
||||
|
||||
elif [[ $1 == '-g' ]]; then
|
||||
|
||||
cmd_to_run="$ldapsearch_cmd -LLL -x -h $LdapServer -p $LdapPort -D \"$BindUsername\" -w \"$BindPassword\" -b \"$BaseDN\" \"$GroupFilter\""
|
||||
echo $cmd_to_run
|
||||
echo "-------------------------"
|
||||
eval $cmd_to_run
|
||||
|
||||
else
|
||||
echo "User or Group not specified"
|
||||
fi
|
||||
1057
server/scripts/mattermost-mysql-5.0.0.sql
Обычный файл
1057
server/scripts/mattermost-mysql-5.0.0.sql
Обычный файл
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
1198
server/scripts/mattermost-mysql-6.0.0.sql
Обычный файл
1198
server/scripts/mattermost-mysql-6.0.0.sql
Обычный файл
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
1818
server/scripts/mattermost-postgresql-5.0.0.sql
Обычный файл
1818
server/scripts/mattermost-postgresql-5.0.0.sql
Обычный файл
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2378
server/scripts/mattermost-postgresql-6.0.0.sql
Обычный файл
2378
server/scripts/mattermost-postgresql-6.0.0.sql
Обычный файл
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
59
server/scripts/mysql-migration-test.sh
Исполняемый файл
59
server/scripts/mysql-migration-test.sh
Исполняемый файл
@@ -0,0 +1,59 @@
|
||||
./scripts/jq-dep-check.sh
|
||||
|
||||
TMPDIR=`mktemp -d 2>/dev/null || mktemp -d -t 'tmpConfigDir'`
|
||||
DUMPDIR=`mktemp -d 2>/dev/null || mktemp -d -t 'dumpDir'`
|
||||
SCHEMA_VERSION=$1
|
||||
|
||||
echo "Creating databases"
|
||||
docker exec mattermost-mysql mysql -uroot -pmostest -e "CREATE DATABASE migrated; CREATE DATABASE latest; GRANT ALL PRIVILEGES ON migrated.* TO mmuser; GRANT ALL PRIVILEGES ON latest.* TO mmuser"
|
||||
|
||||
echo "Importing mysql dump from version ${SCHEMA_VERSION}"
|
||||
docker exec -i mattermost-mysql mysql -D migrated -uroot -pmostest < $(pwd)/scripts/mattermost-mysql-$SCHEMA_VERSION.sql
|
||||
|
||||
docker exec -i mattermost-mysql mysql -D migrated -uroot -pmostest -e "INSERT INTO Systems (Name, Value) VALUES ('Version', '$SCHEMA_VERSION')"
|
||||
|
||||
echo "Setting up config for db migration"
|
||||
cat config/config.json | \
|
||||
jq '.SqlSettings.DataSource = "mmuser:mostest@tcp(localhost:3306)/migrated?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s"' | \
|
||||
jq '.SqlSettings.DriverName = "mysql"' > $TMPDIR/config.json
|
||||
|
||||
echo "Running the migration"
|
||||
make ARGS="db migrate --config $TMPDIR/config.json" run-cli
|
||||
|
||||
echo "Setting up config for fresh db setup"
|
||||
cat config/config.json | \
|
||||
jq '.SqlSettings.DataSource = "mmuser:mostest@tcp(localhost:3306)/latest?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s"' | \
|
||||
jq '.SqlSettings.DriverName = "mysql"' > $TMPDIR/config.json
|
||||
|
||||
echo "Setting up fresh db"
|
||||
make ARGS="db migrate --config $TMPDIR/config.json" run-cli
|
||||
|
||||
if [ "$SCHEMA_VERSION" == "5.0.0" ]; then
|
||||
for i in "ChannelMembers SchemeGuest" "ChannelMembers MsgCountRoot" "ChannelMembers MentionCountRoot" "Channels TotalMsgCountRoot"; do
|
||||
a=( $i );
|
||||
echo "Ignoring known MySQL mismatch: ${a[0]}.${a[1]}"
|
||||
docker exec mattermost-mysql mysql -D migrated -uroot -pmostest -e "ALTER TABLE ${a[0]} DROP COLUMN ${a[1]};"
|
||||
docker exec mattermost-mysql mysql -D latest -uroot -pmostest -e "ALTER TABLE ${a[0]} DROP COLUMN ${a[1]};"
|
||||
done
|
||||
fi
|
||||
|
||||
echo "Generating dump"
|
||||
docker exec mattermost-mysql mysqldump --skip-opt --no-data --compact -u root -pmostest migrated > $DUMPDIR/migrated.sql
|
||||
docker exec mattermost-mysql mysqldump --skip-opt --no-data --compact -u root -pmostest latest > $DUMPDIR/latest.sql
|
||||
|
||||
echo "Removing databases created for db comparison"
|
||||
docker exec mattermost-mysql mysql -uroot -pmostest -e "DROP DATABASE migrated; DROP DATABASE latest"
|
||||
|
||||
echo "Generating diff"
|
||||
git diff --word-diff=color $DUMPDIR/migrated.sql $DUMPDIR/latest.sql > $DUMPDIR/diff.txt
|
||||
diffErrorCode=$?
|
||||
|
||||
if [ $diffErrorCode -eq 0 ]; then
|
||||
echo "Both schemas are same"
|
||||
else
|
||||
echo "Schema mismatch"
|
||||
cat $DUMPDIR/diff.txt
|
||||
fi
|
||||
rm -rf $TMPDIR $DUMPDIR
|
||||
|
||||
exit $diffErrorCode
|
||||
11
server/scripts/prereq-check-enterprise.sh
Исполняемый файл
11
server/scripts/prereq-check-enterprise.sh
Исполняемый файл
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
check_prereq()
|
||||
{
|
||||
local dependency=$1
|
||||
type "$dependency" >/dev/null 2>&1 || { echo >&2 "Mattermost Enterprise requires '$dependency' but it doesn't appear to be installed. Aborting."; exit 1; }
|
||||
}
|
||||
|
||||
echo "Checking enterprise prerequisites"
|
||||
|
||||
check_prereq 'xmlsec1'
|
||||
49
server/scripts/prereq-check.sh
Исполняемый файл
49
server/scripts/prereq-check.sh
Исполняемый файл
@@ -0,0 +1,49 @@
|
||||
#!/bin/bash
|
||||
check_version()
|
||||
{
|
||||
local version=$1 check=$2
|
||||
local winner=$(echo -e "$version\n$check" | sed '/^$/d' | sort -t. -s -k 1,1nr -k 2,2nr -k 3,3nr -k 4,4nr | head -1)
|
||||
[[ "$winner" = "$version" ]] && return 0
|
||||
return 1
|
||||
}
|
||||
|
||||
check_prereq()
|
||||
{
|
||||
if [ ! $# == 3 ]; then
|
||||
echo "Unable to determine '$1' version! Ensure that '$1' is in your path and try again." && exit 1
|
||||
fi
|
||||
|
||||
local dependency=$1 required_version=$2 installed_version=$3
|
||||
|
||||
type $dependency >/dev/null 2>&1 || { echo >&2 "Mattermost requires '$dependency' but it doesn't appear to be installed. Aborting."; exit 1; }
|
||||
|
||||
if check_version $installed_version $required_version; then
|
||||
echo "$dependency minimum requirement met. Required: $required_version, Found: $installed_version"
|
||||
else
|
||||
echo "WARNING! Mattermost did not find the minimum supported version of '$dependency' installed. Required: $required_version, Found: $installed_version"
|
||||
echo "We highly recommend stopping installation and updating dependencies before continuing"
|
||||
read -p "Enter Y to continue anyway (not recommended)." -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]
|
||||
then
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
echo "Checking prerequisites"
|
||||
|
||||
REQUIREDNODEVERSION=16.0.0
|
||||
REQUIREDNPMVERSION=7.10.0
|
||||
REQUIREDGOVERSION=1.18.0
|
||||
REQUIREDDOCKERVERSION=17.0
|
||||
|
||||
NODEVERSION=$(sed 's/v//' <<< $(node -v))
|
||||
NPMVERSION=$(npm -v)
|
||||
GOVERSION=$(sed -ne 's/[^0-9]*\(\([0-9]\.\)\{0,4\}[0-9][^.]\).*/\1/p' <<< $(go version))
|
||||
DOCKERVERSION=$(docker version --format '{{.Server.Version}}' | sed 's/[a-z-]//g')
|
||||
|
||||
check_prereq 'node' $REQUIREDNODEVERSION $NODEVERSION
|
||||
check_prereq 'npm' $REQUIREDNPMVERSION $NPMVERSION
|
||||
check_prereq 'go' $REQUIREDGOVERSION $GOVERSION
|
||||
check_prereq 'docker' $REQUIREDDOCKERVERSION $DOCKERVERSION
|
||||
59
server/scripts/psql-migration-test.sh
Исполняемый файл
59
server/scripts/psql-migration-test.sh
Исполняемый файл
@@ -0,0 +1,59 @@
|
||||
./scripts/jq-dep-check.sh
|
||||
|
||||
TMPDIR=`mktemp -d 2>/dev/null || mktemp -d -t 'tmpConfigDir'`
|
||||
DUMPDIR=`mktemp -d 2>/dev/null || mktemp -d -t 'dumpDir'`
|
||||
SCHEMA_VERSION=$1
|
||||
|
||||
echo "Creating databases"
|
||||
docker exec mattermost-postgres sh -c 'exec echo "CREATE DATABASE migrated; CREATE DATABASE latest;" | exec psql -U mmuser mattermost_test'
|
||||
|
||||
echo "Importing postgres dump from version ${SCHEMA_VERSION}"
|
||||
docker exec -i mattermost-postgres psql -U mmuser -d migrated < $(pwd)/scripts/mattermost-postgresql-$SCHEMA_VERSION.sql
|
||||
|
||||
docker exec -i mattermost-postgres psql -U mmuser -d migrated -c "INSERT INTO Systems (Name, Value) VALUES ('Version', '$SCHEMA_VERSION')"
|
||||
|
||||
echo "Setting up config for db migration"
|
||||
cat config/config.json | \
|
||||
jq '.SqlSettings.DataSource = "postgres://mmuser:mostest@localhost:5432/migrated?sslmode=disable&connect_timeout=10"'| \
|
||||
jq '.SqlSettings.DriverName = "postgres"' > $TMPDIR/config.json
|
||||
|
||||
echo "Running the migration"
|
||||
make ARGS="db migrate --config $TMPDIR/config.json" run-cli
|
||||
|
||||
echo "Setting up config for fresh db setup"
|
||||
cat config/config.json | \
|
||||
jq '.SqlSettings.DataSource = "postgres://mmuser:mostest@localhost:5432/latest?sslmode=disable&connect_timeout=10"'| \
|
||||
jq '.SqlSettings.DriverName = "postgres"' > $TMPDIR/config.json
|
||||
|
||||
echo "Setting up fresh db"
|
||||
make ARGS="db migrate --config $TMPDIR/config.json" run-cli
|
||||
|
||||
if [ "$SCHEMA_VERSION" == "5.0.0" ]; then
|
||||
for i in "ChannelMembers MentionCountRoot" "ChannelMembers MsgCountRoot" "Channels TotalMsgCountRoot"; do
|
||||
a=( $i );
|
||||
echo "Ignoring known Postgres mismatch: ${a[0]}.${a[1]}"
|
||||
docker exec mattermost-postgres psql -U mmuser -d migrated -c "ALTER TABLE ${a[0]} DROP COLUMN ${a[1]};"
|
||||
docker exec mattermost-postgres psql -U mmuser -d latest -c "ALTER TABLE ${a[0]} DROP COLUMN ${a[1]};"
|
||||
done
|
||||
fi
|
||||
|
||||
echo "Generating dump"
|
||||
docker exec mattermost-postgres pg_dump --schema-only -d migrated -U mmuser > $DUMPDIR/migrated.sql
|
||||
docker exec mattermost-postgres pg_dump --schema-only -d latest -U mmuser > $DUMPDIR/latest.sql
|
||||
|
||||
echo "Removing databases created for db comparison"
|
||||
docker exec mattermost-postgres sh -c 'exec echo "DROP DATABASE migrated; DROP DATABASE latest;" | exec psql -U mmuser mattermost_test'
|
||||
|
||||
echo "Generating diff"
|
||||
git diff --word-diff=color $DUMPDIR/migrated.sql $DUMPDIR/latest.sql > $DUMPDIR/diff.txt
|
||||
diffErrorCode=$?
|
||||
|
||||
if [ $diffErrorCode -eq 0 ]; then
|
||||
echo "Both schemas are same"
|
||||
else
|
||||
echo "Schema mismatch"
|
||||
cat $DUMPDIR/diff.txt
|
||||
fi
|
||||
rm -rf $TMPDIR $DUMPDIR
|
||||
|
||||
exit $diffErrorCode
|
||||
4
server/scripts/replica-lag-set.sh
Исполняемый файл
4
server/scripts/replica-lag-set.sh
Исполняемый файл
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
stmt="STOP SLAVE SQL_THREAD FOR CHANNEL '';CHANGE MASTER TO MASTER_DELAY = $1;START SLAVE SQL_THREAD FOR CHANNEL '';SHOW SLAVE STATUS\G;"
|
||||
docker exec mattermost-mysql-read-replica sh -c "export MYSQL_PWD=mostest; mysql -u root -e \"$stmt\"" | grep SQL_Delay
|
||||
32
server/scripts/replica-mysql-config.sh
Исполняемый файл
32
server/scripts/replica-mysql-config.sh
Исполняемый файл
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
until docker exec mattermost-mysql sh -c 'mysql -u root -pmostest -e ";"'
|
||||
do
|
||||
echo "Waiting for mattermost-mysql database connection..."
|
||||
sleep 4
|
||||
done
|
||||
|
||||
priv_stmt='GRANT REPLICATION SLAVE ON *.* TO "mmuser"@"%" IDENTIFIED BY "mostest"; FLUSH PRIVILEGES;'
|
||||
docker exec mattermost-mysql sh -c "mysql -u root -pmostest -e '$priv_stmt'"
|
||||
|
||||
until docker-compose -f docker-compose.makefile.yml exec mysql-read-replica sh -c 'mysql -u root -pmostest -e ";"'
|
||||
do
|
||||
echo "Waiting for mysql-read-replica database connection..."
|
||||
sleep 4
|
||||
done
|
||||
|
||||
docker-ip() {
|
||||
docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$@"
|
||||
}
|
||||
|
||||
MS_STATUS=`docker exec mattermost-mysql sh -c 'mysql -u root -pmostest -e "SHOW MASTER STATUS"'`
|
||||
CURRENT_LOG=`echo $MS_STATUS | awk '{print $6}'`
|
||||
CURRENT_POS=`echo $MS_STATUS | awk '{print $7}'`
|
||||
|
||||
start_slave_stmt="CHANGE MASTER TO MASTER_HOST='$(docker-ip mattermost-mysql)',MASTER_USER='mmuser',MASTER_PASSWORD='mostest',MASTER_LOG_FILE='$CURRENT_LOG',MASTER_LOG_POS=$CURRENT_POS; START SLAVE;"
|
||||
start_slave_cmd='mysql -u root -pmostest -e "'
|
||||
start_slave_cmd+="$start_slave_stmt"
|
||||
start_slave_cmd+='"'
|
||||
docker exec mattermost-mysql-read-replica sh -c "$start_slave_cmd"
|
||||
|
||||
docker exec mattermost-mysql-read-replica sh -c "mysql -u root -pmostest -e 'SHOW SLAVE STATUS \G'"
|
||||
20
server/scripts/setup_go_work.sh
Исполняемый файл
20
server/scripts/setup_go_work.sh
Исполняемый файл
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ $1 != "true" ]] ;
|
||||
then
|
||||
echo "Creating a go.work file"
|
||||
|
||||
txt="go 1.19\n\nuse ./\n"
|
||||
|
||||
if [ "$BUILD_ENTERPRISE_READY" == "true" ]
|
||||
then
|
||||
txt="${txt}use ../enterprise\n"
|
||||
fi
|
||||
|
||||
if [ "$BUILD_PLAYBOOKS" == "true" ]
|
||||
then
|
||||
txt="${txt}use ../mattermost-plugin-playbooks\n"
|
||||
fi
|
||||
|
||||
printf "$txt" > "../go.work"
|
||||
fi
|
||||
9
server/scripts/test-xprog.sh
Исполняемый файл
9
server/scripts/test-xprog.sh
Исполняемый файл
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
[[ $1 =~ (github.com.*)/_test ]] && \
|
||||
echo Testing ${BASH_REMATCH[1]}
|
||||
coverprofile=`pwd`/cprofile.out
|
||||
if [[ $1 == *"/enterprise/"* ]]; then
|
||||
cd "$(dirname "$(dirname "${BASH_SOURCE[0]}")")"
|
||||
fi
|
||||
"$@" -test.coverprofile "$coverprofile"
|
||||
38
server/scripts/test.sh
Исполняемый файл
38
server/scripts/test.sh
Исполняемый файл
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
set -o pipefail
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
||||
|
||||
GO=$1
|
||||
GOFLAGS=$2
|
||||
PACKAGES=$3
|
||||
TESTS=$4
|
||||
TESTFLAGS=$5
|
||||
GOBIN=$6
|
||||
TIMEOUT=$7
|
||||
COVERMODE=$8
|
||||
|
||||
PACKAGES_COMMA=$(echo $PACKAGES | tr ' ' ',')
|
||||
export MM_SERVER_PATH=$PWD
|
||||
|
||||
echo "Packages to test: $PACKAGES"
|
||||
echo "GOFLAGS: $GOFLAGS"
|
||||
|
||||
if [[ $GOFLAGS == "-race " && $IS_CI == "true" ]] ;
|
||||
then
|
||||
export GOMAXPROCS=4
|
||||
fi
|
||||
|
||||
find . -name 'cprofile*.out' -exec sh -c 'rm "{}"' \;
|
||||
find . -type d -name data -not -path './data' | xargs rm -rf
|
||||
|
||||
$GO test $GOFLAGS -run=$TESTS $TESTFLAGS -v -timeout=$TIMEOUT -covermode=$COVERMODE -coverpkg=$PACKAGES_COMMA -exec $DIR/test-xprog.sh $PACKAGES 2>&1 > >( tee output )
|
||||
EXIT_STATUS=$?
|
||||
|
||||
cat output | $GOBIN/go-junit-report > report.xml
|
||||
rm output
|
||||
find . -name 'cprofile*.out' -exec sh -c 'tail -n +2 "{}" >> cover.out ; rm "{}"' \;
|
||||
rm -f config/*.crt
|
||||
rm -f config/*.key
|
||||
|
||||
exit $EXIT_STATUS
|
||||
20
server/scripts/wait-for-system-start.sh
Исполняемый файл
20
server/scripts/wait-for-system-start.sh
Исполняемый файл
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
total=0
|
||||
max_wait_seconds=60
|
||||
|
||||
echo "waiting $max_wait_seconds seconds for the server to start"
|
||||
|
||||
while [[ "$total" -le "$max_wait_seconds" ]]; do
|
||||
if bin/mmctl system status --local 2> /dev/null; then
|
||||
exit 0
|
||||
else
|
||||
((total=total+1))
|
||||
printf "."
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
|
||||
printf "\nserver didn't start in $max_wait_seconds seconds\n"
|
||||
|
||||
exit 1
|
||||
Ссылка в новой задаче
Block a user