|
| 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" |
0 commit comments