Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c6e1ed5
Merge pull request #1 from dynamicaction/ICL-20845_flok_upgrade_mongo…
Sep 5, 2018
63b18ba
ICL-22960 - Adding Jenkinsfile
Oct 11, 2019
e05c50f
ICL-22960 - Fixing lint errors
Oct 11, 2019
460dfa7
Merge pull request #2 from dynamicaction/ICL-22960_adding_Jenkinsfile
Oct 11, 2019
6eb780e
ICL-22853_upgrade_node12
Oct 22, 2019
ec75523
node_12_upgrade - Fixing tests
Nov 11, 2019
e21d3c2
Merge pull request #3 from dynamicaction/node_12_upgrade
Nov 13, 2019
ff09883
node14 - Bump packages and add support for node14
Nov 23, 2020
193cf99
Merge pull request #5 from dynamicaction/node14
Dec 2, 2020
74c9a16
ICL-23917 - Adding before
Jan 7, 2021
cc05548
Merge pull request #6 from dynamicaction/ICL-23917_flok_add_before
Jan 11, 2021
e1c9f3e
master - Fixing jshint error
Jan 11, 2021
20a0743
fix false jenkins claim that regex env param is supported
seangarner Feb 16, 2022
c793050
Upgrade mongodb lib to support node 18
tmwoodruff Dec 6, 2023
b4852cc
Merge pull request #7 from dynamicaction/mongodb_upgrade
tmwoodruff Dec 6, 2023
b8a675e
3.0.3
tmwoodruff Dec 6, 2023
70dfbaf
ICL-26062-bump to node 18 for build server
georgistanevod Dec 12, 2023
c3b8c5a
[skip ci] bump to version 4.0.0 for release
georgistanevod Jan 3, 2024
b989a0f
node_22_upgrade - Upgrade nodejs version
svedbg Aug 26, 2025
218c3a5
Remove Require nodejs for dsm package
DilaraOflaz Sep 19, 2025
2c91de0
Merge pull request #10 from dynamicaction/PFM_2529_Remove_require_nodejs
seangarner Sep 24, 2025
65a9573
temporarily allow builds on master jenkins node
seangarner Sep 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ nohup.out
test/down/flokStatus/f2ccf261-e498-4b21-b49b-805610d5ca94.json
test/down/flok.lock
test/show/flok.lock
package-lock.json
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# flok changelog

## 3.0.2 (2020/11/23)

- adding support for nodejs 14

## 3.0.1 (2019/10/11)

- adding support for Jenkins pipeline

## 3.0.0 (2018/08/23)

- [major] upgrade bundled mongo driver to `^3.1.3` which contains breaking changes from `^2.2.0`
Expand Down
254 changes: 254 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
def version() {
def isStg = (BRANCH_NAME =~ /^(heads\/)?\d{1,4}\.\d{1,4}\.\d{1,5}(\+hotfix\.\d{1,3})?/)
def env = (BUILD_ENV == 'ci1') ? 'ci' : 'dev'
isStg ? BRANCH_NAME : env
}

pipeline {
agent { label 'master' }
tools {
nodejs 'nodejs22'
maven 'maven221'
}
parameters {
string(
defaultValue: "ci1",
description: 'Environment to build and deploy to.',
name: 'BUILD_ENV'
)
}
environment {
BUILD_ENV = "${params.BUILD_ENV}"
BUILD_INSTANCE = "${env.BUILD_ENV == 'dev1' ? 'dapi1' : 'webapi1'}"
BUILD_NUMBER = "${currentBuild.startTimeInMillis}~${currentBuild.number}"
BUILD_DATE = sh(
script: 'echo $(date -R)',
returnStdout: true
).trim()
GIT_OWNER = "dynamicaction"
GIT_REPO = "flok"
GIT_SOURCE = "https://github.com/${GIT_OWNER}/${GIT_REPO}"
GIT_COMMIT = sh(
script: 'git describe --always',
returnStdout: true
).trim()
GIT_BRANCH = sh(
script: 'git rev-parse --abbrev-ref HEAD',
returnStdout: true
).trim()
}

stages {

stage("parameterizing") {
when {
expression {
def v = version();
return v == 'ci' || v == 'dev'
}
}
steps {
script {
echo "deploying on " + BUILD_ENV + " branch: " + GIT_BRANCH
if (BUILD_ENV == "ci1" && GIT_BRANCH != "master") {
currentBuild.result = 'ABORTED'
error('DRY RUN COMPLETED. JOB PARAMETERIZED.')
}
}
}
}

stage('Prepare') {
steps {
sh 'make dev'
}
}

stage('Build') {
parallel {
stage('test') {
steps {
sh 'make test'
}
}
stage('lint') {
steps {
sh 'make lint'
}
}
}
}

stage('Package') {
steps {
sh 'npm prune --production'
sh """
mvn clean package rpm:rpm \
-Drpmversion=${version()} \
-Drpmrelease=${BUILD_NUMBER} \
-Dgit_commit=${GIT_COMMIT} \
-Dgit_source=${GIT_SOURCE}
"""
}
}

stage('DeployDev') {
when {
expression {
def v = version();
return v == 'ci' || v == 'dev'
}
}
steps {
sshPublisher alwaysPublishFromMaster: true, continueOnError: true, publishers: [
sshPublisherDesc(
configName: 'shared_repo',
sshLabel: [label: "$BUILD_ENV"],
transfers: [
sshTransfer(
cleanRemote: false,
excludes: '',
execCommand: "createrepo_c --update /srv/yum/shared/x86_64",
execTimeout: 300000,
flatten: false,
makeEmptyDirs: false,
noDefaultExcludes: false,
patternSeparator: '[, ]+',
remoteDirectory: "x86_64",
remoteDirectorySDF: false,
removePrefix: 'target/rpm/flok/RPMS/x86_64/',
sourceFiles: 'target/rpm/flok/RPMS/x86_64/*.rpm'
)
],
usePromotionTimestamp: false,
useWorkspaceInPromotion: false,
verbose: true
),
sshPublisherDesc(
configName: "${BUILD_INSTANCE}.${BUILD_ENV}",
sshLabel: [label: BUILD_ENV],
sshRetry: [
retries: 2,
retryDelay: 10000
],
transfers: [
sshTransfer(
cleanRemote: false,
excludes: '',
execCommand: '''
sudo yum clean all
E=$?;
if [[ $E -ne 0 ]]
then
echo "Cleaning up yum cache error!"
exit $E
fi
sudo puppet agent -ot --color=false --no-noop;
E=$?;
if [[ $E -eq 1 ]]
then
echo "Run of Puppet configuration client already in progress; sleeping 90 sec"
sleep 90
sudo puppet agent -ot --color=false --no-noop;
E=$?;
fi

if [[ $E -eq 2 ]]
then
echo "All changes were deployed"
exit 0
fi
if [[ $E -eq 0 ]]
then
echo "There were no changes for deployment"
exit 0
fi
echo "There were failures during the transaction"
exit $E
''',
execTimeout: 120000,
flatten: true,
makeEmptyDirs: false,
noDefaultExcludes: false,
patternSeparator: '[, ]+',
remoteDirectory: '',
remoteDirectorySDF: false,
removePrefix: '',
sourceFiles: '',
usePty: true
)
],
usePromotionTimestamp: false,
useWorkspaceInPromotion: false,
verbose: false
),
]
script {
def description = "Deploying ${GIT_BRANCH} to ${BUILD_ENV}"
def deployURL = "https://api.github.com/repos/${GIT_OWNER}/${GIT_REPO}/deployments"
def deployBody = '{"ref": "' + GIT_COMMIT +'","environment": "' + BUILD_ENV +'","description": "' + description + '","auto_merge":false,"required_contexts":[]}'

// Create new Deployment using the GitHub Deployment API
def response = httpRequest authentication: 'github-deployment-token', httpMode: 'POST', requestBody: deployBody, responseHandle: 'STRING', url: deployURL

if(response.status != 201) {
error("Deployment API Create Failed: " + response.status)
}

// Get the ID of the GitHub Deployment just created
def responseJson = readJSON text: response.content
def id = responseJson.id

if(id == "") {
error("Could not extract id from Deployment response")
}

// At this point we need to get the status of sshPublisher
//def result = (deployStatus) ? 'failure' : 'success'
def deployStatusBody = '{"state": "' + "success" + '","target_url": "https://' + BUILD_ENV + '.dynamicaction.com"}'
def deployStatusURL = "https://api.github.com/repos/${GIT_OWNER}/${GIT_REPO}/deployments/${id}/statuses"
def deployStatusResponse = httpRequest authentication: 'github-deployment-token', httpMode: 'POST', requestBody: deployStatusBody , responseHandle: 'STRING', url: deployStatusURL

if(deployStatusResponse.status != 201) {
error("Deployment Status API Update Failed: " + deployStatusResponse.status)
}
}
}
}

stage('DeployStg') {
when {
expression {
def v = version();
return v != 'ci' && v != 'dev'
}
}
steps {
sshPublisher alwaysPublishFromMaster: true, continueOnError: true, publishers: [
sshPublisherDesc(
configName: 'shared_repo',
sshLabel: [label: "$BUILD_ENV"],
transfers: [
sshTransfer(
cleanRemote: false,
excludes: '',
flatten: false,
makeEmptyDirs: false,
noDefaultExcludes: false,
patternSeparator: '[, ]+',
remoteDirectory: "pending/stg/x86_64",
remoteDirectorySDF: false,
removePrefix: 'target/rpm/flok/RPMS/x86_64/',
sourceFiles: 'target/rpm/flok/RPMS/x86_64/*.rpm'
)
],
usePromotionTimestamp: false,
useWorkspaceInPromotion: false,
verbose: true
)
]
}
}

}
}
19 changes: 15 additions & 4 deletions lib/flok.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ var compose = require('mout/function/compose');
var prop = require('mout/function/prop');
var properCase = require('mout/string/properCase');
var pluck = require('mout/array/pluck');
var startsWith = require('mout/string/startsWith');

var generator = require('./generator');
var Migration = require('./migration');
Expand Down Expand Up @@ -280,8 +279,20 @@ Flok.prototype.sortMigrationsUp = function sortMigrationsUp(callback) {
return a.time - b.time;
});

var sortedIds = [];
var i = 0;
const mBefore = filter(this.migrations, 'before');
for (let i = 0; i < mBefore.length; i++) {
//Find migration with id from before and add as deps
const beforId = mBefore[i].before;
const depM = this.migrations.find(({id}) => id === beforId);
if (depM.dependencies) {
depM.dependencies.push(mBefore[i].id);
} else {
depM.dependencies = [mBefore[i].id];
}
}

const sortedIds = [];
let i = 0;
while (sortedIds.length < this.migrations.length) {
var m = this.migrations[i];

Expand Down Expand Up @@ -596,7 +607,7 @@ Flok.prototype._saveMigrationStatus = function _saveMigrationStatus(err, migrati
this._run(this, this.saveMigrationStatus, [status, migration], function (e) {
if (e) {
//TODO: write test for saving migration status fallback
var f = path.join(os.tmpDir(), 'flok_status_dump_' + guid()) + '.json';
var f = path.join(os.tmpdir(), 'flok_status_dump_' + guid()) + '.json';
var c = JSON.stringify(status);
self.log.fatal(e,
'!!UNABLE TO SAVE RESULT OF MIGRATION!! (%s) status dumped to %s',
Expand Down
2 changes: 1 addition & 1 deletion lib/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Migration.prototype.skip = function skip() {
this.status.signature = this.signature;
this.status.runMethod = 'up';
this.status.error = null;
}
};

Migration.prototype.getStatus = function getStatus() {
return this.status;
Expand Down
Loading