-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Kanika Pasrija <[email protected]>
- Loading branch information
1 parent
69077f2
commit 2954073
Showing
4 changed files
with
449 additions
and
412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,7 @@ jobs: | |
username: ${{ secrets.REGISTRY_USERNAME }} | ||
password: ${{ secrets.REGISTRY_PASSWORD }} | ||
- run: | | ||
docker build .t contoso.azurecr.io/nodejssampleapp:${{ github.sha }} | ||
docker build . -t contoso.azurecr.io/nodejssampleapp:${{ github.sha }} | ||
docker push contoso.azurecr.io/nodejssampleapp:${{ github.sha }} | ||
- name: 'Deploy to Azure Container Instances' | ||
|
@@ -134,6 +134,18 @@ jobs: | |
location: 'east us' | ||
``` | ||
# Local Development and Testing | ||
If you wish to develop and test changes against a local fork or development repo, you can do so by including the `node_modules` in tagged release branch. Note that the `aci-deploy` repository does not include these modules in the master branch, so you cannot point your action to `aci-deploy/master` to pick up recent commits. | ||
|
||
Testing can be performed against your local repo by performing the following: | ||
|
||
* Fork this repo. | ||
* Create a separate branch on your local copy. This will be used to execute the action from your workflow. | ||
* Perform an `npm install` and `npm run build` | ||
* Ensure that you check in the `node_modules` directory to your branch. | ||
* Update your workflow to refer to your tagged release from forked copy. | ||
|
||
# Contributing | ||
|
||
This project welcomes contributions and suggestions. Most contributions require you to agree to a | ||
|
@@ -146,4 +158,4 @@ provided by the bot. You will only need to do this once across all repos using o | |
|
||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). | ||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or | ||
contact [[email protected]](mailto:[email protected]) with any additional questions or comments. | ||
contact [[email protected]](mailto:[email protected]) with any additional questions or comments. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,123 +1,135 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const core = __importStar(require("@actions/core")); | ||
const crypto = __importStar(require("crypto")); | ||
const AuthorizerFactory_1 = require("azure-actions-webclient/AuthorizerFactory"); | ||
const arm_containerinstance_1 = require("@azure/arm-containerinstance"); | ||
const ms_rest_js_1 = require("@azure/ms-rest-js"); | ||
const taskparameters_1 = require("./taskparameters"); | ||
var prefix = !!process.env.AZURE_HTTP_USER_AGENT ? `${process.env.AZURE_HTTP_USER_AGENT}` : ""; | ||
function main() { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
// Set user agent variable | ||
let usrAgentRepo = crypto.createHash('sha256').update(`${process.env.GITHUB_REPOSITORY}`).digest('hex'); | ||
let actionName = 'DeployAzureContainerInstance'; | ||
let userAgentString = (!!prefix ? `${prefix}+` : '') + `GITHUBACTIONS_${actionName}_${usrAgentRepo}`; | ||
core.exportVariable('AZURE_HTTP_USER_AGENT', userAgentString); | ||
let endpoint = yield AuthorizerFactory_1.AuthorizerFactory.getAuthorizer(); | ||
var taskParams = taskparameters_1.TaskParameters.getTaskParams(endpoint); | ||
let bearerToken = yield endpoint.getToken(); | ||
let creds = new ms_rest_js_1.TokenCredentials(bearerToken); | ||
core.debug("Predeployment Steps Started"); | ||
const client = new arm_containerinstance_1.ContainerInstanceManagementClient(creds, taskParams.subscriptionId); | ||
core.debug("Deployment Step Started"); | ||
let containerGroupInstance = { | ||
"location": taskParams.location, | ||
"containers": [ | ||
{ | ||
"name": taskParams.containerName, | ||
"command": taskParams.commandLine, | ||
"environmentVariables": taskParams.environmentVariables, | ||
"image": taskParams.image, | ||
"ports": taskParams.ports, | ||
"resources": getResources(taskParams), | ||
"volumeMounts": taskParams.volumeMounts | ||
} | ||
], | ||
"imageRegistryCredentials": taskParams.registryUsername ? [{ "server": taskParams.registryLoginServer, "username": taskParams.registryUsername, "password": taskParams.registryPassword }] : [], | ||
"ipAddress": { | ||
"ports": getPorts(taskParams), | ||
"type": taskParams.ipAddress, | ||
"dnsNameLabel": taskParams.dnsNameLabel | ||
}, | ||
"diagnostics": taskParams.diagnostics, | ||
"volumes": taskParams.volumes, | ||
"osType": taskParams.osType, | ||
"restartPolicy": taskParams.restartPolicy, | ||
"type": "Microsoft.ContainerInstance/containerGroups", | ||
"name": taskParams.containerName | ||
}; | ||
let containerDeploymentResult = yield client.containerGroups.createOrUpdate(taskParams.resourceGroup, taskParams.containerName, containerGroupInstance); | ||
if (containerDeploymentResult.provisioningState == "Succeeded") { | ||
console.log("Deployment Succeeded."); | ||
let appUrlWithoutPort = (_a = containerDeploymentResult.ipAddress) === null || _a === void 0 ? void 0 : _a.fqdn; | ||
let port = taskParams.ports[0].port; | ||
let appUrl = "http://" + appUrlWithoutPort + ":" + port.toString() + "/"; | ||
core.setOutput("app-url", appUrl); | ||
console.log("Your App has been deployed at: " + appUrl); | ||
} | ||
else { | ||
core.debug("Deployment Result: " + containerDeploymentResult); | ||
throw Error("Container Deployment Failed" + containerDeploymentResult); | ||
} | ||
} | ||
catch (error) { | ||
core.debug("Deployment Failed with Error: " + error); | ||
core.setFailed(error); | ||
} | ||
finally { | ||
// Reset AZURE_HTTP_USER_AGENT | ||
core.exportVariable('AZURE_HTTP_USER_AGENT', prefix); | ||
} | ||
}); | ||
} | ||
function getResources(taskParams) { | ||
if (taskParams.gpuCount) { | ||
let resRequirements = { | ||
"requests": { | ||
"cpu": taskParams.cpu, | ||
"memoryInGB": taskParams.memory, | ||
"gpu": { | ||
"count": taskParams.gpuCount, | ||
"sku": taskParams.gpuSku | ||
} | ||
} | ||
}; | ||
return resRequirements; | ||
} | ||
else { | ||
let resRequirements = { | ||
"requests": { | ||
"cpu": taskParams.cpu, | ||
"memoryInGB": taskParams.memory | ||
} | ||
}; | ||
return resRequirements; | ||
} | ||
} | ||
function getPorts(taskParams) { | ||
let ports = taskParams.ports; | ||
ports.forEach((port) => { | ||
port.protocol = taskParams.protocol; | ||
}); | ||
return ports; | ||
} | ||
main(); | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const core = __importStar(require("@actions/core")); | ||
const crypto = __importStar(require("crypto")); | ||
const AuthorizerFactory_1 = require("azure-actions-webclient/AuthorizerFactory"); | ||
const arm_containerinstance_1 = require("@azure/arm-containerinstance"); | ||
const ms_rest_js_1 = require("@azure/ms-rest-js"); | ||
const taskparameters_1 = require("./taskparameters"); | ||
var prefix = !!process.env.AZURE_HTTP_USER_AGENT ? `${process.env.AZURE_HTTP_USER_AGENT}` : ""; | ||
function main() { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
// Set user agent variable | ||
let usrAgentRepo = crypto.createHash('sha256').update(`${process.env.GITHUB_REPOSITORY}`).digest('hex'); | ||
let actionName = 'DeployAzureContainerInstance'; | ||
let userAgentString = (!!prefix ? `${prefix}+` : '') + `GITHUBACTIONS_${actionName}_${usrAgentRepo}`; | ||
core.exportVariable('AZURE_HTTP_USER_AGENT', userAgentString); | ||
let endpoint = yield AuthorizerFactory_1.AuthorizerFactory.getAuthorizer(); | ||
var taskParams = taskparameters_1.TaskParameters.getTaskParams(endpoint); | ||
let bearerToken = yield endpoint.getToken(); | ||
let creds = new ms_rest_js_1.TokenCredentials(bearerToken); | ||
core.debug("Predeployment Steps Started"); | ||
const client = new arm_containerinstance_1.ContainerInstanceManagementClient(creds, taskParams.subscriptionId); | ||
core.debug("Deployment Step Started"); | ||
let containerGroupInstance = { | ||
"location": taskParams.location, | ||
"containers": [ | ||
{ | ||
"name": taskParams.containerName, | ||
"command": taskParams.commandLine, | ||
"environmentVariables": taskParams.environmentVariables, | ||
"image": taskParams.image, | ||
"ports": taskParams.ports, | ||
"resources": getResources(taskParams), | ||
"volumeMounts": taskParams.volumeMounts | ||
} | ||
], | ||
"imageRegistryCredentials": taskParams.registryUsername ? [{ "server": taskParams.registryLoginServer, "username": taskParams.registryUsername, "password": taskParams.registryPassword }] : [], | ||
"ipAddress": { | ||
"ports": getPorts(taskParams), | ||
"type": taskParams.ipAddress, | ||
"dnsNameLabel": taskParams.dnsNameLabel | ||
}, | ||
"diagnostics": taskParams.diagnostics, | ||
"volumes": taskParams.volumes, | ||
"osType": taskParams.osType, | ||
"restartPolicy": taskParams.restartPolicy, | ||
"type": "Microsoft.ContainerInstance/containerGroups", | ||
"name": taskParams.containerName | ||
}; | ||
let containerDeploymentResult = yield client.containerGroups.createOrUpdate(taskParams.resourceGroup, taskParams.containerName, containerGroupInstance); | ||
if (containerDeploymentResult.provisioningState == "Succeeded") { | ||
console.log("Deployment Succeeded."); | ||
let appUrlWithoutPort = (_a = containerDeploymentResult.ipAddress) === null || _a === void 0 ? void 0 : _a.fqdn; | ||
let port = taskParams.ports[0].port; | ||
let appUrl = "http://" + appUrlWithoutPort + ":" + port.toString() + "/"; | ||
core.setOutput("app-url", appUrl); | ||
console.log("Your App has been deployed at: " + appUrl); | ||
} | ||
else { | ||
core.debug("Deployment Result: " + containerDeploymentResult); | ||
throw Error("Container Deployment Failed" + containerDeploymentResult); | ||
} | ||
} | ||
catch (error) { | ||
core.debug("Deployment Failed with Error: " + error); | ||
core.setFailed(error); | ||
} | ||
finally { | ||
// Reset AZURE_HTTP_USER_AGENT | ||
core.exportVariable('AZURE_HTTP_USER_AGENT', prefix); | ||
} | ||
}); | ||
} | ||
function getResources(taskParams) { | ||
if (taskParams.gpuCount) { | ||
let resRequirements = { | ||
"requests": { | ||
"cpu": taskParams.cpu, | ||
"memoryInGB": taskParams.memory, | ||
"gpu": { | ||
"count": taskParams.gpuCount, | ||
"sku": taskParams.gpuSku | ||
} | ||
} | ||
}; | ||
return resRequirements; | ||
} | ||
else { | ||
let resRequirements = { | ||
"requests": { | ||
"cpu": taskParams.cpu, | ||
"memoryInGB": taskParams.memory | ||
} | ||
}; | ||
return resRequirements; | ||
} | ||
} | ||
function getPorts(taskParams) { | ||
let ports = taskParams.ports; | ||
ports.forEach((port) => { | ||
port.protocol = taskParams.protocol; | ||
}); | ||
return ports; | ||
} | ||
main(); |
Oops, something went wrong.