diff --git a/.releaserc.json b/.releaserc.json index 3e0dc3fd..a7213846 100644 --- a/.releaserc.json +++ b/.releaserc.json @@ -1,7 +1,8 @@ { "release": { "branches": [ - "master" + "master", + "develop" ] }, "plugins": [ diff --git a/Jenkinsfile b/Jenkinsfile index 7dcbd5db..a129b4fd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -52,6 +52,32 @@ pipeline { sh 'npx semantic-release' } } + + stage("Deploy production") { + // deploy from master only + when { + branch 'master' + } + environment { + GH_TOKEN = credentials('e2d21e2c-c919-4137-9355-21e4602a862e') + } + steps { + script { + remote = [:] + remote.name = env.ENTERPRISE_HOSTNAME + remote.host = env.ENTERPRISE_SERVER + remote.allowAnyHosts = true + + withCredentials([usernamePassword(credentialsId: '966e5fa4-833f-4477-a3b4-26327116d3f5', passwordVariable: 'ssh_pw', usernameVariable: 'ssh_user')]) { + remote.user = ssh_user + remote.password = ssh_pw + } + } + // execute a remote script which does all the necessary deploy steps + // TODO: put the script in git + sshCommand remote: remote, command: './update-enterprise.sh' + } + } } tools { nodejs 'node' diff --git a/package-lock.json b/package-lock.json index 91e5c256..f051ab7e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3793,6 +3793,23 @@ "integrity": "sha512-W+bw9ds02rAQaMvaLYxAbJ6cvguW/iJXNT6lTssS1ps6QdrMKttqEAMEG/b5CR8TZl3/L7/lH0ZV5nNR1LXikA==", "dev": true }, + "@types/tar-fs": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@types/tar-fs/-/tar-fs-2.0.0.tgz", + "integrity": "sha512-3H2HmxuT1OCZYXi1KG5xIjbpv97JjdLSRByH13YhHK8lr+GaJndJ91IuQfHxn23BQRaWHf2LTnlHPQcQDzt8vw==", + "requires": { + "@types/node": "*", + "@types/tar-stream": "*" + } + }, + "@types/tar-stream": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@types/tar-stream/-/tar-stream-2.1.0.tgz", + "integrity": "sha512-s1UQxQUVMHbSkCC0X4qdoiWgHF8DoyY1JjQouFsnk/8ysoTdBaiCHud/exoAZzKDbzAXVc+ah6sczxGVMAohFw==", + "requires": { + "@types/node": "*" + } + }, "@types/tough-cookie": { "version": "2.3.5", "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-2.3.5.tgz", @@ -6690,6 +6707,42 @@ "file-uri-to-path": "1.0.0" } }, + "bl": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/bl/-/bl-4.0.3.tgz", + "integrity": "sha512-fs4G6/Hu4/EE+F75J8DuN/0IpQqNjAdC7aEQv7Qt8MHGUH7Ckv2MwTEEeN9QehD0pfIDkMI1bkHYkKy7xHyKIg==", + "requires": { + "buffer": "^5.5.0", + "inherits": "^2.0.4", + "readable-stream": "^3.4.0" + }, + "dependencies": { + "buffer": { + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.6.0.tgz", + "integrity": "sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw==", + "requires": { + "base64-js": "^1.0.2", + "ieee754": "^1.1.4" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } + } + }, "bluebird": { "version": "3.5.5", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.5.tgz", @@ -7410,8 +7463,7 @@ "chownr": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz", - "integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==", - "dev": true + "integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==" }, "chrome-trace-event": { "version": "1.0.2", @@ -9532,7 +9584,6 @@ "version": "1.4.4", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", - "dev": true, "requires": { "once": "^1.4.0" } @@ -11371,6 +11422,11 @@ "readable-stream": "^2.0.0" } }, + "fs-constants": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", + "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==" + }, "fs-extra": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", @@ -12943,8 +12999,7 @@ "ieee754": { "version": "1.1.13", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz", - "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==", - "dev": true + "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==" }, "iferr": { "version": "0.1.5", @@ -14859,6 +14914,11 @@ "minimist": "^1.2.5" } }, + "mkdirp-classic": { + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz", + "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==" + }, "mocha": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/mocha/-/mocha-7.2.0.tgz", @@ -19302,7 +19362,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, "requires": { "wrappy": "1" } @@ -20740,7 +20799,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", - "dev": true, "requires": { "end-of-stream": "^1.1.0", "once": "^1.3.1" @@ -23078,6 +23136,41 @@ "integrity": "sha512-4WK/bYZmj8xLr+HUCODHGF1ZFzsYffasLUgEiMBY4fgtltdO6B4WJtlSbPaDTLpYTcGVwM2qLnFTICEcNxs3kA==", "dev": true }, + "tar-fs": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.0.tgz", + "integrity": "sha512-9uW5iDvrIMCVpvasdFHW0wJPez0K4JnMZtsuIeDI7HyMGJNxmDZDOCQROr7lXyS+iL/QMpj07qcjGYTSdRFXUg==", + "requires": { + "chownr": "^1.1.1", + "mkdirp-classic": "^0.5.2", + "pump": "^3.0.0", + "tar-stream": "^2.0.0" + } + }, + "tar-stream": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.1.4.tgz", + "integrity": "sha512-o3pS2zlG4gxr67GmFYBLlq+dM8gyRGUOvsrHclSkvtVtQbjV0s/+ZE8OpICbaj8clrX3tjeHngYGP7rweaBnuw==", + "requires": { + "bl": "^4.0.3", + "end-of-stream": "^1.4.1", + "fs-constants": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^3.1.1" + }, + "dependencies": { + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } + } + }, "tarn": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/tarn/-/tarn-2.0.0.tgz", @@ -24949,8 +25042,7 @@ "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "write": { "version": "1.0.3", diff --git a/package.json b/package.json index c5147b61..b135cf3d 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "@fortawesome/fontawesome-svg-core": "^1.2.32", "@fortawesome/free-solid-svg-icons": "^5.15.1", "@rmp135/sql-ts": "^1.5.2", + "@types/tar-fs": "^2.0.0", "bcrypt-nodejs": "0.0.3", "bcryptjs": "^2.4.3", "bootstrap": "^4.5.2", @@ -60,6 +61,7 @@ "read-last-lines": "^1.7.2", "request-promise-native": "^1.0.9", "stringify-stream": "^1.0.5", + "tar-fs": "^2.1.0", "throttle-exec": "^3.1.0", "throttle-function": "^0.1.0", "tough-cookie": "^4.0.0", diff --git a/src/server/bin/update.js b/src/server/bin/update.js new file mode 100644 index 00000000..c0fc8d1d --- /dev/null +++ b/src/server/bin/update.js @@ -0,0 +1,96 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +const fs = require("fs"); +const requestPromise = require("request-promise-native"); +const request = require("request"); +const tar = require("tar-fs"); +const path = require("path"); + +/** + * @returns {Promise} the version string + */ +module.exports.readLocalVersion = async function readLocalVersion() { + const packageJsonPath = path.join(process.cwd(), "package.json"); + const packageJsonString = await fs.promises.readFile(packageJsonPath, "utf8"); + const packageJson = JSON.parse(packageJsonString); + return packageJson.version +} + +module.exports.readRemoteVersion = async function readRemoteVersion() { + const response = await requestPromise.get( + "https://api.github.com/repos/mytlogos/enterprise-lister/releases/latest", + { + headers: { + "User-Agent": "bot", + "Accept": "application/vnd.github.v3+json" + } + } + ); + + const latestRelease = JSON.parse(response); + return latestRelease.tag_name; +} + +module.exports.downloadLatest = async function downloadLatest() { + console.log("Checking for latest Release..."); + const response = await requestPromise.get( + "https://api.github.com/repos/mytlogos/enterprise-lister/releases/latest", + { + headers: { + "User-Agent": "bot", + "Accept": "application/vnd.github.v3+json" + } + } + ); + + const latestRelease = JSON.parse(response); + console.log(`Latest Release is ${latestRelease.tag_name}.`); + + let distAsset; + for (const asset of latestRelease.assets) { + if (asset.name === "dist.tar") { + distAsset = asset; + break; + } + } + if (distAsset) { + const distDir = path.join(process.cwd(), "dist"); + console.log("Dist Asset available, wiping previous dist directory..."); + // wipe dist directory clean + await fs.promises.rmdir(distDir, { recursive: true }); + + console.log(`Finished wiping '${distDir}'. Downloading and extracting new Dist Directory...`); + + // download latest dist.tar and extract it directly into the dist directory + await new Promise((resolve, reject) => { + let finished = false; + request(distAsset.browser_download_url) + .pipe(tar.extract(process.cwd())) + .on("entry", (header) => console.log(`Extracting ${header.name}...`)) + .on("error", () => { + if (!finished) { + finished = true; + reject(); + } + }) + .on("finish", () => { + if (!finished) { + finished = true; + resolve(); + } + }); + }); + console.log("Finished downloading and extracting dist."); + } else { + console.log("No Dist Asset available."); + } +} + +// run this if this file was called directly via node +if (require.main === module) { + module.exports.downloadLatest() + .then(() => process.exit(0)) + .catch(error => { + console.error(error.body); + process.exit(1); + }); +} \ No newline at end of file diff --git a/src/server/tsconfig.json b/src/server/tsconfig.json index 8fab5deb..5d07086c 100644 --- a/src/server/tsconfig.json +++ b/src/server/tsconfig.json @@ -24,7 +24,8 @@ "include": [ "bin/**/*.ts", "bin/**/*.tsx", - "bin/**/*.vue" + "bin/**/*.vue", + "bin/**/*.js" // "tests/**/*.ts", // "tests/**/*.tsx" ]