/*
 * Licensed Materials - Property of IBM Corp.
 * IBM UrbanCode Deploy
 * (c) Copyright IBM Corporation 2016. All Rights Reserved.
 *
 * U.S. Government Users Restricted Rights - Use, duplication or disclosure restricted by
 * GSA ADP Schedule Contract with IBM Corp.
 */
import com.urbancode.air.AirPluginTool
import com.urbancode.air.ExitCodeException
import com.urbancode.air.plugin.cf.ic.helper.CFICHelper

AirPluginTool apTool = new AirPluginTool(args[0], args[1])
def props = apTool.getStepProperties()

final def workDir = new File('.').canonicalFile
def commandPath = props['commandPath']
def image = props['image']
def name = props['name']
def ports = props['ports']
def exposedPorts = props['exposedPorts'] ? Boolean.valueOf(props['exposedPorts']) : ""
def command = props['command'].trim()
def bindApp = props['bindApp'].trim()
def additionalArgs = props['additionalArgs']

CFICHelper icHelper = new CFICHelper(workDir, commandPath)

try {
    icHelper.runImage(image, name, ports, exposedPorts, command, bindApp, additionalArgs)
}
catch(ExitCodeException ex) {
    println("Could not successfully run image: ${image}")
    println(ex)
    System.exit(1)
}