-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.ts
81 lines (62 loc) · 2.99 KB
/
gulpfile.ts
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
import * as fs from "fs";
import * as gulp from "gulp";
import * as shell from "gulp-shell";
const contents = fs.readFileSync("./package.json").toString();
const npmPackage = JSON.parse(contents);
const version = npmPackage.version;
const [versionMajor, versionMajMin] = versionMajorMinor(version);
const repo = npmPackage.dockerRepository;
const imageName = npmPackage.dockerImageName || npmPackage.name;
const dockerRepoImage = `${repo}/${imageName}`;
///
// The objective here is to build and tag the actual version, mark it as latest, and also tag it with just the major
// version and major.minor as the "latest" within those scopes. Iterations of deploy-services should generally use
// major.minor in the Compose file rather that just latest. This facilitates side-by-side deployments of current and
// next version systems where pulling "latest" doesn't affect the older system on subsequent up commands.
///
const imageWithVersion = `${dockerRepoImage}:${version}`;
const imageWithVersionMajor = versionMajor ? `${dockerRepoImage}:${versionMajor}` : null;
const imageWithVersionMajMin = versionMajMin ? `${dockerRepoImage}:${versionMajMin}` : null;
const imageAsLatest = `${dockerRepoImage}:latest`;
const buildCommand = `docker build --tag ${imageWithVersion} .`;
const tagMajorCommand = imageWithVersionMajor ? `docker tag ${imageWithVersion} ${imageWithVersionMajor}` : `echo "could not tag with major version"`;
const tagMajMinCommand = imageWithVersionMajMin ? `docker tag ${imageWithVersion} ${imageWithVersionMajMin}` : `echo "could not tag with major.minor version"`;
const tagLatestCommand = `docker tag ${imageWithVersion} ${imageAsLatest}`;
const pushCommand = `docker push ${imageWithVersion}`;
const pushMajorCommand = imageWithVersionMajor ? `docker push ${imageWithVersionMajor}` : `echo "could not push major version"`;
const pushMajMinCommand = imageWithVersionMajMin ? `docker push ${imageWithVersionMajMin}` : `echo "could not push major.minor version"`;
const pushLatestCommand = `docker push ${imageAsLatest}`;
const cleanCommand = `rm -rf dist`;
const compileTypescript = `tsc -p tsconfig.prod.json`;
const moveFiles = `cp ./{package.json,yarn.lock,.sequelizerc,LICENSE,docker-entry.sh,migrate.sh} dist`;
const moveMigrations = `cp -R sequelize-migrations dist/`;
gulp.task("default", ["docker-build"]);
gulp.task("release", ["docker-push"]);
gulp.task("build", shell.task([
cleanCommand,
compileTypescript,
moveFiles,
moveMigrations
])
);
gulp.task("docker-build",["build"], shell.task([
buildCommand,
tagMajorCommand,
tagMajMinCommand,
tagLatestCommand
])
);
gulp.task("docker-push", ["docker-build"], shell.task([
pushCommand,
pushMajorCommand,
pushMajMinCommand,
pushLatestCommand
])
);
function versionMajorMinor(version: string) {
const parts = version.split(".");
if (parts.length === 3) {
return [`${parts[0]}`, `${parts[0]}.${parts[1]}`];
}
return [null, null];
}