2021-06-11 18:24:59 +02:00
|
|
|
import { execCommand2, rootDir } from './tool-utils';
|
2021-07-08 15:04:03 +02:00
|
|
|
import * as moment from 'moment';
|
2021-06-11 18:24:59 +02:00
|
|
|
|
2021-09-23 17:48:26 +02:00
|
|
|
export function getVersionFromTag(tagName: string, isPreRelease: boolean): string {
|
2021-06-11 18:24:59 +02:00
|
|
|
if (tagName.indexOf('server-') !== 0) throw new Error(`Invalid tag: ${tagName}`);
|
|
|
|
const s = tagName.split('-');
|
2021-06-19 16:14:19 +02:00
|
|
|
const suffix = isPreRelease ? '-beta' : '';
|
|
|
|
return s[1].substr(1) + suffix;
|
2021-06-11 18:24:59 +02:00
|
|
|
}
|
|
|
|
|
2021-09-29 18:55:54 +02:00
|
|
|
export function getIsPreRelease(_tagName: string): boolean {
|
|
|
|
// For now we only create pre-releases from CI. It's after, once the release
|
|
|
|
// has been proven stable, that it is tagged as "latest".
|
|
|
|
return true;
|
|
|
|
// return tagName.indexOf('-beta') > 0;
|
2021-06-11 18:24:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
const argv = require('yargs').argv;
|
|
|
|
if (!argv.tagName) throw new Error('--tag-name not provided');
|
|
|
|
|
2021-08-14 17:58:08 +02:00
|
|
|
const pushImages = !!argv.pushImages;
|
2021-06-11 18:24:59 +02:00
|
|
|
const tagName = argv.tagName;
|
|
|
|
const isPreRelease = getIsPreRelease(tagName);
|
2021-06-19 16:14:19 +02:00
|
|
|
const imageVersion = getVersionFromTag(tagName, isPreRelease);
|
2021-07-08 15:04:03 +02:00
|
|
|
const buildDate = moment(new Date().getTime()).format('YYYY-MM-DDTHH:mm:ssZ');
|
|
|
|
let revision = '';
|
|
|
|
try {
|
|
|
|
revision = await execCommand2('git rev-parse --short HEAD', { showOutput: false });
|
|
|
|
} catch (error) {
|
|
|
|
console.info('Could not get git commit: metadata revision field will be empty');
|
|
|
|
}
|
2021-09-14 14:01:33 +02:00
|
|
|
const buildArgs = `--build-arg BUILD_DATE="${buildDate}" --build-arg REVISION="${revision}" --build-arg VERSION="${imageVersion}"`;
|
2021-07-25 11:38:36 +02:00
|
|
|
const dockerTags: string[] = [];
|
|
|
|
const versionPart = imageVersion.split('.');
|
2021-09-29 18:55:54 +02:00
|
|
|
dockerTags.push(isPreRelease ? 'beta' : 'latest');
|
2021-07-25 11:38:36 +02:00
|
|
|
dockerTags.push(versionPart[0] + (isPreRelease ? '-beta' : ''));
|
|
|
|
dockerTags.push(`${versionPart[0]}.${versionPart[1]}${isPreRelease ? '-beta' : ''}`);
|
|
|
|
dockerTags.push(imageVersion);
|
2021-06-11 18:24:59 +02:00
|
|
|
|
|
|
|
process.chdir(rootDir);
|
|
|
|
console.info(`Running from: ${process.cwd()}`);
|
|
|
|
|
|
|
|
console.info('tagName:', tagName);
|
2021-08-14 17:58:08 +02:00
|
|
|
console.info('pushImages:', pushImages);
|
2021-06-11 18:24:59 +02:00
|
|
|
console.info('imageVersion:', imageVersion);
|
|
|
|
console.info('isPreRelease:', isPreRelease);
|
2021-07-25 11:38:36 +02:00
|
|
|
console.info('Docker tags:', dockerTags.join(', '));
|
2021-06-11 18:24:59 +02:00
|
|
|
|
2021-09-14 14:01:33 +02:00
|
|
|
await execCommand2(`docker build -t "joplin/server:${imageVersion}" ${buildArgs} -f Dockerfile.server .`);
|
|
|
|
for (const tag of dockerTags) {
|
|
|
|
await execCommand2(`docker tag "joplin/server:${imageVersion}" "joplin/server:${tag}"`);
|
|
|
|
if (pushImages) await execCommand2(`docker push joplin/server:${tag}`);
|
2021-06-19 16:14:19 +02:00
|
|
|
}
|
2021-06-11 18:24:59 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 17:48:26 +02:00
|
|
|
if (require.main === module) {
|
|
|
|
main().catch((error) => {
|
|
|
|
console.error('Fatal error');
|
|
|
|
console.error(error);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
|
|
|
}
|