Skip to content

Commit

Permalink
Merge pull request #31 from mytlogos/develop
Browse files Browse the repository at this point in the history
Automatic Deploy with Jenkins
  • Loading branch information
mytlogos authored Oct 19, 2020
2 parents 82d1114 + 2e39022 commit 39b3b90
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .releaserc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"release": {
"branches": [
"master"
"master",
"develop"
]
},
"plugins": [
Expand Down
26 changes: 26 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
110 changes: 101 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
96 changes: 96 additions & 0 deletions src/server/bin/update.js
Original file line number Diff line number Diff line change
@@ -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<string>} 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);
});
}
3 changes: 2 additions & 1 deletion src/server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"include": [
"bin/**/*.ts",
"bin/**/*.tsx",
"bin/**/*.vue"
"bin/**/*.vue",
"bin/**/*.js"
// "tests/**/*.ts",
// "tests/**/*.tsx"
]
Expand Down

0 comments on commit 39b3b90

Please sign in to comment.