Created
August 1, 2019 09:13
-
-
Save sayadi/eaa99f4621a3b32abd559d81aa19c96f to your computer and use it in GitHub Desktop.
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
version: 2 | |
general: | |
branches: | |
only: | |
- dev | |
- staging | |
- prod | |
jobs: | |
build: | |
docker: | |
- image: circleci/openjdk:8-jdk | |
steps: | |
- checkout | |
- run: | |
name: Deploy | |
command: | | |
# 1- Install AWS CLI | |
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip" | |
unzip awscli-bundle.zip | |
./awscli-bundle/install -b ~/bin/aws | |
# 2- Get the public IP of the current CircleCI runner | |
PUBLIC_IP=$(curl ipinfo.io/ip) | |
# 3- Get AWS Region# TODO Don't forget to replcae by your own Region | |
AWS_REGION=us-east-2 | |
# 4- Get SG ID# TODO Don't forget to replace by your own SG ID | |
SG_ID=sg-XXXXXXXX | |
# 5- Add an ingress rule to the security group | |
~/bin/aws ec2 authorize-security-group-ingress --region $AWS_REGION --group-id $SG_ID \ | |
--protocol tcp --port 22 --cidr $PUBLIC_IP/24 | |
# 6- Give the ingress rule some time to propogate | |
sleep 5 | |
# 7- SSH to the server to deploy | |
# TODO Change to your username | |
EC2_USERNAME=ubuntu | |
# TODO Change to your server's URL or public IP | |
EC2_PUBLIC_DNS=application-server.example.com | |
ssh -o StrictHostKeyChecking=no $EC2_USERNAME@$EC2_PUBLIC_DNS \ | |
# other commands | |
# TODO Perform steps to deploy | |
# . | |
# . | |
# . | |
# 8- Remove the ingress rule | |
~/bin/aws ec2 revoke-security-group-ingress --region $AWS_REGION --group-id $SG_ID \ | |
--protocol tcp --port 22 --cidr $PUBLIC_IP/24 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not working