Commit 653c6723 by Feanil Patel

Optionally tag instances when roles deploy code.

The instance gets tagged with the repo and hash that was deployed.
parent a3634074
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
dest="{{ alton_code_dir }}" repo="{{ alton_source_repo }}" dest="{{ alton_code_dir }}" repo="{{ alton_source_repo }}"
version="{{ alton_version }}" accept_hostkey=yes version="{{ alton_version }}" accept_hostkey=yes
sudo_user: "{{ alton_user }}" sudo_user: "{{ alton_user }}"
register: alton_checkout
notify: restart alton notify: restart alton
- name: install the requirements - name: install the requirements
...@@ -55,3 +56,5 @@ ...@@ -55,3 +56,5 @@
state=started state=started
when: not disable_edx_services when: not disable_edx_services
- include: ec2.yml tags=deploy
when: COMMON_TAG_EC2_INSTANCE
---
- name: get instance information
action: ec2_facts
tags:
- deploy
- name: tag instance
ec2_tag: resource={{ ansible_ec2_instance_id }} region={{ ansible_ec2_placement_region }}
args:
tags:
"version:alton" : "{{ alton_source_repo }} {{ alton_checkout.after |truncate(7,True,'')}}"
when: alton_checkout.after is defined
tags:
- deploy
...@@ -109,3 +109,6 @@ ...@@ -109,3 +109,6 @@
- name: remove read-only ssh key for the content repo - name: remove read-only ssh key for the content repo
file: path={{ analytics_api_git_identity_file }} state=absent file: path={{ analytics_api_git_identity_file }} state=absent
- include: ec2.yml tags=deploy
when: COMMON_TAG_EC2_INSTANCE
---
- name: get instance information
action: ec2_facts
- name: tag instance
ec2_tag: resource={{ ansible_ec2_instance_id }} region={{ ansible_ec2_placement_region }}
args:
tags:
"version:analytics_api" : "{{ analytics_api_source_repo }} {{ analytics_api_code_checkout.after |truncate(7,True,'')}}"
when: analytics_api_code_checkout.after is defined
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
sudo_user: "{{ certs_user }}" sudo_user: "{{ certs_user }}"
environment: environment:
GIT_SSH: "{{ certs_git_ssh }}" GIT_SSH: "{{ certs_git_ssh }}"
register: certs_checkout
notify: restart certs notify: restart certs
- name: remove read-only ssh key for the certs repo - name: remove read-only ssh key for the certs repo
...@@ -96,4 +97,7 @@ ...@@ -96,4 +97,7 @@
- python - python
- pip - pip
- include: ec2.yml tags=deploy
when: COMMON_TAG_EC2_INSTANCE
- set_fact: certs_installed=true - set_fact: certs_installed=true
---
- name: get instance information
action: ec2_facts
- name: tag instance
ec2_tag: resource={{ ansible_ec2_instance_id }} region={{ ansible_ec2_placement_region }}
args:
tags:
"version:certs" : "{{ CERT_REPO }} {{ certs_checkout.after|truncate(7,True,'') }}"
when: certs_checkout.after is defined
...@@ -55,6 +55,7 @@ COMMON_MONGO_READ_ONLY_PASS: !!null ...@@ -55,6 +55,7 @@ COMMON_MONGO_READ_ONLY_PASS: !!null
COMMON_ENABLE_DATADOG: False COMMON_ENABLE_DATADOG: False
COMMON_ENABLE_SPLUNKFORWARDER: False COMMON_ENABLE_SPLUNKFORWARDER: False
COMMON_ENABLE_NEWRELIC: False COMMON_ENABLE_NEWRELIC: False
COMMON_TAG_EC2_INSTANCE: False
common_debian_pkgs: common_debian_pkgs:
- ntp - ntp
- ack-grep - ack-grep
......
...@@ -29,12 +29,14 @@ ...@@ -29,12 +29,14 @@
# Do A Checkout # Do A Checkout
- name: checkout edx-platform repo into {{edxapp_code_dir}} - name: checkout edx-platform repo into {{edxapp_code_dir}}
git: > git: >
dest={{edxapp_code_dir}} repo={{edx_platform_repo}} version={{edx_platform_version}} dest={{edxapp_code_dir}}
repo={{edx_platform_repo}}
version={{edx_platform_version}}
accept_hostkey=yes accept_hostkey=yes
register: chkout
sudo_user: "{{ edxapp_user }}" sudo_user: "{{ edxapp_user }}"
environment: environment:
GIT_SSH: "{{ edxapp_git_ssh }}" GIT_SSH: "{{ edxapp_git_ssh }}"
register: edxapp_platform_checkout
notify: notify:
- "restart edxapp" - "restart edxapp"
- "restart edxapp_workers" - "restart edxapp_workers"
...@@ -48,12 +50,15 @@ ...@@ -48,12 +50,15 @@
- name: checkout theme - name: checkout theme
git: > git: >
dest={{ edxapp_app_dir }}/themes/{{edxapp_theme_name}} repo={{edxapp_theme_source_repo}} version={{edxapp_theme_version}} dest={{ edxapp_app_dir }}/themes/{{edxapp_theme_name}}
repo={{edxapp_theme_source_repo}}
version={{edxapp_theme_version}}
accept_hostkey=yes accept_hostkey=yes
when: edxapp_theme_name != '' when: edxapp_theme_name != ''
sudo_user: "{{ edxapp_user }}" sudo_user: "{{ edxapp_user }}"
environment: environment:
GIT_SSH: "{{ edxapp_git_ssh }}" GIT_SSH: "{{ edxapp_git_ssh }}"
register: edxapp_theme_checkout
notify: notify:
- "restart edxapp" - "restart edxapp"
- "restart edxapp_workers" - "restart edxapp_workers"
...@@ -417,4 +422,7 @@ ...@@ -417,4 +422,7 @@
file: path={{ edxapp_git_identity }} state=absent file: path={{ edxapp_git_identity }} state=absent
when: EDXAPP_USE_GIT_IDENTITY when: EDXAPP_USE_GIT_IDENTITY
- include: ec2.yml tags=deploy
when: COMMON_TAG_EC2_INSTANCE
- set_fact: edxapp_installed=true - set_fact: edxapp_installed=true
---
- name: get instance information
action: ec2_facts
- name: tag instance with edx_platform version
ec2_tag: resource={{ ansible_ec2_instance_id }} region={{ ansible_ec2_placement_region }}
args:
tags:
"version:edx_platform" : "{{ edx_platform_repo }} {{ edxapp_platform_checkout.after|truncate(7,True,'') }}"
when: edxapp_platform_checkout.after is defined
- name: tag instance with edxapp theme version
ec2_tag: resource={{ ansible_ec2_instance_id }} region={{ ansible_ec2_placement_region }}
args:
tags:
"version:edxapp_theme" : "{{ edxapp_theme_source_repo }} {{ edxapp_theme_checkout.after|truncate(7,True,'') }}"
when: edxapp_theme_checkout.after is defined
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
dest={{ forum_code_dir }} repo={{ forum_source_repo }} version={{ forum_version }} dest={{ forum_code_dir }} repo={{ forum_source_repo }} version={{ forum_version }}
accept_hostkey=yes accept_hostkey=yes
sudo_user: "{{ forum_user }}" sudo_user: "{{ forum_user }}"
register: forum_checkout
notify: restart the forum service notify: restart the forum service
# TODO: This is done as the common_web_user # TODO: This is done as the common_web_user
...@@ -66,4 +67,7 @@ ...@@ -66,4 +67,7 @@
- include: test.yml tags=deploy - include: test.yml tags=deploy
- include: ec2.yml tags=deploy
when: COMMON_TAG_EC2_INSTANCE
- set_fact: forum_installed=true - set_fact: forum_installed=true
---
- name: get instance information
action: ec2_facts
- name: tag instance
ec2_tag: resource={{ ansible_ec2_instance_id }} region={{ ansible_ec2_placement_region }}
args:
tags:
"version:forum" : "{{ forum_source_repo }} {{ forum_checkout.after|truncate(7,True,'') }}"
when: forum_checkout.after is defined
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
dest={{ xqueue_code_dir }} repo={{ xqueue_source_repo }} version={{ xqueue_version }} dest={{ xqueue_code_dir }} repo={{ xqueue_source_repo }} version={{ xqueue_version }}
accept_hostkey=yes accept_hostkey=yes
sudo_user: "{{ xqueue_user }}" sudo_user: "{{ xqueue_user }}"
register: xqueue_checkout
notify: notify:
- restart xqueue - restart xqueue
...@@ -114,4 +115,7 @@ ...@@ -114,4 +115,7 @@
- python - python
- pip - pip
- include: ec2.yml tags=deploy
when: COMMON_TAG_EC2_INSTANCE
- set_fact: xqueue_installed=true - set_fact: xqueue_installed=true
---
- name: get instance information
action: ec2_facts
- name: tag instance
ec2_tag: resource={{ ansible_ec2_instance_id }} region={{ ansible_ec2_placement_region }}
args:
tags:
"version:xqueue" : "{{ xqueue_source_repo }} {{ xqueue_checkout.after|truncate(7,True,'') }}"
when: xqueue_checkout.after is defined
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
dest={{ xqwatcher_code_dir }} repo={{ xqwatcher_source_repo }} version={{ XQWATCHER_VERSION }} dest={{ xqwatcher_code_dir }} repo={{ xqwatcher_source_repo }} version={{ XQWATCHER_VERSION }}
accept_hostkey=yes accept_hostkey=yes
ssh_opts="{{ xqwatcher_git_ssh_opts }}" ssh_opts="{{ xqwatcher_git_ssh_opts }}"
register: xqwatcher_checkout
- name: install application requirements - name: install application requirements
pip: > pip: >
...@@ -39,4 +40,7 @@ ...@@ -39,4 +40,7 @@
- name: update supervisor configuration - name: update supervisor configuration
shell: "{{ xqwatcher_supervisor_ctl }} -c {{ xqwatcher_supervisor_app_dir }}/supervisord.conf update" shell: "{{ xqwatcher_supervisor_ctl }} -c {{ xqwatcher_supervisor_app_dir }}/supervisord.conf update"
when: not disable_edx_services when: not disable_edx_services
notify: restart xqwatcher notify: restart xqwatcher
\ No newline at end of file
- include: ec2.yml tags=deploy
when: COMMON_TAG_EC2_INSTANCE
---
- name: get instance information
action: ec2_facts
- name: tag instance
ec2_tag: resource={{ ansible_ec2_instance_id }} region={{ ansible_ec2_placement_region }}
args:
tags:
"version:xqwatcher" : "{{ xqwatcher_source_repo }} {{ xqwatcher_checkout.after|truncate(7,True,'') }}"
when: xqwatcher_checkout.after is defined
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
dest={{xserver_code_dir}} repo={{xserver_source_repo}} version={{xserver_version}} dest={{xserver_code_dir}} repo={{xserver_source_repo}} version={{xserver_version}}
accept_hostkey=yes accept_hostkey=yes
sudo_user: "{{ xserver_user }}" sudo_user: "{{ xserver_user }}"
register: xserver_checkout
notify: restart xserver notify: restart xserver
- name: install requirements - name: install requirements
...@@ -56,6 +57,7 @@ ...@@ -56,6 +57,7 @@
environment: environment:
GIT_SSH: /tmp/git_ssh.sh GIT_SSH: /tmp/git_ssh.sh
notify: restart xserver notify: restart xserver
register: xserver_grader_checkout
sudo_user: "{{ xserver_user }}" sudo_user: "{{ xserver_user }}"
- name: remove read-only ssh key for the content repo - name: remove read-only ssh key for the content repo
...@@ -92,3 +94,6 @@ ...@@ -92,3 +94,6 @@
- name: enforce app-armor rules - name: enforce app-armor rules
command: aa-enforce {{ xserver_venv_sandbox_dir }} command: aa-enforce {{ xserver_venv_sandbox_dir }}
- include: ec2.yml tags=deploy
when: COMMON_TAG_EC2_INSTANCE
---
- name: get instance information
action: ec2_facts
- name: tag instance for xserver
ec2_tag: resource={{ ansible_ec2_instance_id }} region={{ ansible_ec2_placement_region }}
args:
tags:
"version:xserver" : "{{ xserver_source_repo }} {{ xserver_checkout.after|truncate(7,True,'') }}"
when: xserver_checkout.after is defined
- name: tag instance for xserver grader
ec2_tag: resource={{ ansible_ec2_instance_id }} region={{ ansible_ec2_placement_region }}
args:
tags:
"version:xserver_grader" : "{{ XSERVER_GRADER_SOURCE }} {{ xserver_grader_checkout.after|truncate(7,True,'') }}"
when: xserver_grader_checkout.after is defined
...@@ -29,11 +29,6 @@ if [[ -z "$BUILD_NUMBER" ]]; then ...@@ -29,11 +29,6 @@ if [[ -z "$BUILD_NUMBER" ]]; then
exit -1 exit -1
fi fi
if [[ -z "$refs" ]]; then
echo "refs not specified."
exit -1
fi
if [[ -z "$deployment" ]]; then if [[ -z "$deployment" ]]; then
echo "deployment not specified." echo "deployment not specified."
exit -1 exit -1
...@@ -65,6 +60,10 @@ cd $WORKSPACE/configuration ...@@ -65,6 +60,10 @@ cd $WORKSPACE/configuration
configuration=`git rev-parse --short HEAD` configuration=`git rev-parse --short HEAD`
cd $WORKSPACE cd $WORKSPACE
cd $WORKSPACE/configuration-secure
configuration_secure=`git rev-parse --short HEAD`
cd $WORKSPACE
base_params="" base_params=""
if [[ -n "$base_ami" ]]; then if [[ -n "$base_ami" ]]; then
base_params="-b $base_ami" base_params="-b $base_ami"
...@@ -103,10 +102,7 @@ pip install -r requirements.txt ...@@ -103,10 +102,7 @@ pip install -r requirements.txt
cd util/vpc-tools/ cd util/vpc-tools/
echo "$refs" > /var/tmp/$BUILD_ID-refs.yml
cat /var/tmp/$BUILD_ID-refs.yml
echo "$vars" > /var/tmp/$BUILD_ID-extra-vars.yml echo "$vars" > /var/tmp/$BUILD_ID-extra-vars.yml
cat /var/tmp/$BUILD_ID-extra-vars.yml cat /var/tmp/$BUILD_ID-extra-vars.yml
python -u abbey.py -p $play -t c3.large -d $deployment -e $environment -i /edx/var/jenkins/.ssh/id_rsa $base_params $blessed_params $playbookdir_params --vars /var/tmp/$BUILD_ID-extra-vars.yml --refs /var/tmp/$BUILD_ID-refs.yml -c $BUILD_NUMBER --configuration-version $configuration --configuration-secure-version $configuration_secure -k $jenkins_admin_ec2_key --configuration-secure-repo $jenkins_admin_configuration_secure_repo $configurationprivate_params $hipchat_params $cleanup_params python -u abbey.py -p $play -t c3.large -d $deployment -e $environment -i /edx/var/jenkins/.ssh/id_rsa $base_params $blessed_params $playbookdir_params --vars /var/tmp/$BUILD_ID-extra-vars.yml -c $BUILD_NUMBER --configuration-version $configuration --configuration-secure-version $configuration_secure -k $jenkins_admin_ec2_key --configuration-secure-repo $jenkins_admin_configuration_secure_repo $configurationprivate_params $hipchat_params $cleanup_params
...@@ -524,18 +524,20 @@ def create_ami(instance_id, name, description): ...@@ -524,18 +524,20 @@ def create_ami(instance_id, name, description):
time.sleep(AWS_API_WAIT_TIME) time.sleep(AWS_API_WAIT_TIME)
img.add_tag("play", args.play) img.add_tag("play", args.play)
time.sleep(AWS_API_WAIT_TIME) time.sleep(AWS_API_WAIT_TIME)
img.add_tag("configuration_ref", args.configuration_version) conf_tag = "{} {}".format("http://github.com/edx/configuration", args.configuration_version)
img.add_tag("version: configuration", conf_tag)
time.sleep(AWS_API_WAIT_TIME) time.sleep(AWS_API_WAIT_TIME)
img.add_tag("configuration_secure_ref", args.configuration_secure_version) conf_secure_tag = "{} {}".format(args.configuration_secure_repo, args.configuration_secure_version)
time.sleep(AWS_API_WAIT_TIME) img.add_tag("version: configuration_secure", conf_secure_tag)
img.add_tag("configuration_secure_repo", args.configuration_secure_repo)
time.sleep(AWS_API_WAIT_TIME) time.sleep(AWS_API_WAIT_TIME)
img.add_tag("cache_id", args.cache_id) img.add_tag("cache_id", args.cache_id)
time.sleep(AWS_API_WAIT_TIME) time.sleep(AWS_API_WAIT_TIME)
for name,value in extra_vars.items():
if name.endswith('_version'): # Get versions from the instance.
key = "vars:{}".format(repo) tags = ec2.get_all_tags(filters={'resource-id': instance_id})
img.add_tag(key, value) for tag in tags:
if tag.name.startswith('version:'):
img.add_tag(tag.name, tag.value)
time.sleep(AWS_API_WAIT_TIME) time.sleep(AWS_API_WAIT_TIME)
break break
else: else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment