Skip to content

Commit

Permalink
Create infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
longbui98 committed Oct 24, 2023
1 parent 9424ce3 commit 1cd8e40
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 48 deletions.
85 changes: 42 additions & 43 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ version: 2.1
commands:
destroy-environment:
description: Destroy back-end and front-end cloudformation stacks given a workflow ID.
parameters:
# Add parameter here
steps:
- run:
name: Destroy environments
when: on_fail
command: |
# Your code here
exit 1
aws cloudformation delete-stack --stack-name udapeople-backend-${CIRCLE_WORKFLOW_ID:0:7}
revert-migrations:
description: Revert the last migration if successfully run in the current workflow.
Expand Down Expand Up @@ -129,40 +126,42 @@ jobs:
npm audit fix --force
npm audit --audit-level=critical
# deploy-infrastructure:
# docker:
# # Docker image here that supports AWS CLI
# steps:
# # Checkout code from git
# - run:
# name: Ensure back-end infrastructure exists
# command: |
# aws cloudformation deploy \
# --template-file .circleci/files/backend.yml \
# #--tags project=your-tag \
# # --stack-name "your back-end stack name with workflow id" \
# # --parameter-overrides ID="your workflow id"
# exit 1
# - run:
# name: Ensure front-end infrastructure exist
# command: |
# aws cloudformation deploy \
# --template-file .circleci/files/frontend.yml \
# #--tags project=your-tag \
# # --stack-name "your front-end stack name with workflow id" \
# # --parameter-overrides ID="your workflow id"
# exit 1
# - run:
# name: Add back-end ip to ansible inventory
# command: |
# # Your code here
# exit 1
# - persist_to_workspace:
# root: ~/
# paths:
# - project/.circleci/ansible/inventory.txt
# # Here's where you will add some code to rollback on failure

deploy-infrastructure:
docker:
- image: amazon/aws-cli
steps:
- checkout
- run:
name: Install tar and gzip
command: |
yum install -y tar gzip
- run:
name: Ensure back-end infrastructure exists
command: |
aws cloudformation deploy \
--template-file .circleci/files/backend.yml \
--tags project=cicd_project \
--stack-name "udapeople-backend-${CIRCLE_WORKFLOW_ID:0:7}" \
--parameter-overrides ID="udapeople-backend-${CIRCLE_WORKFLOW_ID:0:7}"
- run:
name: Ensure front-end infrastructure exist
command: |
aws cloudformation deploy \
--template-file .circleci/files/frontend.yml \
--tags project=cicd_project \
--stack-name "udapeople-backend-${CIRCLE_WORKFLOW_ID:0:7}" \
--parameter-overrides ID="udapeople-backend-${CIRCLE_WORKFLOW_ID:0:7}"
- run:
name: Add back-end ip to ansible inventory
command: |
aws ec2 describe-instances \
--query 'Reservations[*].Instances[*].PublicIpAddress' \
--output text >> inventory
- persist_to_workspace:
root: ~/
paths:
- project/.circleci/ansible/inventory.txt
- destroy-environment
# configure-infrastructure:
# docker:
# # Docker image here that supports Ansible
Expand Down Expand Up @@ -308,11 +307,11 @@ workflows:
requires: [build-backend]
- scan-frontend:
requires: [build-frontend]
# - deploy-infrastructure:
# requires: [test-frontend, test-backend, scan-frontend, scan-backend]
# filters:
# branches:
# only: [test-feature-branch]
- deploy-infrastructure:
requires: [test-frontend, test-backend, scan-frontend, scan-backend]
filters:
branches:
only: [test-feature-branch]
# - configure-infrastructure:
# requires: [deploy-infrastructure]
# - run-migrations:
Expand Down
6 changes: 2 additions & 4 deletions .circleci/files/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ Resources:
InstanceType: t2.micro
SecurityGroups:
- Ref: InstanceSecurityGroup
KeyName: udacity # If you use another key pair name, you should change this value to match.
# If this ami id is not available for you, you can find another (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/finding-an-ami.html)
# Ubuntu 18 or higher works fine
ImageId: ami-068663a3c619dd892
KeyName: test-key2
ImageId: ami-0fc5d935ebf8bc3bc
Tags:
- Key: Name
Value: !Sub backend-${ID}
3 changes: 2 additions & 1 deletion .circleci/files/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Resources:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub "udapeople-${ID}"
AccessControl: PublicRead
PublicAccessBlockConfiguration:
BlockPublicPolicy: false
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: 404.html
Expand Down

0 comments on commit 1cd8e40

Please sign in to comment.