#4 Git Fixed Template. #54
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
name: Pipeline | |
on: | |
push: | |
branches: | |
- "main" | |
- "feature**" | |
paths: | |
- "backend/**" | |
- "template.yaml" | |
- ".github/workflows/**" | |
delete: | |
branches: | |
- "feature**" | |
env: | |
PIPELINE_USER_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
PIPELINE_USER_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
SAM_TEMPLATE: template.yaml | |
TESTING_STACK_NAME: Hakaton | |
TESTING_PIPELINE_EXECUTION_ROLE: arn:aws:iam::637423332149:role/aws-sam-cli-managed-Prod-pipe-PipelineExecutionRole-4GrKOHN5GWbe | |
TESTING_CLOUDFORMATION_EXECUTION_ROLE: arn:aws:iam::637423332149:role/aws-sam-cli-managed-Prod--CloudFormationExecutionRo-Zg8WRkjgoysq | |
TESTING_ARTIFACTS_BUCKET: aws-sam-cli-managed-prod-pipeline--artifactsbucket-fqycoijnkq2u | |
# 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: eu-central-1 | |
PROD_STACK_NAME: Hakaton | |
PROD_PIPELINE_EXECUTION_ROLE: arn:aws:iam::637423332149:role/aws-sam-cli-managed-Prod-pipe-PipelineExecutionRole-4GrKOHN5GWbe | |
PROD_CLOUDFORMATION_EXECUTION_ROLE: arn:aws:iam::637423332149:role/aws-sam-cli-managed-Prod--CloudFormationExecutionRo-Zg8WRkjgoysq | |
PROD_ARTIFACTS_BUCKET: aws-sam-cli-managed-prod-pipeline--artifactsbucket-fqycoijnkq2u | |
# If there are functions with "Image" PackageType in your template, | |
# uncomment the line below and add "--image-repository ${PROD_IMAGE_REPOSITORY}" to | |
# prod "sam package" and "sam deploy" commands. | |
# PROD_IMAGE_REPOSITORY = '0123456789.dkr.ecr.region.amazonaws.com/repository-name' | |
PROD_REGION: eu-central-1 | |
S3_BUCKET: s3-deployment-bucket-12421512 | |
jobs: | |
build-and-package: | |
if: github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: aws-actions/setup-sam@v2 | |
with: | |
use-installer: true | |
- name: Build resources | |
run: sam build --template ${SAM_TEMPLATE} --use-container | |
- name: Assume the prod pipeline user role | |
uses: aws-actions/configure-aws-credentials@v1-node16 | |
with: | |
aws-access-key-id: ${{ env.PIPELINE_USER_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ env.PIPELINE_USER_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.PROD_REGION }} | |
role-to-assume: ${{ env.PROD_PIPELINE_EXECUTION_ROLE }} | |
role-session-name: prod-packaging | |
role-duration-seconds: 3600 | |
role-skip-session-tagging: true | |
- name: Upload artifacts to production artifact buckets | |
run: | | |
sam package \ | |
--s3-bucket ${PROD_ARTIFACTS_BUCKET} \ | |
--region ${PROD_REGION} \ | |
--output-template-file packaged-prod.yaml | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: packaged-prod.yaml | |
path: packaged-prod.yaml | |
deploy-prod: | |
if: github.ref == 'refs/heads/main' | |
needs: [build-and-package] | |
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 | |
# environment: <configured-environment> | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: aws-actions/setup-sam@v2 | |
with: | |
use-installer: true | |
- uses: actions/download-artifact@v3 | |
with: | |
name: packaged-prod.yaml | |
- name: Assume the prod pipeline user role | |
uses: aws-actions/configure-aws-credentials@v1-node16 | |
with: | |
aws-access-key-id: ${{ env.PIPELINE_USER_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ env.PIPELINE_USER_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.PROD_REGION }} | |
role-to-assume: ${{ env.PROD_PIPELINE_EXECUTION_ROLE }} | |
role-session-name: prod-deployment | |
role-duration-seconds: 3600 | |
role-skip-session-tagging: true | |
- name: Deploy to production account | |
run: | | |
sam deploy --stack-name ${PROD_STACK_NAME} \ | |
--template packaged-prod.yaml \ | |
--capabilities CAPABILITY_IAM \ | |
--region ${PROD_REGION} \ | |
--s3-bucket ${PROD_ARTIFACTS_BUCKET} \ | |
--no-fail-on-empty-changeset \ | |
--role-arn ${PROD_CLOUDFORMATION_EXECUTION_ROLE} |