forked from bcgov/supreme-court-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JASPER-173: Develop the mTLS API Gateway components (#68)
* - Initial GHA for deploying Lambda functions to ECR - Test publish-lambdas GHA - Added lambdas - Added Dockerfile for creating lambda images - Added "initial" stack to separate resources that needs to be provisioned first - Refactor TF code to make it maintainable and reusable - Created Github Action to deploy lambda functions - Implemented first set of lambda functions - Added httpService class to isolate axios calls and certificate processing - Added mtls_cert in secrets - Updated openshift job to pull the new secret - Added eslint support for aws - Added deploying of initial TF stack - Cleanup in publish-lambdas - Used IAM in apigw method authorization for now until authorizer has been setup --------- Co-authored-by: Ronaldo Macapobre <[email protected]>
- Loading branch information
1 parent
1dd9e2e
commit 7e8c235
Showing
88 changed files
with
5,905 additions
and
768 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Build Lambda | ||
description: Builds all Lambda functions | ||
|
||
inputs: | ||
working_directory: | ||
description: The working directory where the code will be built. | ||
required: true | ||
node_version: | ||
description: The node version that will be used. | ||
required: true | ||
|
||
runs: | ||
using: composite | ||
|
||
steps: | ||
- name: Install Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ env.node_version }} | ||
|
||
- run: npm ci | ||
shell: bash | ||
working-directory: ${{ inputs.working_directory }} | ||
|
||
- run: npm run lint | ||
shell: bash | ||
working-directory: ${{ inputs.working_directory }} | ||
continue-on-error: false | ||
|
||
- run: npm run build | ||
shell: bash | ||
working-directory: ${{ inputs.working_directory }} | ||
|
||
- run: npm run test --if-present | ||
shell: bash | ||
working-directory: ${{ inputs.working_directory }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
name: Deploy Lambda | ||
description: Deploy image to a Lambda function to AWS | ||
|
||
inputs: | ||
environment: | ||
description: The environment to which the image will be deployed. | ||
required: true | ||
aws_account: | ||
description: The AWS Account ID. | ||
required: true | ||
region: | ||
description: The AWS Region of the AWS Account. | ||
required: true | ||
app_name: | ||
description: The application name. | ||
required: true | ||
resource: | ||
description: The resource path of the lambda function. | ||
required: true | ||
lambda_name: | ||
description: The lambda function name name. | ||
required: true | ||
aws_role_arn: | ||
description: The AWS Role ARN to assume. | ||
required: true | ||
ghcr_token: | ||
description: The token to use to login to the GHCR. | ||
required: true | ||
github_image_repo: | ||
description: The GCHR repo where images are stored. | ||
required: true | ||
image_name: | ||
description: The name of the image to be deployed. | ||
required: true | ||
short_sha: | ||
description: The short SHA used to tag image in GCHR. | ||
required: true | ||
|
||
runs: | ||
using: composite | ||
|
||
steps: | ||
- name: Set reusable variables | ||
id: vars | ||
shell: bash | ||
run: | | ||
echo "full_ecr_repo_url=${{ inputs.aws_account }}.dkr.ecr.${{ inputs.region }}.amazonaws.com/${{ inputs.app_name }}-lambda-repo-${{ inputs.environment }}" >> $GITHUB_OUTPUT | ||
echo "container_name=${{ inputs.app_name }}-${{ inputs.tier_name }}-container-${{ inputs.environment }}" >> $GITHUB_OUTPUT | ||
- name: Log in to the GHCR | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ inputs.ghcr_token }} | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
role-skip-session-tagging: true | ||
aws-region: ${{ inputs.region }} | ||
role-to-assume: ${{ inputs.aws_role_arn }} | ||
role-duration-seconds: 1800 | ||
role-session-name: ci-deployment | ||
|
||
- name: Login to Amazon ECR | ||
uses: aws-actions/amazon-ecr-login@v2 | ||
|
||
- name: Check ECR Image exists | ||
id: ecr-check | ||
shell: bash | ||
run: | | ||
IMAGE_TAG=${{ inputs.resource }}${{ inputs.lambda_name }}-${{ inputs.short_sha }} | ||
REPOSITORY_NAME=${{ inputs.app_name }}-lambda-repo-${{ inputs.environment }} | ||
IMAGE_EXISTS=$(aws ecr describe-images --repository-name $REPOSITORY_NAME --query "imageDetails[?contains(imageTags, '$IMAGE_TAG')]" --output text) | ||
if [ -z "$IMAGE_EXISTS" ]; then | ||
echo "Image with tag $IMAGE_TAG does not exist." | ||
echo "exists=false" >> $GITHUB_OUTPUT | ||
else | ||
echo "Image with tag $IMAGE_TAG already exists." | ||
echo "exists=true" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Push if Docker image does not exist | ||
if: steps.ecr-check.outputs.exists == 'false' | ||
shell: bash | ||
run: | | ||
docker pull ${{ inputs.github_image_repo }}/${{ inputs.image_name }}:${{ inputs.short_sha}} | ||
docker tag ${{ inputs.github_image_repo }}/${{ inputs.image_name }}:${{ inputs.short_sha}} ${{ steps.vars.outputs.full_ecr_repo_url }}:${{ inputs.image_name }}-${{ inputs.short_sha }} | ||
docker push ${{ steps.vars.outputs.full_ecr_repo_url }}:${{ inputs.image_name }}-${{ inputs.short_sha }} | ||
- name: Update Lambda Function | ||
shell: bash | ||
run: | | ||
aws lambda update-function-code \ | ||
--function-name ${{ inputs.app_name }}-${{ inputs.lambda_name }}-lambda-${{ inputs.environment }} \ | ||
--image-uri ${{ env.full_ecr_repo_url }}:${{ inputs.resource }}.${{ inputs.lambda_name }}-${{ inputs.short_sha }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Build and Test Lambdas | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
paths: | ||
- "aws/**" | ||
|
||
workflow_dispatch: | ||
|
||
env: | ||
WORKING_DIRECTORY: ./aws | ||
NODE_VERSION: 20 | ||
|
||
jobs: | ||
build-and-test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Building Lambdas codebase | ||
uses: ./.github/workflows/actions/build-lambdas | ||
with: | ||
working_directory: ${{ env.WORKING_DIRECTORY }} | ||
node_version: ${{ env.NODE_VERSION }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.