forked from remiheens/mattermost-docker-arm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·140 lines (132 loc) · 5.55 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
set -eux
# build user
BUILD_USER_HOME="${BUILD_USER_HOME:-/build}"
BUILD_USER_NAME="${BUILD_USER_NAME:-build}"
# Debian release used during build
DEBIAN_RELEASE="${DEBIAN_RELEASE:-bookworm}"
# Mattermost version to build
MATTERMOST_VERSION="${MATTERMOST_VERSION:-v5.26.0}"
# golang version
GO_VERSION="${GO_VERSION:-1.20.8}"
if [ "$(id -u)" -eq 0 ]; then # as root user
# create build user, if needed
set +e
if ! id -u "${BUILD_USER_NAME}"; then # create build user
set -e
useradd --create-home --home-dir "${BUILD_USER_HOME}" --skel "${PWD}" \
"${BUILD_USER_NAME}"
fi
set -e
# configure apt
printf 'APT::Install-Recommends "0";' \
> '/etc/apt/apt.conf.d/99-no-install-recommends'
printf 'APT::Install-Suggests "0";' \
> '/etc/apt/apt.conf.d/99-no-install-suggests'
printf 'APT::Get::Assume-Yes "true";' \
> '/etc/apt/apt.conf.d/99-assume-yes'
# update repositories
apt-get update
# dependencies to setup repositories
apt-get install --quiet \
gnupg2 dirmngr apt-transport-https ca-certificates curl
# add required additional repositories
printf 'deb-src http://deb.debian.org/debian %s main' "${DEBIAN_RELEASE}" \
> "/etc/apt/sources.list.d/${DEBIAN_RELEASE}-source.list"
printf 'deb http://deb.debian.org/debian %s-backports main' "${DEBIAN_RELEASE}" \
> "/etc/apt/sources.list.d/${DEBIAN_RELEASE}-backports.list"
# update repositories
apt-get update
# install dependencies
apt-get install --quiet \
wget build-essential patch git python3
# install 'pngquant' build dependencies (required by node module)
apt-get build-dep --quiet \
pngquant
# install go from golang.org
if [ ! -f go${GO_VERSION}.linux-amd64.tar.gz ]; then
wget https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz
fi
if [ ! -d /usr/local/go ]; then
tar -xvf go${GO_VERSION}.linux-amd64.tar.gz
mv go /usr/local
fi
export GOROOT=/usr/local/go
export PATH=$GOROOT/bin:$PATH
# FIXME go (executed by build user) writes to GOROOT
install --directory --owner="${BUILD_USER_NAME}" \
"$(go env GOROOT)/pkg/$(go env GOOS)_$(go env GOARCH)"
echo "GOOS_GOARCH=$(go env GOOS)_$(go env GOARCH)"
# Re-invoke this build.sh script with the 'build' user
runuser -u "${BUILD_USER_NAME}" -- "${0}"
# salvage build artifacts
cp --verbose \
"${BUILD_USER_HOME}/mattermost-${MATTERMOST_VERSION}-$(go env GOOS)-$(go env GOARCH).tar.gz" \
"${BUILD_USER_HOME}/mattermost-${MATTERMOST_VERSION}-$(go env GOOS)-$(go env GOARCH).tar.gz.sha512sum" \
"${HOME}"
exit 0
fi
# as non-root user
export GOROOT=/usr/local/go
export PATH=$GOROOT/bin:$PATH
cd "${HOME}"
# install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
# download and extract Mattermost sources
install --directory "${HOME}/go/src/github.com/mattermost/mattermost"
wget --quiet --continue --output-document="mattermost.tar.gz" \
"https://github.com/mattermost/mattermost/archive/${MATTERMOST_VERSION}.tar.gz"
tar --directory="${HOME}/go/src/github.com/mattermost/mattermost" \
--strip-components=1 --extract --file="mattermost.tar.gz"
# install mattermost-webapp's required version of nodejs
pushd "${HOME}/go/src/github.com/mattermost/mattermost/webapp"
nvm install
popd
# prepare the go build environment
install --directory "${HOME}/go/bin"
if [ "$(go env GOOS)_$(go env GOARCH)" != 'linux_amd64' ] && [ ! -f "${HOME}/go/bin/linux_amd64" ] && [ ! -h "${HOME}/go/bin/linux_amd64" ]; then
ln --symbolic \
"${HOME}/go/bin/$(go env GOOS)_$(go env GOARCH)" \
"${HOME}/go/bin/linux_amd64"
fi
# # build Mattermost webapp
npm set progress false
sed -i -e 's#--verbose#--display minimal#' \
"${HOME}/go/src/github.com/mattermost/mattermost/webapp/package.json"
make --directory="${HOME}/go/src/github.com/mattermost/mattermost/webapp" \
dist
# build Mattermost server
patch --directory="${HOME}/go/src/github.com/mattermost/mattermost/server" \
--strip=1 -t < "/root/build-release.patch"
sed -i \
-e 's#go generate#env --unset=GOOS --unset=GOARCH go generate#' \
-e 's#$(GO) generate#env --unset=GOOS --unset=GOARCH go generate#' \
-e 's#PWD#CURDIR#' \
"${HOME}/go/src/github.com/mattermost/mattermost/server/Makefile" \
"${HOME}/go/src/github.com/mattermost/mattermost/server/build/release.mk"
make --directory="${HOME}/go/src/github.com/mattermost/mattermost/server" \
config-reset \
BUILD_NUMBER="dev-$(go env GOOS)-$(go env GOARCH)-${MATTERMOST_VERSION}" \
GO="GOARCH= GOOS= $(command -v go)" \
PLUGIN_PACKAGES=''
make --directory="${HOME}/go/src/github.com/mattermost/mattermost/server" \
setup-go-work \
BUILD_NUMBER="dev-$(go env GOOS)-$(go env GOARCH)-${MATTERMOST_VERSION}" \
GO="GOARCH= GOOS= $(command -v go)" \
PLUGIN_PACKAGES=''
make --directory="${HOME}/go/src/github.com/mattermost/mattermost/server" \
build-linux package-linux \
BUILD_NUMBER="dev-$(go env GOOS)-$(go env GOARCH)-${MATTERMOST_VERSION}" \
BUILD_BOARDS=0 \
BUILD_ENTERPRISE=0 \
GO="GOARCH=$(go env GOARCH) GOOS=$(go env GOOS) $(command -v go)" \
PLUGIN_PACKAGES=''
# test archive before using it by listing its contents
tar -tzf "${HOME}/go/src/github.com/mattermost/mattermost/server/dist/mattermost-team-linux-amd64.tar.gz"
# rename archive and calculate its SHA512 sum
mv "${HOME}/go/src/github.com/mattermost/mattermost/server/dist/mattermost-team-linux-amd64.tar.gz" \
"${HOME}/mattermost-${MATTERMOST_VERSION}-$(go env GOOS)-$(go env GOARCH).tar.gz"
sha512sum "${HOME}/mattermost-${MATTERMOST_VERSION}-$(go env GOOS)-$(go env GOARCH).tar.gz" | \
tee "${HOME}/mattermost-${MATTERMOST_VERSION}-$(go env GOOS)-$(go env GOARCH).tar.gz.sha512sum"