Skip to content

Commit c73b5ee

Browse files
committed
feat(sar): add support for publishing SAR via Github Actions
1 parent cfb5099 commit c73b5ee

File tree

3 files changed

+140
-0
lines changed

3 files changed

+140
-0
lines changed

.github/workflows/publish_v2_layer.yml

+26
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
defaults:
2424
run:
2525
working-directory: ./layer
26+
outputs:
27+
release-tag-version: ${{ steps.release-notes-tag.outputs.release-tag-version }}
2628
steps:
2729
- name: checkout
2830
uses: actions/checkout@v3
@@ -46,11 +48,13 @@ jobs:
4648
poetry export --format requirements.txt --output requirements.txt
4749
pip install -r requirements.txt
4850
- name: Set release notes tag
51+
id: release-notes-tag
4952
run: |
5053
RELEASE_INPUT=${{ inputs.latest_published_version }}
5154
LATEST_TAG=$(git describe --tag --abbrev=0)
5255
RELEASE_TAG_VERSION=${RELEASE_INPUT:-$LATEST_TAG}
5356
echo RELEASE_TAG_VERSION="${RELEASE_TAG_VERSION:1}" >> "$GITHUB_ENV"
57+
echo "::set-output name=release-tag-version::$RELEASE_TAG_VERSION"
5458
- name: Set up QEMU
5559
uses: docker/setup-qemu-action@8b122486cedac8393e77aa9734c3528886e4a1a8 # v2.0.0
5660
# NOTE: we need QEMU to build Layer against a different architecture (e.g., ARM)
@@ -81,6 +85,17 @@ jobs:
8185
artefact-name: "cdk-layer-artefact"
8286
environment: "layer-beta"
8387

88+
deploy-sar-beta:
89+
needs:
90+
- build-layer
91+
uses: ./.github/workflows/reusable_deploy_v2_sar.yml
92+
secrets: inherit
93+
with:
94+
stage: "BETA"
95+
artefact-name: "cdk-layer-artefact"
96+
environment: "layer-beta"
97+
package-version: ${{ needs.build-layer.outputs.release-tag-version }}
98+
8499
# deploy-prod:
85100
# needs:
86101
# - deploy-beta
@@ -90,3 +105,14 @@ jobs:
90105
# stage: "PROD"
91106
# artefact-name: "cdk-layer-artefact"
92107
# environment: "layer-prod"
108+
109+
# deploy-sar-prod:
110+
# needs:
111+
# - build-layer
112+
# uses: ./.github/workflows/reusable_deploy_v2_sar.yml
113+
# secrets: inherit
114+
# with:
115+
# stage: "PROD"
116+
# artefact-name: "cdk-layer-artefact"
117+
# environment: "layer-beta"
118+
# package-version: ${{ needs.build-layer.outputs.release-tag-version }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Deploy V2 SAR
2+
3+
permissions:
4+
id-token: write
5+
contents: read
6+
7+
env:
8+
SAM_VERSION: 2.44.0
9+
NODE_VERSION: 16.12
10+
AWS_REGION: eu-central-1
11+
12+
on:
13+
workflow_call:
14+
inputs:
15+
stage:
16+
description: "Deployment stage (BETA, PROD)"
17+
required: true
18+
type: string
19+
artefact-name:
20+
description: "CDK Layer Artefact name to download"
21+
required: true
22+
type: string
23+
package-version:
24+
description: "The version of the package to deploy"
25+
required: true
26+
type: string
27+
environment:
28+
description: "GitHub Environment to use for encrypted secrets"
29+
required: true
30+
type: string
31+
32+
jobs:
33+
deploy-cdk-stack:
34+
runs-on: ubuntu-latest
35+
environment: ${{ inputs.environment }}
36+
defaults:
37+
run:
38+
working-directory: ./layer
39+
steps:
40+
- name: checkout
41+
uses: actions/checkout@v3
42+
- name: aws credentials
43+
uses: aws-actions/configure-aws-credentials@v1
44+
with:
45+
aws-region: $AWS_REGION
46+
role-to-assume: ${{ secrets.AWS_SAR_ROLE_ARN }}
47+
- name: Setup Node.js
48+
uses: actions/setup-node@v3
49+
with:
50+
node-version: $NODE_VERSION
51+
- name: install cdk and deps
52+
run: |
53+
npm install -g "aws-cdk@$CDK_VERSION"
54+
cdk --version
55+
- name: Download artifact
56+
uses: actions/download-artifact@v3
57+
with:
58+
name: ${{ inputs.artefact-name }}
59+
path: layer
60+
- name: unzip artefact
61+
run: |
62+
unzip cdk.out.zip
63+
- name: Deploy x86_64 SAR
64+
run: |
65+
asset=$(jq -jc '.Resources[] | select(.Properties.CompatibleArchitectures == ["x86_64"]) | .Metadata."aws:asset:path"' cdk.out/LayerStack.template.json)
66+
sed -e "s/<VERSION>/${{ inputs.package-version }}/g" -e "s/<SAR_APP_NAME>/aws-lambda-powertools-python-layer-v2/g" -e "s/<LAYER_CONTENT_PATH>/.\/cdk.out\/$asset/g" sar/template.txt > sar/template.yml
67+
cp ../README.md ../LICENSE "./cdk.out/$asset/"
68+
pipx run sam=="$SAM_VERSION" package --template-file sar/template.yml --output-template-file packaged.yml --s3-bucket ${{ secrets.AWS_SAR_S3_BUCKET }}
69+
pipx run sam=="$SAM_VERSION" publish --template packaged.yml --region "$AWS_REGION"
70+
- name: Deploy arm64 SAR
71+
run: |
72+
asset=$(jq -jc '.Resources[] | select(.Properties.CompatibleArchitectures == ["arm64"]) | .Metadata."aws:asset:path"' cdk.out/LayerStack.template.json)
73+
sed -e "s/<VERSION>/${{ inputs.package-version }}/g" -e "s/<SAR_APP_NAME>/aws-lambda-powertools-python-layer-v2-arm64/g" -e "s/<LAYER_CONTENT_PATH>/.\/cdk.out\/$asset/g" sar/template.txt > sar/template.yml
74+
cp ../README.md ../LICENSE "./cdk.out/$asset/"
75+
pipx run sam=="$SAM_VERSION" package --template-file sar/template.yml --output-template-file packaged.yml --s3-bucket ${{ secrets.AWS_SAR_S3_BUCKET }}
76+
pipx run sam=="$SAM_VERSION" publish --template packaged.yml --region "$AWS_REGION"

layer/sar/template.txt

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
3+
Metadata:
4+
AWS::ServerlessRepo::Application:
5+
Name: <SAR_APP_NAME>
6+
Description: "AWS Lambda Layer for aws-lambda-powertools "
7+
Author: AWS
8+
SpdxLicenseId: Apache-2.0
9+
LicenseUrl: LICENSE
10+
ReadmeUrl: README.md
11+
Labels: ['layer','lambda','powertools','python', 'aws']
12+
HomePageUrl: https://github.com/awslabs/aws-lambda-powertools-python
13+
SemanticVersion: <VERSION>
14+
SourceCodeUrl: https://github.com/awslabs/aws-lambda-powertools-python
15+
16+
Transform: AWS::Serverless-2016-10-31
17+
Description: AWS Lambda Layer for aws-lambda-powertools with python 3.9, 3.8 or 3.7
18+
19+
Resources:
20+
LambdaLayer:
21+
Type: AWS::Serverless::LayerVersion
22+
Properties:
23+
Description: "AWS Lambda Layer for aws-lambda-powertools version <VERSION>"
24+
LayerName: <SAR_APP_NAME>
25+
ContentUri: <LAYER_CONTENT_PATH>
26+
CompatibleRuntimes:
27+
- python3.9
28+
- python3.8
29+
- python3.7
30+
LicenseInfo: 'Available under the Apache-2.0 license.'
31+
RetentionPolicy: Retain
32+
33+
Outputs:
34+
LayerVersionArn:
35+
Description: ARN for the published Layer version
36+
Value: !Ref LambdaLayer
37+
Export:
38+
Name: !Sub 'LayerVersionArn-${AWS::StackName}'

0 commit comments

Comments
 (0)