Skip to content

Pipeline Functions

🛠️ Tools · ⬅ Home


Application Configuration

Usage

dotEnvConfigure [ where ] [ --help ]

Loads .env which is the current project configuration file Also loads .env.local if it exists Generally speaking - these are NAME=value files and should be parsable by bash and other languages. Requires the file .env to exist and is loaded via bash source and all variables are exported in the current shell context. If .env.local exists, it is also loaded in a similar manner. Use with caution on trusted content only.

Arguments

  • where - Directory. Optional. Where to load the .env files.
  • --help - Flag. Optional. Display this help.

Return codes

  • 1 - if .env does not exist; outputs an error
  • 0 - if files are loaded successfully

Build Utilities

buildFailed

Output debugging information when the build fails

Usage

buildFailed logFile [ message ]

Outputs debugging information after build fails: - last 50 lines in build log - Failed message - last 3 lines in build log

Arguments

  • logFile - File. Required. The most recent log from the current script.
  • message - String. Optional. Any additional message to output.

Examples

quietLog="$(buildQuietLog "$me")"
if ! ./bin/deploy.sh >>"$quietLog"; then
    decorate error "Deploy failed"
    buildFailed "$quietLog"
fi

Sample Output

stdout

Return codes

  • 1 - Always fails

Usage

versionSort [ -r | --reverse ] [ --help ]

Sorts semantic versions prefixed with a v character; intended to be used as a pipe. vXXX.XXX.XXX for sort - -k 1.c,1 - the c is the 1-based character index, so 2 means skip the 1st character Odd you can't globally flip sort order with -r - that only works with non-keyed entries I assume

Arguments

-r |- --reverse - Reverse the sort order (optional) - --help - Flag. Optional. Display this help.

Examples

git tag | grep -e '^v[0-9.]*$' | versionSort

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

Requires

throwArgument sort usageDocument decorate

Usage

ipLookup [ --help ]

Get the current IP address of a host

Arguments

  • --help - Flag. Optional. Display this help.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

Environment

  • IP_URL - URL. URL to look up IP my address remotely

  • IP_URL_FILTER - String. jq filter to parse IP_URL result (assuming JSON) if blank, no filter is used and raw result is returned

Usage

isUpToDate keyDate upToDateDays [ --name name ] [ --help ]

For security one should update keys every N days This value would be better encrypted and tied to the key itself so developers can not just update the value to avoid the security issue. This tool checks the value and checks if it is upToDateDays of today; if not this fails. It will also fail if: - upToDateDays is less than zero or greater than 366 - keyDate is empty or has an invalid value Otherwise, the tool may output a message to the console warning of pending days, and returns exit code 0 if the keyDate has not exceeded the number of days.

Arguments

  • keyDate - Date. Required. Formatted like YYYY-MM-DD. Truncated at 10 characters as well.
  • upToDateDays - Integer. Required. Days that key expires after keyDate.
  • --name name - String. Optional. Name of the expiring item for error messages.
  • --help - Flag. Optional. Display this help.

Examples

if !isUpToDate "$AWS_ACCESS_KEY_DATE" 90; then
  bigText Failed, update key and reset date
  exit 99
fi

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

Application Environment

Usage

environmentFileApplicationMake [ --help ] [ requiredVariable ... ] [ -- ] [ optionalVariable ... ]

Create environment file .env for build. Note that this does NOT change or modify the current environment.

Arguments

  • --help - Flag. Optional. Display this help.
  • requiredVariable ... - EnvironmentVariable. Optional. One or more environment variables which should be non-blank and included in the .env file.
  • -- - Divider. Optional. Divides the requiredEnvironment values from the optionalEnvironment. Should appear once and only once.
  • optionalVariable ... - EnvironmentVariable. Optional. One or more environment variables which are included if blank or not

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

Environment

  • APPLICATION_VERSION - String. This is the version number which can be displayed
  • reserved and set to hookRun version-current if not set already
  • APPLICATION_BUILD_DATE - Date. Time when a build was initiated, set upon first invocation if not already
  • reserved and set to current date; format like SQL.
  • APPLICATION_TAG - String. This is the full version number including debugging or release identifiers
  • reserved and set to hookRun application-id
  • APPLICATION_ID - String. This is the unique hash which represents the source code state (typically a git hash)
  • reserved and set to hookRun application-tag

environmentFileShow

Display and validate application variables.

Usage

environmentFileShow [ environmentName ] [ -- ] [ optionalEnvironmentName ]

Display and validate application variables.

Arguments

  • environmentName - EnvironmentVariable. Optional. A required environment variable name
  • -- - Separator. Optional. Separates requires from optional environment variables
  • optionalEnvironmentName - EnvironmentVariable. Optional. An optional environment variable name.

Return codes

  • 1 - If any required application variables are blank, the function fails with an environment error
  • 0 - All required application variables are non-blank

Usage

environmentApplicationLoad [ --help ]

Loads application environment variables, set them to their default values if needed, and outputs the list of variables and values.

Arguments

  • --help - Flag. Optional. Display this help.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

Environment

  • BUILD_TIMESTAMP - Integer. Time when a build was initiated, set upon first invocation if not already

  • APPLICATION_BUILD_DATE - Date. Time when a build was initiated, set upon first invocation if not already

  • APPLICATION_VERSION - String. This is the version number which can be displayed

  • APPLICATION_ID - String. This is the unique hash which represents the source code state (typically a git hash)

  • APPLICATION_TAG - String. This is the full version number including debugging or release identifiers

Deployment tools

Usage

deployApplication [ --help ] [ --first ] [ --revert ] --home deployHome --id applicationId --application applicationPath [ --target targetPackage ] [ --message message ]

This acts on the local file system only but used in tandem with deployment functions.

Arguments

  • --help - Flag. Optional. This help.
  • --first - Flag. Optional. The first deployment has no prior version and can not be reverted.
  • --revert - Flag. Optional. Means this is part of the undo process of a deployment.
  • --home deployHome - Directory. Required. Path where the deployments database is on system.
  • --id applicationId - String. Required. Should match APPLICATION_ID or APPLICATION_TAG in .env or .deploy/
  • --application applicationPath - FileDirectory. Required. Path on the system where the application is live
  • --target targetPackage - Filename. Optional. Package name, defaults to BUILD_TARGET
  • --message message - String. Optional. Message to display in the maintenance message on systems while upgrade is occurring.

Examples

deployApplication --home /var/www/DEPLOY --id 10c2fab1 --application /var/www/apps/cool-app

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

Environment

  • BUILD_TARGET - String. The file to generate when generating builds APPLICATION_ID - String. This is the unique hash which represents the source code state (typically a git hash) APPLICATION_TAG - String. This is the full version number including debugging or release identifiers

Usage

deployNextVersion deployHome versionName

Get the next version of the supplied version

Arguments

  • deployHome - Directory. Required. Deployment database home.
  • versionName - String. Required. Application ID to look for

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

Usage

deployPreviousVersion deployHome versionName

Get the previous version of the supplied version

Arguments

  • deployHome - Directory. Required. Deployment database home.
  • versionName - String. Required. Application ID to look for

Return codes

  • 1 - No version exists
  • 2 - Argument error

Usage

deployHasVersion deployHome versionName

Does a deploy version exist? versionName is the version identifier for deployments

Arguments

  • deployHome - Directory. Required. Deployment database home.
  • versionName - String. Required. Application ID to look for

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

Usage

deployApplicationVersion applicationHome

Extracts version from an application either from .deploy files or from the the .env if that does not exist. Checks APPLICATION_ID and APPLICATION_TAG and uses first non-blank value.

Arguments

  • applicationHome - Directory. Required. Application home to get the version from.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error