|
| 1 | +name: Deploy Lambda PDV reconciler |
| 2 | +permissions: |
| 3 | + contents: read |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - "main" |
| 9 | + paths: |
| 10 | + - "**/src/oneid/oneid-lambda-pdv-reconciler/**" |
| 11 | + workflow_dispatch: |
| 12 | + inputs: |
| 13 | + environment: |
| 14 | + description: 'Choose environment' |
| 15 | + type: choice |
| 16 | + required: true |
| 17 | + default: dev |
| 18 | + options: |
| 19 | + - dev |
| 20 | + - uat |
| 21 | + - prod |
| 22 | +jobs: |
| 23 | + setup: |
| 24 | + runs-on: ubuntu-22.04 |
| 25 | + outputs: |
| 26 | + matrix: ${{ steps.setmatrix.outputs.matrix }} |
| 27 | + |
| 28 | + steps: |
| 29 | + - name: Set Dynamic Env Matrix |
| 30 | + id: setmatrix |
| 31 | + run: | |
| 32 | + echo "github.ref ${{ github.ref }}" |
| 33 | + echo "event name ${{ github.event_name }}" |
| 34 | + |
| 35 | + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then |
| 36 | + if [ "${{ github.event.inputs.environment }}" == "prod" ]; then |
| 37 | + matrixStringifiedObject="{\"include\":[{\"environment\":\"prod\", \"region\":\"eu-south-1\"}, {\"environment\":\"prod\", \"region\":\"eu-central-1\"}]}" |
| 38 | + else |
| 39 | + matrixStringifiedObject="{\"include\":[{\"environment\":\"${{ github.event.inputs.environment }}\", \"region\":\"eu-south-1\"}]}" |
| 40 | + fi |
| 41 | + else |
| 42 | + matrixStringifiedObject="{\"include\":[{\"environment\":\"dev\", \"region\":\"eu-south-1\"}, {\"environment\":\"uat\", \"region\":\"eu-south-1\"}, {\"environment\":\"prod\", \"region\":\"eu-south-1\"}, {\"environment\":\"prod\", \"region\":\"eu-central-1\"}]}" |
| 43 | + fi |
| 44 | +
|
| 45 | + echo "matrix=$matrixStringifiedObject" >> $GITHUB_OUTPUT |
| 46 | +
|
| 47 | + build: |
| 48 | + runs-on: ubuntu-22.04 |
| 49 | + steps: |
| 50 | + - name: Checkout code |
| 51 | + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 |
| 52 | + |
| 53 | + - name: Zip Lambda |
| 54 | + working-directory: src/oneid/oneid-lambda-pdv-reconciler |
| 55 | + run: | |
| 56 | + mkdir -p ./target && zip -r target/oneid-lambda-pdv-reconciler.zip . -x "*.dist-info/*" -x "target/*" |
| 57 | +
|
| 58 | + - name: Archive build artifacts |
| 59 | + uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 |
| 60 | + with: |
| 61 | + name: pdv-reconciler-lambda |
| 62 | + path: ./src/oneid/oneid-lambda-pdv-reconciler/target/oneid-lambda-pdv-reconciler.zip |
| 63 | + |
| 64 | + deploy: |
| 65 | + name: Deploy lambda pdv reconciler ${{ matrix.environment }}-${{ matrix.region }} |
| 66 | + if: ${{ needs.setup.outputs.matrix != '' }} |
| 67 | + runs-on: ubuntu-22.04 |
| 68 | + needs: [ setup, build ] |
| 69 | + strategy: |
| 70 | + matrix: ${{ fromJson(needs.setup.outputs.matrix) }} |
| 71 | + |
| 72 | + continue-on-error: false |
| 73 | + environment: ${{ matrix.environment == 'prod' && format('{0}/{1}', matrix.environment, matrix.region) || matrix.environment }} |
| 74 | + env: |
| 75 | + ENV_SHORT: ${{ fromJSON('{"dev":"d","uat":"u","prod":"p"}')[matrix.environment] }} |
| 76 | + REGION_SHORT: ${{ fromJSON('{"eu-south-1":"es-1","eu-central-1":"ec-1"}')[matrix.region] }} |
| 77 | + permissions: |
| 78 | + id-token: write |
| 79 | + contents: read |
| 80 | + |
| 81 | + steps: |
| 82 | + - name: Download build artifacts |
| 83 | + uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e |
| 84 | + with: |
| 85 | + name: pdv-reconciler-lambda |
| 86 | + path: ./src/oneid/oneid-lambda-pdv-reconciler/target |
| 87 | + |
| 88 | + - name: Configure AWS Credentials |
| 89 | + uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 |
| 90 | + with: |
| 91 | + role-to-assume: ${{ vars.IAM_ROLE_DEPLOY_LAMBDA }} |
| 92 | + aws-region: ${{ matrix.region }} |
| 93 | + |
| 94 | + - name: Update Lambda function (${{ matrix.environment }}) |
| 95 | + run: | |
| 96 | + aws s3 cp src/oneid/oneid-lambda-pdv-reconciler/target/oneid-lambda-pdv-reconciler.zip s3://${{vars.LAMBDA_CODE_BUCKET_NAME}}/${{vars.LAMBDA_PDV_RECONCILER_KEY}} |
| 97 | +
|
| 98 | + - name: Deploy Lambda function (${{ matrix.environment }}) |
| 99 | + run: | |
| 100 | + aws lambda update-function-code \ |
| 101 | + --function-name oneid-${{ env.REGION_SHORT }}-${{ env.ENV_SHORT }}-pdv-reconciler \ |
| 102 | + --s3-bucket ${{vars.LAMBDA_CODE_BUCKET_NAME}} --s3-key ${{vars.LAMBDA_PDV_RECONCILER_KEY}} |
0 commit comments