Skip to content

Commit

Permalink
Move deployer interface to deployer-lib (#140)
Browse files Browse the repository at this point in the history
* Use deployer-lib

* Update S3 upload output titles
  • Loading branch information
huntharo authored Nov 28, 2021
1 parent 90cada3 commit 5d7df1e
Show file tree
Hide file tree
Showing 17 changed files with 218 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"node": true
},
"root": true,
"plugins": ["@typescript-eslint", "prettier"],
"plugins": ["@typescript-eslint", "import", "prettier"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
Expand Down
34 changes: 34 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"workspaces": [
"./packages/microapps-datalib/",
"./packages/microapps-cdk/",
"./packages/microapps-deployer-lib/",
"./packages/microapps-deployer/",
"./packages/microapps-publish/",
"./packages/microapps-router/",
Expand Down
1 change: 1 addition & 0 deletions packages/microapps-deployer-lib/LICENSE
25 changes: 25 additions & 0 deletions packages/microapps-deployer-lib/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@pwrdrvr/microapps-deployer-lib",
"version": "0.0.0",
"private": true,
"description": "Deployer svc interface for the microapps framework",
"source": "src/index.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/pwrdrvr/microapps-core.git"
},
"author": "PwrDrvr LLC",
"license": "MIT",
"bugs": {
"url": "https://github.com/pwrdrvr/microapps-core/issues"
},
"homepage": "https://github.com/pwrdrvr/microapps-core#readme",
"devDependencies": {
"@types/node": "^14.17.34"
}
}
37 changes: 37 additions & 0 deletions packages/microapps-deployer-lib/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export interface IRequestBase {
type: 'createApp' | 'deployVersion' | 'deployVersionPreflight';
}

export interface ICreateApplicationRequest extends IRequestBase {
type: 'createApp';
appName: string;
displayName: string;
}

export interface IDeployVersionRequestBase extends IRequestBase {
appName: string;
semVer: string;
}

export interface IDeployVersionPreflightRequest extends IDeployVersionRequestBase {
type: 'deployVersionPreflight';
}

export interface IDeployVersionRequest extends IDeployVersionRequestBase {
type: 'deployVersion';
lambdaARN: string;
defaultFile: string;
}

export interface IDeployerResponse {
statusCode: number;
}

export interface IDeployVersionPreflightResponse extends IDeployerResponse {
s3UploadUrl?: string;
awsCredentials?: {
accessKeyId: string;
secretAccessKey: string;
sessionToken: string;
};
}
14 changes: 14 additions & 0 deletions packages/microapps-deployer-lib/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "../../tsconfig.packages.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"resolveJsonModule": true
},
"references": [
{
"path": "../microapps-datalib/"
}
],
"exclude": ["**/*.spec.ts", "dist"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import 'jest-dynalite/withDb';
import { DBManager, Application } from '@pwrdrvr/microapps-datalib';
import type * as lambda from 'aws-lambda';
import * as dynamodb from '@aws-sdk/client-dynamodb';
import { handler, ICreateApplicationRequest, overrideDBManager } from '../index';
import { ICreateApplicationRequest } from '@pwrdrvr/microapps-deployer-lib';
import { handler, overrideDBManager } from '../index';

let dynamoClient: dynamodb.DynamoDBClient;
let dbManager: DBManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Application, DBManager } from '@pwrdrvr/microapps-datalib';
import { ICreateApplicationRequest, IDeployerResponse } from '../index';
import { ICreateApplicationRequest, IDeployerResponse } from '@pwrdrvr/microapps-deployer-lib';

export default class AppController {
public static async CreateApp(opts: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ import * as lambda from '@aws-sdk/client-lambda';
import * as s3 from '@aws-sdk/client-s3';
import * as sts from '@aws-sdk/client-sts';

import {
IDeployVersionPreflightRequest,
ICreateApplicationRequest,
IDeployVersionRequest,
} from '@pwrdrvr/microapps-deployer-lib';
import { DBManager, Version } from '@pwrdrvr/microapps-datalib';
import type * as lambdaTypes from 'aws-lambda';
import { mockClient, AwsClientStub } from 'aws-sdk-client-mock';
import sinon from 'sinon';
import { Config } from '../config/Config';
import {
handler,
IDeployVersionPreflightRequest,
ICreateApplicationRequest,
IDeployVersionRequest,
overrideDBManager,
} from '../index';
import { handler, overrideDBManager } from '../index';

let s3Client: AwsClientStub<s3.S3Client>;
let stsClient: AwsClientStub<sts.STSClient>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
IDeployerResponse,
IDeployVersionPreflightResponse,
IDeployVersionRequestBase,
} from '../index';
} from '@pwrdrvr/microapps-deployer-lib';
import GatewayInfo from '../lib/GatewayInfo';
import Log from '../lib/Log';

Expand Down
45 changes: 7 additions & 38 deletions packages/microapps-deployer/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import 'source-map-support/register';
// Used by ts-convict
import 'reflect-metadata';
import {
IRequestBase,
IDeployVersionPreflightRequest,
ICreateApplicationRequest,
IDeployerResponse,
IDeployVersionRequest,
} from '@pwrdrvr/microapps-deployer-lib';
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { DBManager } from '@pwrdrvr/microapps-datalib';
import type * as lambda from 'aws-lambda';
Expand Down Expand Up @@ -28,44 +35,6 @@ dbManager = new DBManager({ dynamoClient, tableName: Config.instance.db.tableNam

const config = Config.instance;

interface IRequestBase {
type: 'createApp' | 'deployVersion' | 'deployVersionPreflight';
}

export interface ICreateApplicationRequest extends IRequestBase {
type: 'createApp';
appName: string;
displayName: string;
}

export interface IDeployVersionRequestBase extends IRequestBase {
appName: string;
semVer: string;
}

export interface IDeployVersionPreflightRequest extends IDeployVersionRequestBase {
type: 'deployVersionPreflight';
}

export interface IDeployVersionRequest extends IDeployVersionRequestBase {
type: 'deployVersion';
lambdaARN: string;
defaultFile: string;
}

export interface IDeployerResponse {
statusCode: number;
}

export interface IDeployVersionPreflightResponse extends IDeployerResponse {
s3UploadUrl?: string;
awsCredentials?: {
accessKeyId: string;
secretAccessKey: string;
sessionToken: string;
};
}

export async function handler(
event: IRequestBase,
context: lambda.Context,
Expand Down
18 changes: 12 additions & 6 deletions packages/microapps-publish/src/DeployClient.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import * as lambda from '@aws-sdk/client-lambda';

import { TaskWrapper } from 'listr2/dist/lib/task-wrapper';
import { DefaultRenderer } from 'listr2/dist/renderer/default.renderer';
import {
IDeployVersionPreflightRequest,
IDeployVersionPreflightResponse,
ICreateApplicationRequest,
IDeployerResponse,
IDeployVersionRequest,
} from '@pwrdrvr/microapps-deployer';
} from '@pwrdrvr/microapps-deployer-lib';
import { IConfig } from './config/Config';
import { IContext } from './index';

export interface IDeployVersionPreflightResult {
exists: boolean;
Expand Down Expand Up @@ -47,6 +49,7 @@ export default class DeployClient {

public static async DeployVersionPreflight(
config: IConfig,
task: TaskWrapper<IContext, typeof DefaultRenderer>,
): Promise<IDeployVersionPreflightResult> {
const request = {
type: 'deployVersionPreflight',
Expand All @@ -65,7 +68,7 @@ export default class DeployClient {
Buffer.from(response.Payload).toString('utf-8'),
) as IDeployVersionPreflightResponse;
if (dResponse.statusCode === 404) {
console.log(`App/Version do not exist: ${config.app.name}/${config.app.semVer}`);
task.output = `App/Version do not exist: ${config.app.name}/${config.app.semVer}`;
return { exists: false, response: dResponse };
} else {
return { exists: true, response: dResponse };
Expand All @@ -75,7 +78,10 @@ export default class DeployClient {
}
}

public static async DeployVersion(config: IConfig): Promise<void> {
public static async DeployVersion(
config: IConfig,
task: TaskWrapper<IContext, typeof DefaultRenderer>,
): Promise<void> {
const request = {
type: 'deployVersion',
appName: config.app.name,
Expand All @@ -95,9 +101,9 @@ export default class DeployClient {
Buffer.from(response.Payload).toString('utf-8'),
) as IDeployerResponse;
if (dResponse.statusCode === 201) {
console.log(`Deploy succeeded: ${config.app.name}/${config.app.semVer}`);
task.output = `Deploy succeeded: ${config.app.name}/${config.app.semVer}`;
} else {
console.log(`Deploy failed with: ${dResponse.statusCode}`);
task.output = `Deploy failed with: ${dResponse.statusCode}`;
}
} else {
throw new Error(`Lambda call to DeployVersion failed: ${JSON.stringify(response)}`);
Expand Down
10 changes: 9 additions & 1 deletion packages/microapps-publish/src/S3TransferUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@ import { promises as fs, createReadStream } from 'fs';
import * as path from 'path';
import * as s3 from '@aws-sdk/client-s3';
import { Upload } from '@aws-sdk/lib-storage';
import { IDeployVersionPreflightResponse } from '@pwrdrvr/microapps-deployer';
import { IDeployVersionPreflightResponse } from '@pwrdrvr/microapps-deployer-lib';
import { contentType } from 'mime-types';
import pMap from 'p-map';

export default class S3TransferUtility {
/**
* @deprecated 2021-11-27
*
* @param s3Path
* @param destPrefixPath
* @param bucketName
* @param preflightResponse
*/
public static async UploadDir(
s3Path: string,
destPrefixPath: string,
Expand Down
3 changes: 2 additions & 1 deletion packages/microapps-publish/src/S3Uploader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import { IDeployVersionPreflightResponse } from '@pwrdrvr/microapps-deployer';
import { IDeployVersionPreflightResponse } from '@pwrdrvr/microapps-deployer-lib';
import fs from 'fs-extra';
import { IConfig } from './config/Config';
import S3TransferUtility from './S3TransferUtility';
Expand Down Expand Up @@ -38,6 +38,7 @@ export default class S3Uploader {

/**
* Upload files to S3
* @deprecated 2021-11-27
* @param config
* @param s3UploadPath
* @param preflightResponse
Expand Down
Loading

0 comments on commit 5d7df1e

Please sign in to comment.