<commit_before>SSH_OPTS=-o PreferredAuthentications="password" -t
## 
## 
##****************        LS.ext DEVOPS Makefile      ************************
## 

SALT_VERSION=v2014.7.0

help:                  ## Show this help.
	@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'

## 
## 
##*******                      DEPLOYING                         *************

## 
##------- DEV - tasks:                                           -------------

ifdef LSDEVMODE
SHIP=$(LSDEVMODE)-ship
else
SHIP=vm-ship
endif

dev_highstate:         ## Deploy current to your own local environment (vm-devops / vm-ship)
	vagrant ssh vm-devops -c 'echo " ================ deploying =====================" >> deploy.log && sudo salt "*" state.highstate pillar="{'GITREF': 'latest'}" 2>&1 | sudo tee -a deploy.log'

dev_highstate_dry_run:         ## Dry run deployment to your own local environment (vm-devops / $(SHIP))
	vagrant ssh vm-devops -c 'sudo salt "*" state.highstate pillar="{'GITREF': 'latest'}" test=True'

##
##------- PROD - tasks:                                          -------------

prod_highstate:        ## Deploy specified version to production - args: SUDOUSER, MASTER, GITREF
	ssh $(SSH_OPTS) $(SUDOUSER)@$(MASTER) "sudo sh -c 'cd /var/lib/salt-master && git checkout master && git pull && git checkout $(GITREF) 2>&1 | tee -a deploy.log && echo \"======================== $(SUDOUSER) : deploying ref $(GITREF)\" | tee -a deploy.log && date | tee -a deploy.log && salt -t 30 \"*\" --log-level info --log-file-level=debug state.highstate pillar="{'GITREF': '$(GITREF)'}" 2>&1 | tee -a deploy.log'"


prod_revision:         ## Shows the currently checked out revision on MASTER - args: SUDOUSER, MASTER
	ssh $(SSH_OPTS) $(SUDOUSER)@$(MASTER) 'cd /var/lib/salt-master && sudo git rev-parse HEAD'

prod_highstate_dry_run:        ## Dry run deployment of specified version to production - args: SUDOUSER, MASTER, GITREF
	ssh $(SSH_OPTS) $(SUDOUSER)@$(MASTER) "sudo sh -c 'cd /var/lib/salt-master && git checkout master && git pull && git checkout $(GITREF) && salt \"*\" --log-level info --log-file-level=debug state.highstate pillar="{'GITREF': '$(GITREF)'}" test=True'"



##
##
##*******                     EXAMPLE DATA                       *************

##
##------- DEV - tasks:                                           -------------

dev_reset_db: ## Delete content from all relevant tables in koha
	vagrant ssh vm-devops -c 'sudo salt "$(SHIP)" --log-level info state.sls migration.reset pillar="{migration-data-folder: /var/migration_workdir}"'

dev_reset: dev_reset_db dev_reindex_koha

dev_clean_data: ## Delete previously extracted files and temporary files from workdir
	vagrant ssh vm-devops -c 'sudo salt "$(SHIP)" --log-level info state.sls migration.data_cleaned pillar="{migration-data-folder: /var/migration_workdir}"'

dev_extract_example_data_full: dev_clean_data ## After cleaning previous files, downloads complete set of example data from wombat - args: WOMBATUSER
	vagrant ssh $(SHIP) -c 'mkdir -p /var/migration_workdir'
	vagrant ssh $(SHIP) -c 'sudo scp $(WOMBATUSER)@10.172.2.160:/data/example_data_full/* /var/migration_workdir'

dev_extract_example_data_minimum: dev_clean_data ## After cleaning previous files, downloads complete set of example data from migration image
	vagrant ssh $(SHIP) -c 'sudo mkdir -p /var/migration_workdir/'
	vagrant ssh vm-devops -c 'sudo salt "$(SHIP)" --log-level info state.sls migration.copy_example_data pillar="{migration-data-folder: /var/migration_workdir}"'

dev_load_example_data:<commit_msg>Escape args in deploy task.<commit_after>SSH_OPTS=-o PreferredAuthentications="password" -t
## 
## 
##****************        LS.ext DEVOPS Makefile      ************************
## 

SALT_VERSION=v2014.7.0

help:                  ## Show this help.
	@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'

## 
## 
##*******                      DEPLOYING                         *************

## 
##------- DEV - tasks:                                           -------------

ifdef LSDEVMODE
SHIP=$(LSDEVMODE)-ship
else
SHIP=vm-ship
endif

dev_highstate:         ## Deploy current to your own local environment (vm-devops / vm-ship)
	vagrant ssh vm-devops -c 'echo " ================ deploying =====================" >> deploy.log && sudo salt "*" state.highstate pillar="{'GITREF': 'latest'}" 2>&1 | sudo tee -a deploy.log'

dev_highstate_dry_run:         ## Dry run deployment to your own local environment (vm-devops / $(SHIP))
	vagrant ssh vm-devops -c 'sudo salt "*" state.highstate pillar="{'GITREF': 'latest'}" test=True'

##
##------- PROD - tasks:                                          -------------

prod_highstate:        ## Deploy specified version to production - args: SUDOUSER, MASTER, GITREF
	ssh $(SSH_OPTS) $(SUDOUSER)@$(MASTER) "sudo sh -c 'cd /var/lib/salt-master && git checkout master && git pull && git checkout $(GITREF) 2>&1 | tee -a deploy.log && echo \"======================== $(SUDOUSER) : deploying ref $(GITREF)\" | tee -a deploy.log && date | tee -a deploy.log && salt -t 30 \"*\" --log-level info --log-file-level=debug state.highstate pillar=\"{\"GITREF\": \"$(GITREF)\"}\" 2>&1 | tee -a deploy.log'"


prod_revision:         ## Shows the currently checked out revision on MASTER - args: SUDOUSER, MASTER
	ssh $(SSH_OPTS) $(SUDOUSER)@$(MASTER) 'cd /var/lib/salt-master && sudo git rev-parse HEAD'

prod_highstate_dry_run:        ## Dry run deployment of specified version to production - args: SUDOUSER, MASTER, GITREF
	ssh $(SSH_OPTS) $(SUDOUSER)@$(MASTER) "sudo sh -c 'cd /var/lib/salt-master && git checkout master && git pull && git checkout $(GITREF) && salt \"*\" --log-level info --log-file-level=debug state.highstate pillar=\"{\"GITREF\": \"$(GITREF)\"}\" test=True'"



##
##
##*******                     EXAMPLE DATA                       *************

##
##------- DEV - tasks:                                           -------------

dev_reset_db: ## Delete content from all relevant tables in koha
	vagrant ssh vm-devops -c 'sudo salt "$(SHIP)" --log-level info state.sls migration.reset pillar="{migration-data-folder: /var/migration_workdir}"'

dev_reset: dev_reset_db dev_reindex_koha

dev_clean_data: ## Delete previously extracted files and temporary files from workdir
	vagrant ssh vm-devops -c 'sudo salt "$(SHIP)" --log-level info state.sls migration.data_cleaned pillar="{migration-data-folder: /var/migration_workdir}"'

dev_extract_example_data_full: dev_clean_data ## After cleaning previous files, downloads complete set of example data from wombat - args: WOMBATUSER
	vagrant ssh $(SHIP) -c 'mkdir -p /var/migration_workdir'
	vagrant ssh $(SHIP) -c 'sudo scp $(WOMBATUSER)@10.172.2.160:/data/example_data_full/* /var/migration_workdir'

dev_extract_example_data_minimum: dev_clean_data ## After cleaning previous files, downloads complete set of example data from migration image
	vagrant ssh $(SHIP) -c 'sudo mkdir -p /var/migration_workdir/'
	vagrant ssh vm-devops -c 'sudo salt "$(SHIP)" --log-level info state.sls migration.copy_example_data pillar="{migration-data-folder: /var/migration_workdir}"'

dev_load_example_data:
{'fraction_non_alphanumeric': 0.18874446902654868, 'fraction_numerical': 0.006360619469026549, 'mean_word_length': 2.9654605263157894, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '89654', 'n_tokens_mistral': 2440, 'n_tokens_neox': 2265, 'n_words': 633}