From e8b58e2267469b9bc733bef9ad1b74dc4da12995 Mon Sep 17 00:00:00 2001 From: Nikita Evdokimov <9944368+evdokimovn@users.noreply.github.com> Date: Fri, 13 Aug 2021 15:25:15 +0200 Subject: [PATCH] Add release action --- .github/workflows/release.yaml | 41 +++++++++++++++++++ source/constructs/lib/constructs-stack.ts | 10 ++++- .../lib/serverless-image-handler.ts | 11 ++--- source/constructs/test/constructs.test.ts | 6 +-- .../test/serverless-image-handler-test.json | 9 +++- 5 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 000000000..d6f883c92 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,41 @@ +name: Create release +on: + push: + tags: + - '*' + +jobs: + build: + runs-on: ubuntu-latest + env: + DIST_OUTPUT_BUCKET: fishbrain-lambda-deploy + REGION: eu-west-1 + SOLUTION_NAME: serverless-image-handler + VERSION: v5.2.1-meta + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Install cdk + run: npm install -g aws-cdk + - name: Build + run: | + cd deployment + chmod +x ./build-s3-dist.sh + ./build-s3-dist.sh ${{ env.DIST_OUTPUT_BUCKET }} ${{ env.SOLUTION_NAME }} ${{ env.VERSION }} + - name: Archive global assets + uses: papeloto/action-zip@v1 + with: + files: deployment/global-s3-assets + dest: global-s3-assets.zip + - name: Archive regional assets + uses: papeloto/action-zip@v1 + with: + files: deployment/regional-s3-assets + dest: regional-s3-assets.zip + - name: Release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: | + regional-s3-assets.zip + global-s3-assets.zip \ No newline at end of file diff --git a/source/constructs/lib/constructs-stack.ts b/source/constructs/lib/constructs-stack.ts index f313b9e8a..76035b624 100644 --- a/source/constructs/lib/constructs-stack.ts +++ b/source/constructs/lib/constructs-stack.ts @@ -2,8 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 import * as cdk from '@aws-cdk/core'; -import { ServerlessImageHandler, ServerlessImageHandlerProps } from './serverless-image-handler'; -import { CfnParameter } from '@aws-cdk/core'; +import {CfnParameter} from '@aws-cdk/core'; +import {ServerlessImageHandler, ServerlessImageHandlerProps} from './serverless-image-handler'; const { VERSION } = process.env; @@ -12,8 +12,10 @@ const { VERSION } = process.env; */ export class ConstructsStack extends cdk.Stack { constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) { + console.log('HELLO') super(scope, id, props); + console.log('HELLO') // CFN parameters const corsEnabledParameter = new CfnParameter(this, 'CorsEnabled', { type: 'String', @@ -180,5 +182,9 @@ export class ConstructsStack extends cdk.Stack { value: cdk.Fn.ref('LogRetentionPeriod'), description: 'Number of days for event logs from Lambda to be retained in CloudWatch.' }).overrideLogicalId('LogRetentionPeriod'); + new cdk.CfnOutput(this, 'ImageHandlerApiOutput', { + value: cdk.Fn.ref('ImageHandlerApi'), + description: 'API Gateway Origin' + }).overrideLogicalId('ImageHandlerApi'); } } diff --git a/source/constructs/lib/serverless-image-handler.ts b/source/constructs/lib/serverless-image-handler.ts index da60248fa..00aaa5ec6 100644 --- a/source/constructs/lib/serverless-image-handler.ts +++ b/source/constructs/lib/serverless-image-handler.ts @@ -1,16 +1,16 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { Construct, CfnParameter } from "@aws-cdk/core"; +import * as cdk from "@aws-cdk/core"; +import {CfnParameter, Construct} from "@aws-cdk/core"; import * as cdkLambda from '@aws-cdk/aws-lambda'; import * as cdkS3 from '@aws-cdk/aws-s3'; import * as cdkIam from '@aws-cdk/aws-iam'; -import * as cdk from '@aws-cdk/core'; import * as cdkCloudFront from '@aws-cdk/aws-cloudfront'; import * as cdkApiGateway from '@aws-cdk/aws-apigateway'; import * as cdkLogs from '@aws-cdk/aws-logs'; -import { CloudFrontToApiGatewayToLambda } from '@aws-solutions-constructs/aws-cloudfront-apigateway-lambda'; -import { CloudFrontToS3 } from '@aws-solutions-constructs/aws-cloudfront-s3'; +import {CloudFrontToApiGatewayToLambda} from '@aws-solutions-constructs/aws-cloudfront-apigateway-lambda'; +import {CloudFrontToS3} from '@aws-solutions-constructs/aws-cloudfront-s3'; import apiBody from './api.json'; const { BUCKET_NAME, SOLUTION_NAME, VERSION } = process.env; @@ -138,7 +138,8 @@ export class ServerlessImageHandler extends Construct { new cdkIam.PolicyStatement({ actions: [ 'rekognition:DetectFaces', - 'rekognition:DetectModerationLabels' + 'rekognition:DetectModerationLabels', + 'rekognition:DetectLabels' ], resources: [ '*' diff --git a/source/constructs/test/constructs.test.ts b/source/constructs/test/constructs.test.ts index c40e53c6f..5bf04301a 100644 --- a/source/constructs/test/constructs.test.ts +++ b/source/constructs/test/constructs.test.ts @@ -1,15 +1,15 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { expect as expectCDK, matchTemplate, MatchStyle } from '@aws-cdk/assert'; +import {expect as expectCDK, MatchStyle, matchTemplate} from '@aws-cdk/assert'; import * as cdk from '@aws-cdk/core'; -import * as Constructs from '../lib/constructs-stack'; +import {ConstructsStack} from '../lib/constructs-stack'; import TestTemplate from './serverless-image-handler-test.json'; test('Serverless Image Handler Stack', () => { const app = new cdk.App(); // WHEN - const stack = new Constructs.ConstructsStack(app, 'MyTestStack'); + const stack = new ConstructsStack(app, 'MyTestStack'); // THEN expectCDK(stack).to(matchTemplate(TestTemplate, MatchStyle.EXACT)); }); diff --git a/source/constructs/test/serverless-image-handler-test.json b/source/constructs/test/serverless-image-handler-test.json index 50497f483..14a55be15 100644 --- a/source/constructs/test/serverless-image-handler-test.json +++ b/source/constructs/test/serverless-image-handler-test.json @@ -353,7 +353,8 @@ { "Action": [ "rekognition:DetectFaces", - "rekognition:DetectModerationLabels" + "rekognition:DetectModerationLabels", + "rekognition:DetectLabels" ], "Effect": "Allow", "Resource": "*" @@ -1755,6 +1756,12 @@ "Value": { "Ref": "LogRetentionPeriod" } + }, + "ImageHandlerApi": { + "Description": "API Gateway Origin", + "Value": { + "Ref": "ImageHandlerApi" + } } } } \ No newline at end of file