Feature: Upgrade script (#73)

* feat(upgrade): upgrading dbs

* feat(installation): migration script

* fix(upgrdae): proper db version

Signed-off-by: Rajesh Rajendran <rjshrjndrn@gmail.com>

* chore(upgrade): update install.sh

Signed-off-by: Rajesh Rajendran <rjshrjndrn@gmail.com>
This commit is contained in:
Rajesh Rajendran 2021-07-04 10:52:27 +00:00 committed by GitHub
parent 249afe1fd6
commit 5ad8200f86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 174 additions and 0 deletions

View file

@ -0,0 +1,46 @@
---
- hosts: localhost
environment:
KUBECONFIG: "{{ kubeconfig_path }}"
tasks:
- debug:
var: migration_versions
- block:
- name: generating migration db paths
set_fact:
db_path: "{{dst_list | default([])}} + [ '{{ item[0] }}/*.sql' ]"
with_items: "{{ migration_versions.split(',') }}"
- name: Migrate postgresql
shell: |
file="{{ item|basename }}"
kubectl exec -n db postgresql-postgresql-0 -- /bin/bash -c "rm -rf /tmp/$file"
kubectl cp -n db $file postgresql-postgresql-0:/tmp/
kubectl exec -n db postgresql-postgresql-0 -- /bin/bash -c "PGPASSWORD=asayerPostgres psql -U postgres -f /tmp/$file" &> "{{ playbook_dir }}"/postgresql_init.log
args:
chdir: db/init_dbs/postgresql
with_fileglob:
- "{{ db_path }}"
tags:
- postgresql
- block:
- name: generating migration db paths
set_fact:
db_path: "{{dst_list | default([])}} + [ '{{ item[0] }}/*.sql' ]"
with_items: "{{ migration_versions.split(',') }}"
- name: Restoring clickhouse data
shell: |
file="{{ item|basename }}"
kubectl exec -n db clickhouse-0 -- /bin/bash -c "rm -rf /tmp/$file"
kubectl cp -n db $file clickhouse-0:/tmp/
kubectl exec -n db clickhouse-0 -- /bin/bash -c "clickhouse-client < /tmp/$file" 2>&1 | tee -a "{{ playbook_dir }}"/clickhouse_init.log
args:
chdir: db/init_dbs/clickhouse/create
with_fileglob:
- "{{ db_path }}"
retries: 3
delay: 60
register: result
until: result.rc == 0
tags:
- clickhouse
when: enterprise_edition_license|length > 0

View file

@ -29,6 +29,7 @@
- templates/*.yaml
tags:
- app
- template
# Installing and initializing dbs
- import_tasks: install-dbs.yaml

52
scripts/helm/upgrade.sh Normal file
View file

@ -0,0 +1,52 @@
#!/bin/bash
# upgrade.sh v1.10
cwd=$PWD
vars_file_path=$1/scripts/helm/vars.yaml
[[ $# == 1 ]] || {
echo -e "OpenReplay previous version path not given.\nUsage: bash $0 /path/to/previous_openreplay_code_path"
exit 1
}
[[ -f $1 ]] || {
echo -e "$1 doesn't exist. Please check the path and run\n \`bash upgrade.sh </path/to/previous/vars.yaml> \`"
}
which ansible &> /dev/null || {
echo "ansible not found. Are you sure, this is the same machine in which openreplay installed ?"
exit 100;
}
echo -e"Updating vars.yaml\n"
{
ansible localhost -m template -a "src=vars_template.yaml dest=vars.yaml" -e @${vars_file_path}
ansible localhost -m debug -a "var=openreplay_version" -e @${vars_file_path}
} || {
echo -e "variable file update failed. Update the value from old $vars_file_path to ./vars.yaml by hand"
}
old_version=`grep openreplay_version ${vars_file_path} | cut -d "v" -f 3 | cut -d '"' -f 1`
enterprise_edition=`grep enterprise_edition_license ${vars_file_path} | cut -d ":" -f 2 | xargs`
migration(){
# Ref: https://stackoverflow.com/questions/1527049/how-can-i-join-elements-of-an-array-in-bash
# Creating an array of versions to migrate.
db=$1
migration_versions=(`ls -l db/init_dbs/$db | grep -E ^d | awk -v number=${old_version} '$NF > number {print $NF}'`)
# Can't pass the space seperated array to ansible for migration. So joining them with ,
joined_migration_versions=$(IFS=, ; echo "${migration_versions[*]}")
[[ $joined_migration_versions == "" ]] ||
{
echo -e "Starting db migrations"
echo -e "Migrating versions $migration_versions"
ansible-playbook -c local migration.yaml -e vars.yaml -e migration_versions=${joined_migration_versions} --tags $db
}
}
# As of now, we don't have any migrations to do, as there is no delta files,
# We'll have to do full installation.
#
# echo -e "Migrating postgresql"
# migration postgresql
# Re installing everything.
./install.sh

View file

@ -25,6 +25,7 @@ docker_registry_username: ""
docker_registry_password: ""
docker_registry_url: "rg.fr-par.scw.cloud/foss"
image_tag: "v1.1.0"
openreplay_version: "v1.1.0"
# Nginx ssl certificates.
# in cert format

View file

@ -0,0 +1,74 @@
###################
## Mandatory Fields.
###################
# Give the path of the kubeconfig_path: /home/user/.kube/config
# we can access the kubernetes cluster.
# Give absolute file path.
# Use following command to get the full file path
# `readlink -f <file>`
kubeconfig_path: "{{ kubeconfig_path }}"
# Using which domain name, you'll be accessing OpenReplay
# for example: domain_name: "openreplay.mycompany.com"
#
# Without domain name session replay is not possible, because we've to
# create signed url for s3 objects.
domain_name: "{{ domain_name }}"
###################
## Optional Fields.
###################
# If you've private registry, please update the details here.
docker_registry_username: "{{ docker_registry_username }}"
docker_registry_password: "{{ docker_registry_password }}"
docker_registry_url: "{{ docker_registry_url }}"
image_tag: "v1.1.0"
openreplay_version: "v1.1.0"
# Nginx ssl certificates.
# in cert format
# Give absolute file path.
# Use following command to get the full file path
# `readlink -f <file>`
# For example:
# nginx_ssl_cert_file_path: "/home/openreplay/nginx-cert.crt"
# nginx_ssl_key_file_path: "/home/openreplay/nginx-key.pem"
#
# By Default, we'll create a self signed certificate for nginx, and populate the values here.
# Once you've proper domain name, and ssl certificate
# Change the following variables accordingly.
nginx_ssl_cert_file_path: "{{ nginx_ssl_cert_file_path }}"
nginx_ssl_key_file_path: "{{ nginx_ssl_key_file_path }}"
# This key is used to create password for chalice api requests.
# Create a strong password.
# By default, a default key will be generated and will update the value here.
jwt_secret_key: "{{ jwt_secret_key }}"
# Random password for minio,
# If not defined, will generate at runtime.
# Use following command to generate password
# `openssl rand -base64 30`
minio_access_key: "{{ minio_access_key }}"
minio_secret_key: "{{ minio_secret_key }}"
# If you're using enterprise edition.
# Insert the enterprise_edition_License key which you got.
enterprise_edition_license: "{{ enterprise_edition_license }}"
# Enable monitoring
# If set, monitoring stack will be installed
# including, prometheus, grafana and other core components,
# to scrape the metrics. But this will cost, additional resources (cpu and memory).
# Monitoring won't be installed on base installation.
enable_monitoring: "{{ enable_monitoring }}"
# Password for grafana.
# If password is not given, it'll be generated, and updated here.
#
# Use following command to generate password
# `openssl rand -base64 30`
#
# Username: admin
grafana_password: "{{ grafana_password }}"