Skip to content

Commit

Permalink
✨(route:switch) move current route to the next stack
Browse files Browse the repository at this point in the history
We confirm a deployment by triggering a route switch:
1. point the previous route to the current stack
2. point the current route to the next stack
3. point the next route to the default stack (init) who don't exist
4. delete the previous stack
  • Loading branch information
cchaudier committed Jul 11, 2018
1 parent 6d5090b commit 44104fe
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 22 deletions.
7 changes: 7 additions & 0 deletions bin/switch
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

# shellcheck source=bin/_config.sh
source "$(dirname "${BASH_SOURCE[0]}")/_config.sh"

# Run ansible-playbook
_docker_run ansible-playbook switch.yml "$@"
21 changes: 21 additions & 0 deletions docs/developer_guide/playbooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,27 @@ $ docker run --rm -it \
ansible-playbook deploy.yml -e "customer=patient0 env_type=staging"
```

## `switch.yml`

The `switch.yml` playbook move the current stack to the previous route
and move the next stack to the current route.

### Usage

```bash
# sugar development
$ bin/switch -e "customer=patient0 env_type=staging"

# development
$ bin/ansible-playbook switch.yml -e "customer=patient0 env_type=staging"

# native command for production
$ docker run --rm -it \
--env-file env.d/production \
arnold \
ansible-playbook switch.yml -e "customer=patient0 env_type=staging"
```

## `create_project.yml`

This playbook only creates a new OpenShift project name defined with the
Expand Down
22 changes: 22 additions & 0 deletions switch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
# This playbook switch all routes:
# 1. point the "current" route to the stack that was pointed by the "next" route,
# 2. point the "previous" route to the stack that was pointed by the "current" route just before we changed it in 1)
# 3. delete the stack that was pointed by the "previous" route just before we changed it in 2)
# 4. patch the next route to the init stamp

- hosts: local
gather_facts: False

tasks:

- import_tasks: tasks/set_vars.yml

# Patch all apps dest routes with src stack
- include_tasks: tasks/run_tasks_for_apps.yml
vars:
tasks:
- switch_routes
tags:
- route
- switch
1 change: 0 additions & 1 deletion tasks/create_route_aliases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
vars:
routes_aliases: []


- name: Make sure all redirected routes exist or force recreation
openshift_raw:
force: true
Expand Down
6 changes: 1 addition & 5 deletions tasks/create_static_services_routes.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
---
# Create static routes for services of an app

- name: Print app name
debug: msg="App name {{ app.name }}"
tags: route

- name: Make sure static route exists
- name: Make sure static route exists for app[{{ app.name }}]
openshift_raw:
force: true
definition: "{{ lookup('template', 'apps/_common/templates/route/main.yml.j2') | from_yaml }}"
Expand Down
3 changes: 2 additions & 1 deletion tasks/delete_app.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
# Delete objects of the last deployment_stamp
# Delete objects of the last deployment_stamp

- include_tasks: deploy_apps.yml
vars:
deployment_state: "absent"
Expand Down
3 changes: 0 additions & 3 deletions tasks/deploy_apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
# - 'absent': all objects are deleted
# deployment_stamp : the stamp of the object we going to creat or delete

- name: Print desired state
debug: msg="OpenShift objects with deployment_stamp={{ deployment_stamp }} must be {{ deployment_state | default('present') }}"

- name: "OpenShift objects with deployment_stamp[{{ deployment_stamp }}] must be {{ deployment_state | default('present') }}"
openshift_raw:
definition: "{{ lookup('template', 'templates/' + item + '.j2') | from_yaml }}"
Expand Down
12 changes: 4 additions & 8 deletions tasks/deploy_get_stamp_from_route.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
---
# Get deployment_stamp from a route

- name: Print get details
debug: msg="[{{ app.name }}] route.name[{{ app.name }}-{{ prefixe }}] "

- name: Get deployment_stamp of route
- name: Get deployment_stamp of route[{{ app.name }}-{{ prefixe }}]
openshift_raw:
definition: "{{ lookup('template', 'templates/openshift/common/utils/get_deployment_stamp_form_route.yml.j2') | from_yaml }}"
register: my_route

- name: set_fact deployment_stamp to delete
- name: set_fact route_deployment_stamp
set_fact:
route_deployment_stamp: "{{ my_route.result.metadata.labels.deployment_stamp }}"
# cacheable: true

- name: Print old route_deployment_stamp
debug: msg="[{{ app.name }}] route_deployment_stamp [{{ route_deployment_stamp }}]"
- name: Print route_deployment_stamp
debug: msg="[{{ app.name }}] route[{{ app.name }}-{{ prefixe }}] route_deployment_stamp[{{ route_deployment_stamp }}]"
5 changes: 1 addition & 4 deletions tasks/deploy_patch_route.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
---
# Patch routes of all services of one app to the new deployment_stamp

- name: Print patch details
debug: msg="[{{ app.name }}] Patch route[{{ app.name }}-{{ prefixe }}] with deployment_stamp[{{ deployment_stamp }}]"

- name: Patch sure static route exists for all services
- name: "[{{ app.name }}] Patch route[{{ app.name }}-{{ prefixe }}] with deployment_stamp[{{ deployment_stamp }}]"
openshift_raw:
force: true
definition: "{{ lookup('template', 'templates/openshift/common/route/main.yml.j2') | from_yaml }}"
Expand Down
22 changes: 22 additions & 0 deletions tasks/switch_route.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
# Patch all apps dest routes with src stack

- name: Print switch details
debug: msg="[{{ app.name }}] Switch routes from {{ prefixe_route_src }} to {{ prefixe_route_dest }}"
tags: switch

- include_tasks: deploy_get_stamp_from_route.yml
vars:
prefixe: "{{ prefixe_route_src }}"
tags: switch

- include_tasks: deploy_patch_route.yml
vars:
prefixe: "{{ prefixe_route_dest }}"
deployment_stamp: "{{ route_deployment_stamp }}"
tags: switch

- include_tasks: deploy_patch_route.yml
vars:
prefixe: "{{ prefixe_route_src }}"
tags: switch
29 changes: 29 additions & 0 deletions tasks/switch_routes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
# Patch app dest routes with src stack

- include_tasks: deploy_get_stamp_from_route.yml
vars:
prefixe: "previous"
tags: switch

- name: save previous_route_deployment_stamp
set_fact:
previous_route_deployment_stamp: "{{ route_deployment_stamp }}"

- include_tasks: switch_route.yml
vars:
prefixe_route_src: "{{ prefixe_route.src }}"
prefixe_route_dest: "{{ prefixe_route.dest }}"
tasks:
- switch_routes
with_items:
- src: current
dest: previous
- src: next
dest: current
loop_control:
loop_var: prefixe_route

- include_tasks: delete_app.yml
vars:
route_deployment_stamp: "{{ previous_route_deployment_stamp }}"

0 comments on commit 44104fe

Please sign in to comment.