-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatize deployment script #2
base: master
Are you sure you want to change the base?
Changes from 7 commits
c3ddd02
6839b24
c03affb
5045704
0e102a4
940f336
d11a407
83ae729
16dd766
cb77676
0511a81
006a5bb
f330a5d
483d9dc
703ed56
15ef0e2
bf60d17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ node_modules/ | |
# Local files | ||
terraform.tfvars | ||
ip | ||
ips | ||
elb_dns | ||
src.zip | ||
key.pem |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ resource "aws_elb" "node_asg_elb" { | |
} | ||
|
||
provisioner "local-exec" { | ||
command = "echo ${aws_elb.node_asg_elb.dns_name} >> node/elb_dns" | ||
command = "echo ${aws_elb.node_asg_elb.dns_name} > node/elb_dns" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Este cambio ya está hecho en master, qué raro que siga apareciendo en el diff... Podrías hacer un rebase de la branch porfa (o desde una nueva branch, para no modificar lo que hicieorn uds para su tp)? |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,5 @@ else | |
COMMAND="${@:2}" | ||
fi | ||
|
||
ssh -i $DIR/../key.pem ec2-user@$IP -- $COMMAND | ||
# The -o StrictHostKeyChecking=no is to avoid asking for permission to add the $IP to the list of known hosts | ||
ssh -o StrictHostKeyChecking=no -i $DIR/../key.pem ec2-user@$IP -- $COMMAND | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Genial jajaja 👍 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,12 @@ echo "using IP $IP..." | |
|
||
$DIR/stop $IP | ||
|
||
# The -o for the unzip command overrides if there's any existing file | ||
$DIR/remote $IP "\ | ||
echo 'Downloading updated src' && \ | ||
curl https://s3.amazonaws.com/tp-arqui-node-app-src/src.zip > src.zip && \ | ||
curl https://s3.amazonaws.com/tp-arquitecturas/src.zip > src.zip && \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Por favor, hacer que la url se lea de alguna configuración (por ejemplo, un archivo local que se llame There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahí estoy haciendo que lo lea de una variable de entorno. No sé si es posible hacer que esa misma se use en el There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sí, deberías poder hacer que el |
||
echo 'Unpacking src code' && \ | ||
unzip src.zip && \ | ||
unzip -o src.zip && \ | ||
echo 'Installing dependencies' && \ | ||
npm i" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
|
||
IPS=`cat $DIR/ips` | ||
|
||
while IFS='' read -r ip <&3 || [[ -n "$ip" ]]; do | ||
$DIR/update $ip | ||
done 3< ips | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Por favor, agregar un salto de línea al final para que GitHub no ponga símbolos feos en el diff 😅 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,11 @@ resource "aws_instance" "python" { | |
command = "echo ${aws_instance.python.public_ip} > python/ip" | ||
} | ||
|
||
# Use the python app IP in node code | ||
provisioner "local-exec" { | ||
command = "sed -E \"s/(remoteBaseUri:)[^,]*,/\\1 'http:\\/\\/$(cat python/ip):3000',/\" node/config.js > node/temp.js && mv node/temp.js node/config.js" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sugerencia: Mejorar esto para que use el parámetro (tengo que hacer lo mismo en el paso en que configuro datadog dentro del user data yo, je) |
||
} | ||
|
||
# Environment setup | ||
provisioner "remote-exec" { | ||
inline = [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
|
||
# Create infrastructure. This also changes the python IP in the node app so that they can communicate | ||
echo "##### Applying terraform infrastructure #####" | ||
~/terraform apply -auto-approve | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preferiría sacar el terraform apply -auto-approve |
||
|
||
# Start the python app that is not started in the terraform apply command | ||
echo "##### Starting python app #####" | ||
cd python && ./start | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Esto se puede cambiar por algo tipo $DIR/python/start y así funciona independendientemente de dónde esté parada la terminal al ejecutar el script (ver otros scripts sobre cómo setearla). |
||
|
||
cd ../node | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Por favor, seteá una variable $DIR como en los otros scripts y usala, para que se pueda correr desde cualquier lado |
||
|
||
# Get node instances IPs with the AWS CLI. It returns a tab-separated string with the IPs, so we transform them to end-lines | ||
echo "##### Getting node instances IPs #####" | ||
aws ec2 describe-instances --profile terraform --query "Reservations[*].Instances[*].PublicIpAddress" --filters "Name=tag-value,Values=tp_arqui_node_asg_instance" --output=text | tr '\t' '\n' > ips | ||
|
||
# Zip the source code of the node apps with the correct python IP | ||
echo "##### Zipping node source code #####" | ||
./zip | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usar un path absoluto con $DIR |
||
echo "##### Uploading node source code to S3 bucket #####" | ||
aws s3 cp src.zip s3://tp-arquitecturas/src.zip --profile terraform | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Por favor, hacer que la url del código se lea de alguna configuración (archivo local, variable de entorno o argumento) |
||
|
||
# Update the node instances code with the src code uploaded to S3 | ||
while IFS='' read -r ip <&3 || [[ -n "$ip" ]]; do | ||
echo "##### Updating node source code of instance with IP $ip #####" | ||
./update "$ip" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usar paths absolutos con $DIR |
||
done 3< ips | ||
|
||
cd .. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,17 +24,17 @@ variable "private_key_location" { | |
} | ||
|
||
variable "vpc_id" { | ||
default = "vpc-7563400d" | ||
default = "vpc-d7cec3ac" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Por favor, rollbackear los cambios de este archivo |
||
} | ||
|
||
variable "ami_id" { | ||
default = "ami-1853ac65" | ||
default = "ami-14c5486b" | ||
} | ||
|
||
variable "node_version" { | ||
default = "8.11.2" | ||
default = "8.11.1" | ||
} | ||
|
||
variable "src_location" { | ||
default = "https://s3.amazonaws.com/tp-arqui-node-app-src/src.zip" | ||
default = "https://s3.amazonaws.com/tp-arquitecturas/src.zip" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me encanta la documentación!
Lo único, qué opinás de mover la explicación detallada de cómo funciona el script al script mismo? O sea, comentarios arriba de cada línea explicando que hacen por ejemplo (en español está bien por mí, aunque la mayor parte del código esté en inglés), para no tener el código casi duplicado como queda así, que si alguien modifica cualquier cosa del script tiene que venir también a cambiar el README. El TL;DR sí me parece bien que esté acá para que el script tenga visibilidad.