Skip to content

Commit

Permalink
Fix errors, working build
Browse files Browse the repository at this point in the history
  • Loading branch information
Benni-Math committed May 2, 2024
1 parent 1b86a72 commit 394b759
Show file tree
Hide file tree
Showing 40 changed files with 5,848 additions and 1,612 deletions.
3,055 changes: 1,586 additions & 1,469 deletions dist/cdk.js

Large diffs are not rendered by default.

3,984 changes: 3,984 additions & 0 deletions dist/cli.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/index.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

export { }
1 change: 1 addition & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'use strict';
Empty file added dist/index.mjs
Empty file.
2 changes: 1 addition & 1 deletion src/aws/helpers/createEcrArn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import EcrImage from '../../shared/types/EcrImage';
* @param {EcrImage} ecrImage
* @returns {string} an ECR image ARN
*/
const createEcrArn = (ecrImage: EcrImage): string => {
const createEcrArn = (ecrImage: Omit<EcrImage, 'service'>): string => {
return [
'arn:aws:ecr',
ecrImage.region,
Expand Down
5 changes: 4 additions & 1 deletion src/aws/helpers/ecrArnToImageId.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Import helpers
import parseEcrArn from './parseEcrArn';

/**
* Transforms an ECR ARN value into it's URI form
* for example, this:
Expand All @@ -9,7 +12,7 @@
* @returns {string} and ECR image URI
*/
const ecrArnToImageId = (arn: string): string => {
const parsedArn = aws.parseEcrArn(arn);
const parsedArn = parseEcrArn(arn);
const host = [
parsedArn.account,
'dkr.ecr',
Expand Down
1 change: 1 addition & 0 deletions src/aws/helpers/execTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import AWS from 'aws-sdk';
// Import helpers
import getService from './getService';

// Types
export type EnvVariable = {
name: string;
value: string;
Expand Down
12 changes: 5 additions & 7 deletions src/aws/helpers/getCfnStackExports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ import { camelCase } from 'camel-case';
// Import shared errors
import CfnStackNotFound from '../../shared/errors/CfnStackNotFound';

// Import

type Output = CloudFormation.Output;

/**
* Returns an array of objects representing a Cloudformation stack's exports
* @param {string} stackName
* @returns {object[]}
* @returns {Record<string, string>}
*/
const getCfnStackExports = async (stackName: string) => {
const getCfnStackExports = async (
stackName: string,
): Promise<Record<string, string>> => {
const cnf = new AWS.CloudFormation();
// TODO: better typing
let exports: Record<string, string> = {};
Expand All @@ -34,7 +32,7 @@ const getCfnStackExports = async (stackName: string) => {
throw new CfnStackNotFound(`Unable to find stack ${stackName}`);
}
exports = resp.Stacks[0].Outputs.reduce(
(obj: Record<string, string>, output: Output) => {
(obj: Record<string, string>, output: CloudFormation.Output) => {
if (!output.ExportName || !output.OutputValue) {
return { ...obj };
}
Expand Down
9 changes: 7 additions & 2 deletions src/aws/helpers/getCurrentRegion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ import AWS from 'aws-sdk';
* @author Jay Luker
* @returns {string}
*/
const getCurrentRegion = () => {
return AWS.config.region;
const getCurrentRegion = (): string => {
const { region } = AWS.config;
if (!region) {
// TODO: better error type
throw new Error('Could not get current AWS region.');
}
return region;
};

export default getCurrentRegion;
7 changes: 2 additions & 5 deletions src/aws/helpers/getRepoImageList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import looksLikeSemver from '../../shared/helpers/looksLikeSemver';
// Import classes
import AssumedRole from '../classes/AssumedRole';

// Import helpers

/**
* @author Jay Luker
* @param {string} repo - ECR repository name, e.g. 'hdce/fooapp'
Expand All @@ -18,10 +16,9 @@ import AssumedRole from '../classes/AssumedRole';
* @returns {object[]}
*/
const getRepoImageList = async (
repo: string,
// TODO: make `all` optional
all: boolean,
assumedRole: AssumedRole,
repo: string,
all?: boolean,
) => {
const ecr = await assumedRole.getAssumedRoleClient(AWS.ECR);
const images = await getPaginatedResponse(
Expand Down
2 changes: 0 additions & 2 deletions src/aws/helpers/getRepoList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import AWS from 'aws-sdk';
import getPaginatedResponse from './getPaginatedResponse';
import AssumedRole from '../classes/AssumedRole';

// Import helpers

/**
* @author Jay Luker
* @returns {string[]} - array of ECR repository names
Expand Down
1 change: 1 addition & 0 deletions src/aws/helpers/getSsmParametersByPrefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import getPaginatedResponse from './getPaginatedResponse';
/**
* Fetch a set of parameter store entries based on a name prefix,
* e.g. `/caccl-deploy/foo-app`
* @author Jay Luker
* @param {string} prefix
* @returns {object[]}
*/
Expand Down
1 change: 1 addition & 0 deletions src/aws/helpers/getTaskDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import AWS, { ECS } from 'aws-sdk';

/**
* Fetches the data for an ECS task definition
* @author Jay Luker
* @param {string} taskDefName
* @returns {string}
*/
Expand Down
13 changes: 10 additions & 3 deletions src/aws/helpers/imageTagExists.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
// Import helpers
import getRepoImageList from './getRepoImageList';

// Import classes
import AssumedRole from '../classes/AssumedRole';

/**
* Confirms that a repo/tag combo exists
* @author Jay Luker
* @param {string} repoName - ECR repository name
* @param {string} tag - ECR image tag
* @returns {boolean}
*/
const imageTagExists = async (repoName: string, tag: string) => {
// FIXME: need assumed role (only used for ECR functions?)
const imageList = await getRepoImageList(repoName, true);
const imageTagExists = async (
assumedRole: AssumedRole,
repoName: string,
tag: string,
) => {
const imageList = await getRepoImageList(assumedRole, repoName, true);
return imageList.some((i) => {
if (!i.imageTags) return false;
return i.imageTags.includes(tag);
Expand Down
2 changes: 1 addition & 1 deletion src/aws/helpers/initProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import AWS from 'aws-sdk';
import { iniLoader as SharedIniFile } from 'aws-sdk/lib/shared-ini';

// Import errrors
// Import errors
import AwsProfileNotFound from '../../shared/errors/AwsProfileNotFound';

/**
Expand Down
13 changes: 10 additions & 3 deletions src/aws/helpers/isLatestTag.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
// Import helpers
import getRepoImageList from './getRepoImageList';

// Import classes
import AssumedRole from '../classes/AssumedRole';

/**
* Confirms that a tag is the latest for a repo
* @author Jay Luker
* @param {string} repoName
* @param {string} tag
* @returns {boolean}
*/
const isLatestTag = async (repoName: string, tag: string): Promise<boolean> => {
// FIXME: change getRepoImageList arguments
const imageList = await getRepoImageList(repoName);
const isLatestTag = async (
assumedRole: AssumedRole,
repoName: string,
tag: string,
): Promise<boolean> => {
const imageList = await getRepoImageList(assumedRole, repoName);
return (
!!imageList.length &&
!!imageList[0].imageTags &&
Expand Down
2 changes: 2 additions & 0 deletions src/aws/helpers/putSsmParameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import AWS, { SSM } from 'aws-sdk';
import AwsTag from '../../shared/types/AwsTag';

/**
* Add parameters to SSM
* @author Jay Luker
* @param {SSM.PutParameterRequest} opts - the parameter details, name, value, etc
* @param {object[]} tags - aws resource tags
* @returns {object}
Expand Down
1 change: 1 addition & 0 deletions src/aws/helpers/restartEcsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type RestartOpts = {

/**
* Restart an app's ECS service
* @author Jay Luker
* @param {string} cluster
* @param {string} service
* @param {boolean} wait
Expand Down
1 change: 1 addition & 0 deletions src/aws/helpers/secretExists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import AWS from 'aws-sdk';

/**
* Confirm that a secretsmanager entry exists
* @author Jay Luker
* @param {string} secretName
* @returns {boolean}
*/
Expand Down
11 changes: 10 additions & 1 deletion src/aws/helpers/sendSSHPublicKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@ import AWS from 'aws-sdk';
// Import shared helpers
import readFile from '../../shared/helpers/readFile';

// Import constants
import EC2_INSTANCE_CONNECT_USER from '../constants/EC2_INSTANCE_CONNECT_USER';

export type SendSSHPublicKeyOpts = {
instanceAz?: string;
instanceId: string;
sshKeyPath: string;
};

/**
* Send SSH public key to a remote server.
* @author Jay Luker
* @param opts
* @returns
*/
const sendSSHPublicKey = async (opts: SendSSHPublicKeyOpts) => {
// Destructure opts
const { instanceAz, instanceId, sshKeyPath } = opts;
Expand All @@ -19,7 +28,7 @@ const sendSSHPublicKey = async (opts: SendSSHPublicKeyOpts) => {
.sendSSHPublicKey({
AvailabilityZone: instanceAz,
InstanceId: instanceId,
InstanceOSUser: aws.EC2_INSTANCE_CONNECT_USER,
InstanceOSUser: EC2_INSTANCE_CONNECT_USER,
SSHPublicKey: readFile(sshKeyPath),
})
.promise();
Expand Down
1 change: 1 addition & 0 deletions src/aws/helpers/updateTaskDefAppImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import getTaskDefinition from './getTaskDefinition';
/**
* Updates a Fargate task definition, replacing the app container's
* ECR image URI value
* @author Jay Luker
* @param {string} taskDefName
* @param {string} imageArn
* @returns {string} - the full ARN (incl family:revision) of the newly
Expand Down
9 changes: 5 additions & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ import addShowCommand from './commands/addShowCommand';
import addStackCommand from './commands/addStackCommand';
import addUpdateCommand from './commands/addUpdateCommand';

// Import constants
// Import classes
import CacclDeployCommander from './commands/classes/CacclDeployCommander';

// Import constants
import CACCL_DEPLOY_NON_INTERACTIVE from './commands/constants/CACCL_DEPLOY_NON_INTERACTIVE';
import CACCL_DEPLOY_VERSION from './commands/constants/CACCL_DEPLOY_VERSION';

// Import helpers
import byeWithCredentialsError from './commands/helpers/byeWithCredentialsError';
Expand All @@ -40,7 +43,6 @@ import { conf, configDefaults, setConfigDefaults } from './conf';

// Import prompts
import { confirm } from './configPrompts';
import generateVersion from './shared/helpers/generateVersion';
import packageJson from '../package.json';

/**
Expand All @@ -53,7 +55,6 @@ const main = async () => {
byeWithCredentialsError();
}

const cacclDeployVersion = generateVersion();
const { description: packageDescription } = packageJson;

/*
Expand Down Expand Up @@ -83,7 +84,7 @@ const main = async () => {
}

const cli = new CacclDeployCommander()
.version(cacclDeployVersion)
.version(CACCL_DEPLOY_VERSION)
.description([packageDescription, `config: ${conf.path}`].join('\n'));

addAppsCommand(cli);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/addScheduleCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const addScheduleCommand = (
.option('-l, --list', 'list the existing scheduled tasks')
.option(
'-t, --task-id <string>',
'give the taska a string id; by default one will be generated',
'give the task a string id; by default one will be generated',
)
.option(
'-d, --task-description <string>',
Expand Down
23 changes: 19 additions & 4 deletions src/commands/classes/CacclDeployCommander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import yn from 'yn';
import { DeployConfigData } from '../../../types';

// Import aws
import { getCfnStackExports } from '../../aws';
import { AssumedRole, getCfnStackExports } from '../../aws';

// Import conf
import { conf } from '../../conf';
Expand All @@ -30,6 +30,7 @@ import warnAboutVersionDiff from '../../shared/helpers/warnAboutVersionDiff';

// Import constants
import CACCL_DEPLOY_NON_INTERACTIVE from '../constants/CACCL_DEPLOY_NON_INTERACTIVE';
import CACCL_DEPLOY_VERSION from '../constants/CACCL_DEPLOY_VERSION';

// Import helpers
import exitWithError from '../helpers/exitWithError';
Expand All @@ -41,6 +42,10 @@ import initAwsProfile from '../helpers/initAwsProfile';
* @extends Command
*/
class CacclDeployCommander extends Command {
private assumedRole?: AssumedRole;

public ecrAccessRoleArn?: string;

/**
* custom command creator
* @param {string} name
Expand Down Expand Up @@ -99,7 +104,10 @@ class CacclDeployCommander extends Command {
* that reference secretsmanager entries, preserve the secretsmanager ARN
* value rather than dereferencing
*/
async getDeployConfig(keepSecretArns?: boolean): Promise<DeployConfigData> {
async getDeployConfig(
assumedRole: AssumedRole,
keepSecretArns?: boolean,
): Promise<DeployConfigData> {
const appPrefix = this.getAppPrefix();
try {
const deployConfig = await DeployConfig.fromSsmParams(
Expand All @@ -113,7 +121,7 @@ class CacclDeployCommander extends Command {
exitWithError(`${this.app} app configuration not found!`);
}
}
return DeployConfig.generate();
return DeployConfig.generate(assumedRole);
}

/**
Expand All @@ -127,7 +135,7 @@ class CacclDeployCommander extends Command {
const cfnStackName = this.getCfnStackName();
const cfnExports = await getCfnStackExports(cfnStackName);
const stackVersion = cfnExports.cacclDeployVersion;
const cliVersion = cacclDeployVersion;
const cliVersion = CACCL_DEPLOY_VERSION;
if (
cliVersion === stackVersion ||
!warnAboutVersionDiff(stackVersion, cliVersion)
Expand Down Expand Up @@ -190,6 +198,13 @@ class CacclDeployCommander extends Command {
'name of the app to work with',
);
}

public getAssumedRole(): AssumedRole {
if (!this.assumedRole) {
this.assumedRole = new AssumedRole();
}
return this.assumedRole;
}
}

export default CacclDeployCommander;
9 changes: 9 additions & 0 deletions src/commands/constants/CACCL_DEPLOY_VERSION.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import generateVersion from '../../shared/helpers/generateVersion';

/**
* caccl-deploy version, pulled from package.json
* @author Benedikt Arnarsson
*/
const CACCL_DEPLOY_VERSION = generateVersion();

export default CACCL_DEPLOY_VERSION;
5 changes: 5 additions & 0 deletions src/commands/helpers/isProdAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { getAccountId } from '../../../lib/aws';
// Import config
import { conf } from '../../conf';

/**
* Check whether the current AWS account is a production account.
* @author Jay Luker
* @returns boolean indicating whether it is a prod account.
*/
const isProdAccount = async () => {
const prodAccounts = conf.get('productionAccounts');
const accountId = await getAccountId();
Expand Down
Loading

0 comments on commit 394b759

Please sign in to comment.