Skip to content

Commit

Permalink
change pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
maahdisrostampoor committed Jul 12, 2024
1 parent 642912d commit 8a97c12
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 55 deletions.
106 changes: 52 additions & 54 deletions .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@ on:
branches:
- 'main'
- 'feature**'
delete:
branches:
- 'feature**'
# dgieature**'

env:
SAM_TEMPLATE: template.yaml
TESTING_STACK_NAME: sam-dev
TESTING_PIPELINE_EXECUTION_ROLE: arn:aws:iam::381492285923:role/aws-sam-cli-managed-dev-pipel-PipelineExecutionRole-UaHDX0uHMlbb
TESTING_CLOUDFORMATION_EXECUTION_ROLE: arn:aws:iam::381492285923:role/aws-sam-cli-managed-dev-p-CloudFormationExecutionRo-w8faWVZpG2wg
TESTING_ARTIFACTS_BUCKET: aws-sam-cli-managed-dev-pipeline-r-artifactsbucket-hkgixjbuzwh8
DEV_STACK_NAME: sam-dev
DEV_PIPELINE_EXECUTION_ROLE: arn:aws:iam::381492285923:role/aws-sam-cli-managed-dev-pipel-PipelineExecutionRole-UaHDX0uHMlbb
DEV_CLOUDFORMATION_EXECUTION_ROLE: arn:aws:iam::381492285923:role/aws-sam-cli-managed-dev-p-CloudFormationExecutionRo-w8faWVZpG2wg
DEV_ARTIFACTS_BUCKET: aws-sam-cli-managed-dev-pipeline-r-artifactsbucket-hkgixjbuzwh8
# If there are functions with "Image" PackageType in your template,
# uncomment the line below and add "--image-repository ${TESTING_IMAGE_REPOSITORY}" to
# testing "sam package" and "sam deploy" commands.
# TESTING_IMAGE_REPOSITORY = '0123456789.dkr.ecr.region.amazonaws.com/repository-name'
TESTING_REGION: us-east-1
# uncomment the line below and add "--image-repository ${DEV_IMAGE_REPOSITORY}" to
# DEV "sam package" and "sam deploy" commands.
# DEV_IMAGE_REPOSITORY = '0123456789.dkr.ecr.region.amazonaws.com/repository-name'
DEV_REGION: us-east-1
PROD_STACK_NAME: sam-prod
PROD_PIPELINE_EXECUTION_ROLE: arn:aws:iam::381492285923:role/aws-sam-cli-managed-prod-pipe-PipelineExecutionRole-nqfCgyJpQeCe
PROD_CLOUDFORMATION_EXECUTION_ROLE: arn:aws:iam::381492285923:role/aws-sam-cli-managed-prod--CloudFormationExecutionRo-XyodNvEhsqDv
Expand Down Expand Up @@ -51,12 +49,12 @@ jobs:
with:
use-installer: true

- name: Assume the testing pipeline user role
- name: Assume the DEV pipeline user role
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: ${{ env.TESTING_REGION }}
role-to-assume: ${{ env.TESTING_PIPELINE_EXECUTION_ROLE }}
role-session-name: testing-packaging
aws-region: ${{ env.DEV_REGION }}
role-to-assume: ${{ env.DEV_PIPELINE_EXECUTION_ROLE }}
role-session-name: DEV-packaging
role-duration-seconds: 3600
role-skip-session-tagging: true

Expand All @@ -66,7 +64,7 @@ jobs:
run: |
sam delete \
--stack-name $(echo ${FEATURE_BRANCH_NAME##*/} | tr -cd '[a-zA-Z0-9-]') \
--region ${TESTING_REGION} \
--region ${DEV_REGION} \
--no-prompts
build-and-deploy-feature:
Expand All @@ -84,24 +82,24 @@ jobs:
use-installer: true
- run: sam build --template ${SAM_TEMPLATE} --use-container

- name: Assume the testing pipeline user role
- name: Assume the DEV pipeline user role
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: ${{ env.TESTING_REGION }}
role-to-assume: ${{ env.TESTING_PIPELINE_EXECUTION_ROLE }}
aws-region: ${{ env.DEV_REGION }}
role-to-assume: ${{ env.DEV_PIPELINE_EXECUTION_ROLE }}
role-session-name: feature-deployment
role-duration-seconds: 3600
role-skip-session-tagging: true

- name: Deploy to feature stack in the testing account
- name: Deploy to feature stack in the DEV account
shell: bash
run: |
sam deploy --stack-name $(echo ${GITHUB_REF##*/} | tr -cd '[a-zA-Z0-9-]') \
--capabilities CAPABILITY_IAM \
--region ${TESTING_REGION} \
--s3-bucket ${TESTING_ARTIFACTS_BUCKET} \
--region ${DEV_REGION} \
--s3-bucket ${DEV_ARTIFACTS_BUCKET} \
--no-fail-on-empty-changeset \
--role-arn ${TESTING_CLOUDFORMATION_EXECUTION_ROLE}
--role-arn ${DEV_CLOUDFORMATION_EXECUTION_ROLE}
build-and-package:
if: github.ref == 'refs/heads/main'
Expand All @@ -116,26 +114,26 @@ jobs:
- name: Build resources
run: sam build --template ${SAM_TEMPLATE} --use-container

- name: Assume the testing pipeline user role
- name: Assume the DEV pipeline user role
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: ${{ env.TESTING_REGION }}
role-to-assume: ${{ env.TESTING_PIPELINE_EXECUTION_ROLE }}
role-session-name: testing-packaging
aws-region: ${{ env.DEV_REGION }}
role-to-assume: ${{ env.DEV_PIPELINE_EXECUTION_ROLE }}
role-session-name: DEV-packaging
role-duration-seconds: 3600
role-skip-session-tagging: true

- name: Upload artifacts to testing artifact buckets
- name: Upload artifacts to DEV artifact buckets
run: |
sam package \
--s3-bucket ${TESTING_ARTIFACTS_BUCKET} \
--region ${TESTING_REGION} \
--output-template-file packaged-testing.yaml
--s3-bucket ${DEV_ARTIFACTS_BUCKET} \
--region ${DEV_REGION} \
--output-template-file packaged-DEV.yaml
- uses: actions/upload-artifact@v3
with:
name: packaged-testing.yaml
path: packaged-testing.yaml
name: packaged-DEV.yaml
path: packaged-DEV.yaml

- name: Assume the prod pipeline user role
uses: aws-actions/configure-aws-credentials@v1-node16
Expand All @@ -158,7 +156,7 @@ jobs:
name: packaged-prod.yaml
path: packaged-prod.yaml

deploy-testing:
deploy-dev:
if: github.ref == 'refs/heads/main'
needs: [build-and-package]
runs-on: ubuntu-latest
Expand All @@ -169,39 +167,39 @@ jobs:
use-installer: true
- uses: actions/download-artifact@v3
with:
name: packaged-testing.yaml
name: packaged-dev.yaml

- name: Assume the testing pipeline user role
- name: Assume the dev pipeline user role
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: ${{ env.TESTING_REGION }}
role-to-assume: ${{ env.TESTING_PIPELINE_EXECUTION_ROLE }}
role-session-name: testing-deployment
aws-region: ${{ env.DEV_REGION }}
role-to-assume: ${{ env.DEV_PIPELINE_EXECUTION_ROLE }}
role-session-name: dev-deployment
role-duration-seconds: 3600
role-skip-session-tagging: true

- name: Deploy to testing account
- name: Deploy to de account
run: |
sam deploy --stack-name ${TESTING_STACK_NAME} \
--template packaged-testing.yaml \
sam deploy --stack-name ${DEV_STACK_NAME} \
--template packaged-dev.yaml \
--capabilities CAPABILITY_IAM \
--region ${TESTING_REGION} \
--s3-bucket ${TESTING_ARTIFACTS_BUCKET} \
--region ${DEV_REGION} \
--s3-bucket ${DEV_ARTIFACTS_BUCKET} \
--no-fail-on-empty-changeset \
--role-arn ${TESTING_CLOUDFORMATION_EXECUTION_ROLE}
--role-arn ${DEV_CLOUDFORMATION_EXECUTION_ROLE}
integration-test:
if: github.ref == 'refs/heads/main'
needs: [deploy-testing]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: |
# trigger the integration tests here
# integration-test:
# if: github.ref == 'refs/heads/main'
# needs: [deploy-DEV]
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - run: |
# # trigger the integration tests here

deploy-prod:
if: github.ref == 'refs/heads/main'
needs: [integration-test]
# needs: [integration-test]
runs-on: ubuntu-latest
# Configure GitHub Action Environment to have a manual approval step before deployment to production
# https://docs.github.com/en/actions/reference/environments
Expand Down
2 changes: 1 addition & 1 deletion back/movie_lambda/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def lambda_handler(event, context):

# Perform business logic in separate functions
results = perform_google_image_search(image_url)
print(results)
movie_title_list = extract_movie_titles(results)
movie_name_ai = perform_openai_check(results)
final_movie_name = get_final_movie_name(movie_title_list, movie_name_ai)
Expand Down Expand Up @@ -73,7 +74,6 @@ def perform_google_image_search(image_url):
}

search = GoogleSearch(params)
print(search)
return search.get_dict()

def extract_movie_titles(results):
Expand Down
6 changes: 6 additions & 0 deletions back/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Resources:
Properties:
Handler: lambda_function.lambda_handler # Adjust the handler name as per your Lambda function
CodeUri: back/movie_lambda/
VpcConfig:
SubnetIds:
- subnet-02f00e5bc9c9de7ad # Replace with your first private subnet ID
- subnet-0d7e41089c0053eeb # Replace with your private subnet ID
SecurityGroupIds:
- sg-0e968d4e859aedaf0 # Replace with your Lambda function's security group ID
Events:
ApiEvent:
Type: Api
Expand Down

0 comments on commit 8a97c12

Please sign in to comment.