Continuous Deploy with Commandbox II: Project Versioning with Gitlab

Read Part I here: https://impelos.com/continuous-deploy-with-commandbox/

Why Gitlab?

Gitlab allows us to host our own version control system without being subject to the whims of external parties. DigitalOcean does a wonderful job of serving it up for us.

Commandbox to Gitlab API

We’ll be using a CommandBox task runner to apply a version tag to the master branch.

First, we need an array of all of the repository project IDs associated with our project. You can find the project ID under the project’s name in “Project Details” view. We use a struct of arrays so they can be referenced by name later. It’s a constant, so we define it at the beginning of our gitlab task runner.

this.projList = { 'impelos' = [21, 202, 198, ... ] };
this.privateToken = 'privateTokenFromGitlab';

After validating the arguments, the function iterates through all of the projects in the array

  • Validate the project ID, and its master branch
  • Creates a new tag from the arguments
    Gitlab rather nicely checks for an existing tag and returns an appropriate status_code
  • Report back with any codes that might indicate a problem
  • Validates that the tag was created successfully

Here’s how I normally call this function:

box task run gitlab.cfc createTag impelos "1.2.6+4" "Some tale about this build"

You can see the component in its entirety in this gist.

Now that we’ve got the same version set across projects, we can run our continuousDeploy task runner for the first time. Coming soon…

Continuous Deploy with Commandbox

Preamble

As a matter of course, we at Impelos have built a significant set of modules that can plug in to various database systems and schemas to accomplish the needs of our clients.

In order to accomplish the varying client requirements we’ve needed to build a system that’s modular and flexible, while maintaining some consistency in our develop, test, and deploy processes.

Current count is 35 git repositories that need to be in sync before any updates can be rolled out.

What we’re about to show you is deploy only and doesn’t include automated pre-deploy testing. We wouldn’t want you believing this is all we do, now would we?

Our Environment

Currently, Repos are hosted on by our own Gitlab CE server, client servers are typically CentOS 7 virtual machines.

Why CommandBox?

CommandBox is a powerful and multi-talented command-line interface (CLI) for modern CFML. If you’re new to CommandBox, start here:https://www.ortussolutions.com/products/commandbox

Task Runners are automated jobs that can accomplish anything that can be done with CFML via command line rather than http request. For an introduction, start here: https://commandbox.ortusbooks.com/task-runners

First Step: Daemonization

We discovered that running a CommandBox task runner as a daemon on any OS is extremely lightweight, as opposed to starting CommandBox each time using a cron job.  In essence, we’re just going to throw the task into an infinite while loop like this:

component {

function run( string mode = 'once' ){

var interval = 20; // in minutes

while( true ){

// capture the loop's start time
var startStamp = now();

// do the automated processes

// capture the loop's end time
var stopStamp = now();

// calculate the remaining seconds before resuming the loop
var remainingSec = (interval * 60) - stopStamp.compare( startStamp, 's' );

var currSec = timeFormat( stopStamp, "ss" );

var sleepMS = ( (currSec >= startSec ? 60 : 0) + startSec - currSec ) * 1000 + ( remainingSec * 1000 );

if ( arguments.mode == 'once' ){
// break out of the loop as the default course of action
break;
}

sleep( sleepMS );

} // end while

} // end run function

} // end component

Next step:

In a Nutshell

Impelos specializes in making high-value improvements to back-office and production ecosystems for manufacturers of configurable products.

The Goal is Simplicity

For Make To Order manufacturers, Impelos offers à la carte software integrations that automate existing processes or add new functionality, reducing manual work to a minimum.

Solutions For Every Stage Of Your Business

  • Starting with consumer facing sales tools available to your dealer network
  • Dealer self-service portal showing purchase history, open order status, current factory inventory, getting quotes and placing orders, or anything else you can dream up
  • Rapid order entry processes for inside sales
  • Scheduling production for “shippability” and delivering achievable promise dates
  • Automated production release based on sales order scheduling
  • Absolutely Simple shop floor tracking of assembly and finishing processes, and component / subassembly manufacturing
  • Automated materials flush and sales order propagation that fits your back-office software
  • Piece pay reporting based on production activities
  • Automated VIN generation, rapid VIN document printing, and push to MSO at invoicing
  • Business Intelligence views designed to help you see what’s happening inside your business
  • Warranty management system styled after the “best of” software help desk solutions
  • Custom & proprietary software – you dream it, we’ll build it

Revenue Driven, Relationship Focused

We know that you don’t make money until your product is shipped, and you don’t continue to make money without a strong relationship with your dealer network and past consumers. That’s why processes are design to reduce on-hand finished inventory, and minimize administrative effort, so you can focus on building relationships.

Software + Process Optimization = Measurable Value

You need software to track your business activities, but software itself isn’t sufficient for growth: you need a solid platform of activity-based systems that are tuned to strengthen and build for the future. Your market strengths and business goals melded with our process improvement strengths become a powerful force to increase profitability.

Here to Stay

We’ve been in this industry for nearly two decades, and we’re here to grow with it into the future. Our products are designed and built to scale with you, and we’ll support that growth for years to come.

Functions for Holidays in MySQL/MariaDB

Here are a few handy calendar functions for US Holidays:

Create FUNCTION dateEasterSunday (p_year int)
RETURNS date DETERMINISTIC
BEGIN
declare p_day int DEFAULT 0;
declare p_month int DEFAULT 3;
declare p_g int DEFAULT 0;
declare p_c int DEFAULT 0;
declare p_h int DEFAULT 0;
declare p_i int DEFAULT 0;

SET p_g = p_year % 19;
SET p_c = p_year / 100;
SET p_h = (p_c - cast(p_c / 4 as int) - cast((8 * p_c + 13) / 25 as int) + 19 * p_g + 15) % 30;
SET p_i = p_h - cast(p_h / 28 as int) * (1 - cast(p_h / 28 as int) * cast(29 / (p_h + 1) as int) * cast((21 - p_g) / 11 as int));

SET p_day = p_i - ((p_year + cast(p_year / 4 as int) + p_i + 2 - p_c + cast(p_c / 4 as int)) % 7) + 28;

IF (p_day > 31) THEN
SET p_month = 4;
SET p_day = p_day - 31;
END IF;

RETURN str_to_date(concat(p_year, '-', p_month, '-', p_day), '%Y-%m-%d');
END;

drop function dateLaborDay;
Create FUNCTION dateLaborDay (p_year int)
RETURNS date DETERMINISTIC
BEGIN
declare v_days int default 0;

SET v_days = DAYOFWEEK(str_to_date(concat(p_year, ',09,01'), '%Y,%m,%d'));
/* 2 is Monday */
SET v_days = 2-v_days;

IF v_days < 0 THEN RETURN date_add(str_to_date(concat(p_year, ',09,01'), '%Y,%m,%d'), interval 7 + v_days day); ELSE RETURN date_add(str_to_date(concat(p_year, ',09,01'), '%Y,%m,%d'), interval v_days day); END IF; END; create FUNCTION dateMemorialDay (p_year int) RETURNS date deterministic BEGIN declare v_day int default 31; while DAYOFWEEK(str_to_date(concat(p_year, ',05,', v_day), '%Y,%m,%d')) <> 2 DO
SET v_day = v_day - 1;
end while;

RETURN str_to_date(concat(p_year, ',05,', v_day), '%Y,%m,%d');

END;

Create FUNCTION dateThanksgivingUSA (p_year int)
RETURNS date deterministic
BEGIN
declare v_day int default 1;

/* get first thursday */
while DAYOFWEEK(str_to_date(concat(p_year, ',11,', v_day), '%Y,%m,%d')) <> 5 DO
SET v_day = v_day + 1;
end while;

set v_day = v_day + 21;

RETURN str_to_date(concat(p_year, ',11,', v_day), '%Y,%m,%d');

END;

select dateLaborDay(year(now())), dateThanksgivingUSA(year(now())), dateMemorialDay(year(now())), dateEasterSunday(year(now()));

Record Productivity Award

The Human Resources department at Wally’s Widgets, Inc. recently awarded a record bonus for productivity to Leslie Jones for achieving a record 99.999% active time during business hours for a full quarter.

Leslie, a sales representative with the company, credited their operations manager who offered the suggestion of taking a taxi from their New York office to a sales call in Dallas, Texas, rather than flying, because the taxi would be in motion for duration of the journey. Traveling by air, Leslie said, would result in sitting and waiting for the aircraft to board, provide flight instructions to the passengers, and similar wait times.

Their IT staff also assisted by adding steps to their order entry systems to ensure the user was never idle, waiting on their server to process input. “At least 14 clicks to add a Johnson Bolt! And another 22 to remove it from the order!” exclaimed Leslie. They also put reports in places difficult to find or remember, making it a constant hunt to find production status or shipping information.

When asked about Leslie’s financial contribution to sales during that quarter, a co-worker simply shrugged. “I don’t understand it. How can someone so productive add so little value?”

What good is software without insight?

Sure, you have software that tells you how much money is in the bank, and how many finished products are in your possession.  But do you know who built them each step along the way or their warranty info or when a new order will start production and when a full load will leave the factory?

We enhance your existing financial systems with business management solutions designed to free you up to do what you do best—strengthen relationships and innovate.  We provide deep insight into your configuration, production flow, and inventory on hand— from start to finish—so that you and your dealers have access to the details you need—quickly and accurately.

Scheduler

Our “Sales to production to shipping” Order Scheduler allows you to schedule your orders, strengthen trust with your customers,  and simplify purchasing planning.

Configurator

Our Configurator guides buyers through the process of designing the trailer that they want based on templates and options you create, simplifying your sales process, and giving the buyer control over their order.

Dealer Portal

Our Dealer Portal empowers your dealers with information they need about their orders through tools and reports, freeing up both you and the dealer to spend your time doing what you do best—delighting your customers.

Intranet Portal

With VIN Management, Production Release, Configuration Management, and Dashboard Reporting you’re in control of your processes—able to communicate to your team in real time, with accurate, up to the minute information.

Production Tracking Kiosks

Our Tracking Kiosks provide end-to-end status of each unit on the shop floor, giving you new insights into your production process.