mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-25 18:08:14 +08:00
Fix Docker build versioning (#20077)
* Centralise version scripts and fix Docker version * Refactor generation of a git-hash-based version into get-version-from-git * Refactor normalization of versions (stripping leading v) into normalize-version.sh * Call get-version-from-git from ci_package.sh, call normalize-version from package.sh * Refactor docker-write-version.sh into docker-package.sh, which both writes the version file and invokes yarn build passing VERSION * Normalize the version received from the server
This commit is contained in:
parent
b3c5bb899b
commit
b0abbfacd4
@ -16,15 +16,12 @@ WORKDIR /src
|
|||||||
COPY . /src
|
COPY . /src
|
||||||
RUN dos2unix /src/scripts/docker-link-repos.sh && bash /src/scripts/docker-link-repos.sh
|
RUN dos2unix /src/scripts/docker-link-repos.sh && bash /src/scripts/docker-link-repos.sh
|
||||||
RUN yarn --network-timeout=100000 install
|
RUN yarn --network-timeout=100000 install
|
||||||
RUN yarn build
|
|
||||||
|
RUN dos2unix /src/scripts/docker-package.sh && bash /src/scripts/docker-package.sh
|
||||||
|
|
||||||
# Copy the config now so that we don't create another layer in the app image
|
# Copy the config now so that we don't create another layer in the app image
|
||||||
RUN cp /src/config.sample.json /src/webapp/config.json
|
RUN cp /src/config.sample.json /src/webapp/config.json
|
||||||
|
|
||||||
# Ensure we populate the version file
|
|
||||||
RUN dos2unix /src/scripts/docker-write-version.sh && bash /src/scripts/docker-write-version.sh
|
|
||||||
|
|
||||||
|
|
||||||
# App
|
# App
|
||||||
FROM nginx:alpine
|
FROM nginx:alpine
|
||||||
|
|
||||||
|
@ -1,17 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Runs package.sh setting the version to git hashes of the element-web,
|
# Runs package.sh, passing DIST_VERSION determined by git
|
||||||
# react-sdk & js-sdk checkouts, for the case where these dependencies
|
|
||||||
# are git checkouts.
|
|
||||||
|
|
||||||
set -ex
|
set -ex
|
||||||
|
|
||||||
rm dist/element-*.tar.gz || true # rm previous artifacts without failing if it doesn't exist
|
rm dist/element-*.tar.gz || true # rm previous artifacts without failing if it doesn't exist
|
||||||
|
|
||||||
# Since the deps are fetched from git, we can rev-parse
|
DIST_VERSION=`$(dirname $0)/get-version-from-git.sh`
|
||||||
REACT_SHA=$(cd node_modules/matrix-react-sdk; git rev-parse --short=12 HEAD)
|
|
||||||
JSSDK_SHA=$(cd node_modules/matrix-js-sdk; git rev-parse --short=12 HEAD)
|
|
||||||
|
|
||||||
VECTOR_SHA=$(git rev-parse --short=12 HEAD) # use the ACTUAL SHA rather than assume develop
|
CI_PACKAGE=true DIST_VERSION=$DIST_VERSION scripts/package.sh
|
||||||
|
|
||||||
CI_PACKAGE=true DIST_VERSION=$VECTOR_SHA-react-$REACT_SHA-js-$JSSDK_SHA scripts/package.sh
|
|
||||||
|
7
scripts/docker-write-version.sh → scripts/docker-package.sh
Normal file → Executable file
7
scripts/docker-write-version.sh → scripts/docker-package.sh
Normal file → Executable file
@ -13,10 +13,9 @@ DIST_VERSION=$TAG
|
|||||||
# for an appropriately tagged branch as well (heads/v1.2.3).
|
# for an appropriately tagged branch as well (heads/v1.2.3).
|
||||||
if [[ $BRANCH != HEAD && ! $BRANCH =~ heads/v.+ ]]
|
if [[ $BRANCH != HEAD && ! $BRANCH =~ heads/v.+ ]]
|
||||||
then
|
then
|
||||||
REACT_SHA=$(cd node_modules/matrix-react-sdk; git rev-parse --short=12 HEAD)
|
DIST_VERSION=`$(dirname $0)/get-version-from-git.sh`
|
||||||
JSSDK_SHA=$(cd node_modules/matrix-js-sdk; git rev-parse --short=12 HEAD)
|
|
||||||
VECTOR_SHA=$(git rev-parse --short=12 HEAD) # use the ACTUAL SHA rather than assume develop
|
|
||||||
DIST_VERSION=$VECTOR_SHA-react-$REACT_SHA-js-$JSSDK_SHA
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
DIST_VERSION=`$(dirname $0)/normalize-version.sh ${DIST_VERSION}`
|
||||||
|
VERSION=$DIST_VERSION yarn build
|
||||||
echo $DIST_VERSION > /src/webapp/version
|
echo $DIST_VERSION > /src/webapp/version
|
10
scripts/get-version-from-git.sh
Executable file
10
scripts/get-version-from-git.sh
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Echoes a version based on the git hashes of the element-web, react-sdk & js-sdk checkouts, for the case where
|
||||||
|
# these dependencies are git checkouts.
|
||||||
|
|
||||||
|
# Since the deps are fetched from git, we can rev-parse
|
||||||
|
REACT_SHA=$(cd node_modules/matrix-react-sdk; git rev-parse --short=12 HEAD)
|
||||||
|
JSSDK_SHA=$(cd node_modules/matrix-js-sdk; git rev-parse --short=12 HEAD)
|
||||||
|
VECTOR_SHA=$(git rev-parse --short=12 HEAD) # use the ACTUAL SHA rather than assume develop
|
||||||
|
echo $VECTOR_SHA-react-$REACT_SHA-js-$JSSDK_SHA
|
8
scripts/normalize-version.sh
Executable file
8
scripts/normalize-version.sh
Executable file
@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# If $1 looks like v1.2.3 or v1.2.3-foo, strip the leading v, then print it to stdout
|
||||||
|
if [[ $1 =~ ^v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+(-.+)?$ ]]; then
|
||||||
|
echo ${1:1}
|
||||||
|
else
|
||||||
|
echo $1
|
||||||
|
fi
|
@ -21,12 +21,7 @@ cp -r webapp element-$version
|
|||||||
# Just in case you have a local config, remove it before packaging
|
# Just in case you have a local config, remove it before packaging
|
||||||
rm element-$version/config.json || true
|
rm element-$version/config.json || true
|
||||||
|
|
||||||
# if $version looks like semver with leading v, strip it before writing to file
|
$(dirname $0)/normalize-version.sh ${version} > element-$version/version
|
||||||
if [[ ${version} =~ ^v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+(-.+)?$ ]]; then
|
|
||||||
echo ${version:1} > element-$version/version
|
|
||||||
else
|
|
||||||
echo ${version} > element-$version/version
|
|
||||||
fi
|
|
||||||
|
|
||||||
tar chvzf dist/element-$version.tar.gz element-$version
|
tar chvzf dist/element-$version.tar.gz element-$version
|
||||||
rm -r element-$version
|
rm -r element-$version
|
||||||
|
@ -107,7 +107,7 @@ export default class WebPlatform extends VectorBasePlatform {
|
|||||||
// presence of intermediate caching proxies), but still: we're trying
|
// presence of intermediate caching proxies), but still: we're trying
|
||||||
// to tell the user that there is a new version.
|
// to tell the user that there is a new version.
|
||||||
|
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise((resolve, reject) => {
|
||||||
request(
|
request(
|
||||||
{
|
{
|
||||||
method: "GET",
|
method: "GET",
|
||||||
@ -121,27 +121,24 @@ export default class WebPlatform extends VectorBasePlatform {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ver = body.trim();
|
resolve(this.getNormalizedAppVersion(body.trim()));
|
||||||
resolve(ver);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getNormalizedAppVersion(): string {
|
getNormalizedAppVersion(version: string): string {
|
||||||
let ver = process.env.VERSION;
|
|
||||||
|
|
||||||
// if version looks like semver with leading v, strip it
|
// if version looks like semver with leading v, strip it
|
||||||
// (matches scripts/package.sh)
|
// (matches scripts/normalize-version.sh)
|
||||||
const semVerRegex = new RegExp("^v[0-9]+.[0-9]+.[0-9]+(-.+)?$");
|
const semVerRegex = new RegExp("^v[0-9]+.[0-9]+.[0-9]+(-.+)?$");
|
||||||
if (semVerRegex.test(process.env.VERSION)) {
|
if (semVerRegex.test(version)) {
|
||||||
ver = process.env.VERSION.substr(1);
|
return version.substr(1);
|
||||||
}
|
}
|
||||||
return ver;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAppVersion(): Promise<string> {
|
getAppVersion(): Promise<string> {
|
||||||
return Promise.resolve(this.getNormalizedAppVersion());
|
return Promise.resolve(this.getNormalizedAppVersion(process.env.VERSION));
|
||||||
}
|
}
|
||||||
|
|
||||||
startUpdater() {
|
startUpdater() {
|
||||||
@ -155,7 +152,7 @@ export default class WebPlatform extends VectorBasePlatform {
|
|||||||
|
|
||||||
pollForUpdate = () => {
|
pollForUpdate = () => {
|
||||||
return this.getMostRecentVersion().then((mostRecentVersion) => {
|
return this.getMostRecentVersion().then((mostRecentVersion) => {
|
||||||
const currentVersion = this.getNormalizedAppVersion();
|
const currentVersion = this.getNormalizedAppVersion(process.env.VERSION);
|
||||||
|
|
||||||
if (currentVersion !== mostRecentVersion) {
|
if (currentVersion !== mostRecentVersion) {
|
||||||
if (this.shouldShowUpdate(mostRecentVersion)) {
|
if (this.shouldShowUpdate(mostRecentVersion)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user