Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let loginResult: CommandResult;
if (!dockerPasswordStdin) {
loginResult = await runCLICommand(
"docker", ["login", "-u", username, "-p", password, registryName]);
} else {
loginResult = await runCLICommand(
"docker", ["login", "-u", username, "--password-stdin", registryName], false, password);
}
if (loginResult.code) {
throw new RunError(`Failed to login to Docker registry ${registryName}`);
}
// Tag and push the image to the remote repository.
if (!repositoryUrl) {
throw new RunError("Expected repository URL to be defined during push");
}
const tagResult = await runCLICommand("docker", ["tag", imageName, repositoryUrl]);
if (tagResult.code) {
throw new RunError(`Failed to tag Docker image with remote registry URL ${repositoryUrl}`);
}
const pushResult = await runCLICommand("docker", ["push", repositoryUrl]);
if (pushResult.code) {
throw new RunError(`Docker push of image '${imageName}' failed with exit code: ${pushResult.code}`);
}
}
constructor(name: string, container: cloud.Container, opts?: pulumi.ResourceOptions) {
super("cloud:task:Task", name, { }, opts);
if (container.ports && container.ports.length > 0) {
throw new RunError("Tasks should not be given any [ports] in their Container definition.");
}
const { imageOptions, registry } = computeImageOptionsAndRegistry(this, container);
const globalResourceGroupName = shared.globalResourceGroupName;
const memory = pulumi.output(container.memoryReservation);
// Require the client credentials at deployment time so we can fail up-front if they are not
// provided.
const config = new pulumi.Config("cloud-azure");
const subscriptionId = config.require("subscriptionId");
const clientId = config.require("clientId");
const clientSecret = config.require("clientSecret");
const tenantId = config.require("tenantId");
this.run = async (options) => {
export function createNameWithStackInfo(requiredInfo: string) {
const maxLength = 24;
if (requiredInfo.length > maxLength) {
throw new RunError(`'${requiredInfo}' cannot be longer then ${maxLength} characters.`);
}
// No required portion. Just return the stack name.
if (requiredInfo.length === 0) {
return nameWithStackInfo.substr(0, maxLength);
}
// Only enough room for required portion, don't add the stack.
// Also don't add the stack if there wouldn't be room to add it and a dash.
if (requiredInfo.length >= maxLength - "-".length) {
return requiredInfo;
}
// Attempt to keep some portion of the stack, then - then the required part.
const suffix = "-" + requiredInfo;
const result = nameWithStackInfo.substr(0, maxLength - suffix.length) + suffix;
// See what kind of load balancer to create (application L7 for HTTP(S) traffic, or network L4 otherwise).
// Also ensure that we have an SSL certificate for termination at the LB, if that was requested.
let protocol: string;
let targetProtocol: string;
let useAppLoadBalancer: boolean;
let useCertificateARN: string | undefined;
switch (portMappingProtocol) {
case "https":
protocol = "HTTPS";
// Set the target protocol to HTTP, so that the ELB terminates the SSL traffic.
// IDEA: eventually we should let users choose where the SSL termination occurs.
targetProtocol = "HTTP";
useAppLoadBalancer = true;
useCertificateARN = config.acmCertificateARN;
if (!useCertificateARN) {
throw new RunError("Cannot create Service for HTTPS trafic. No ACM certificate ARN configured.");
}
break;
case "http":
protocol = "HTTP";
targetProtocol = "HTTP";
useAppLoadBalancer = true;
break;
case "udp":
throw new RunError("UDP protocol unsupported for Services");
case "tcp":
protocol = "TCP";
targetProtocol = "TCP";
useAppLoadBalancer = false;
break;
default:
throw new RunError(`Unrecognized Service protocol: ${portMapping.protocol}`);
export let externalPublicSubnets: string[] | undefined = undefined;
if (externalPublicSubnetsString) {
externalPublicSubnets = externalPublicSubnetsString.split(",");
}
const externalSecurityGroupsString = config.get("externalSecurityGroups");
/**
* Provide securityGroup ids for the VPC as a comma-seperated string. Required if using an existing VPC.
*/
export let externalSecurityGroups: string[] | undefined = undefined;
if (externalSecurityGroupsString) {
externalSecurityGroups = externalSecurityGroupsString.split(",");
}
if (externalVpcId && (!externalSubnets || !externalSecurityGroups)) {
throw new RunError(
"Must configure 'cloud-aws:externalSubnets' and 'cloud-aws:externalSecurityGroups' " +
"when setting 'cloud-asws:externalVpcId'",
);
}
/**
* Optionally use Fargate-based container compute. All tasks must be Fargate-compatible.
*/
export let useFargate = config.getBoolean("useFargate") || false;
/**
* Optionally auto-provision an ECS Cluster. If set to true, parameters for the cluster can be provided via
* the other "ecsAutoCluster*" configuration variables.
*/
export let ecsAutoCluster = config.getBoolean("ecsAutoCluster") || false;
/**
}
firstPort = false;
const fullHost = hostname.apply(h => `${hostproto}://${h}:${hostport}`);
preEnv[`${serviceEnv}_PORT`] = fullHost;
preEnv[`${serviceEnv}_PORT_${port}_TCP`] = fullHost;
preEnv[`${serviceEnv}_PORT_${port}_TCP_PROTO`]= hostproto;
preEnv[`${serviceEnv}_PORT_${port}_TCP_PORT`] = hostport;
preEnv[`${serviceEnv}_PORT_${port}_TCP_ADDR`] = hostname;
}
}
}
if (container.build) {
if (!repository) {
throw new RunError("Expected a container repository for build image");
}
return computeImageFromBuild(preEnv, container.build, imageName, repository);
}
else if (container.image) {
return computeImageFromImage(preEnv, imageName);
}
else if (container.function) {
return computeImageFromFunction(container.function, preEnv, imageName);
}
else {
throw new RunError("Invalid container definition: `image`, `build`, or `function` must be provided");
}
}
function getEndpointHelper(
endpoints: Endpoints, containerName: string | undefined, containerPort: number | undefined): Endpoint {
containerName = containerName || Object.keys(endpoints)[0];
if (!containerName) {
throw new RunError(`No containers available in this service`);
}
const containerPorts = endpoints[containerName] || {};
containerPort = containerPort || +Object.keys(containerPorts)[0];
if (!containerPort) {
throw new RunError(`No ports available in service container ${containerName}`);
}
const endpoint = containerPorts[containerPort];
if (!endpoint) {
throw new RunError(`No exposed port for ${containerName} port ${containerPort}`);
}
return endpoint;
}
export function hourly(name: string,
scheduleOrHandler: timer.HourlySchedule | timer.Action,
handlerOrOptions?: timer.Action | pulumi.ResourceOptions,
opts?: pulumi.ResourceOptions): void {
let minute: number;
let handler: timer.Action;
if (typeof scheduleOrHandler === "function") {
minute = 0;
handler = scheduleOrHandler as timer.Action;
opts = handlerOrOptions as pulumi.ResourceOptions | undefined;
}
else if (!scheduleOrHandler) {
throw new RunError("Missing required timer handler function");
}
else {
minute = scheduleOrHandler.minuteUTC || 0;
handler = handlerOrOptions as timer.Action;
}
cron(name, `${minute} * * * ? *`, handler, opts);
}
export function daily(name: string,
scheduleOrHandler: timer.DailySchedule | timer.Action,
handlerOrOptions?: timer.Action | pulumi.ResourceOptions,
opts?: pulumi.ResourceOptions): void {
let hour: number;
let minute: number;
let handler: timer.Action;
if (typeof scheduleOrHandler === "function") {
hour = 0;
minute = 0;
handler = scheduleOrHandler as timer.Action;
opts = handlerOrOptions as pulumi.ResourceOptions | undefined;
}
else if (!scheduleOrHandler) {
throw new RunError("Missing required timer handler function");
}
else {
hour = scheduleOrHandler.hourUTC || 0;
minute = scheduleOrHandler.minuteUTC || 0;
handler = handlerOrOptions as timer.Action;
}
cron(name, `${minute} ${hour} * * ? *`, handler, opts);
}