prima-twig 0.37.3 → 0.37.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/twig-feature +270 -75
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 366efc6db82dd87c1778461e3990f2c0dce3205f
4
- data.tar.gz: a3069bf1637c421542730b9a97dd1e14e9b4653f
3
+ metadata.gz: 5746a4b38b1f8e9b72b326f377a22ccff89122b7
4
+ data.tar.gz: 1797fb79ca46301e7efb7909691d36ee54a73b4e
5
5
  SHA512:
6
- metadata.gz: 45d5f722453436ea1df7835bdf98940fe1277ea5067ac94181663597bd2669acd35af748a11531b3116c89b2cd29052f1d20c922ea2865eca5577302878cc261
7
- data.tar.gz: 718fe1dfd51274e1a2fc9866cbbb6a945b80c59e089623acacf273fb88ce510d06c8f4b6518a176958b198edde3b48af1ac21620bbeee2039b284b433314107c
6
+ metadata.gz: d5918ee3803d38ab7f2003b069ae2c56e3fdc62eee800b500be919b5de1dfa21753f5877272fd8aa9a063ec095753d6b75301c82e5fa148ea00ecd265210b0db
7
+ data.tar.gz: 5628fefdf74361a27639b8f003bfb1454346a46a471ad8d152535f663303e0e015093b21bc22a6c2a08ab0bc746f88655e7f325c57d218e219c51e80c9788a4a
@@ -67,8 +67,8 @@ class Release
67
67
  qainit_deploy_update!
68
68
  elsif 'read' == args[1]
69
69
  qainit_read_config! args[2]
70
- # elsif 'minimal' == args[1]
71
- # qainit_minimal_deploy! args[2]
70
+ elsif 'minimal' == args[1]
71
+ qainit_minimal_deploy! args[2]
72
72
  else
73
73
  if args[1]
74
74
  select_branches(args[1])
@@ -462,7 +462,7 @@ class Release
462
462
 
463
463
  def qainit_minimal_deploy!(project)
464
464
  abort('Gli unici progetti permessi sono prima e crash') unless ['prima', 'crash'].include? project
465
- project = choose_branch_to_deploy(project)
465
+ project_definition = choose_branch_to_deploy(project)
466
466
 
467
467
  `git checkout master && git pull && git remote prune origin`
468
468
  output "Inserisci la feature a cui si riferisce il QA: [#{default_name}]".cyan
@@ -476,25 +476,22 @@ class Release
476
476
  end
477
477
 
478
478
  # così recupero le informazioni sul branch, poi vado a scrivere il file branch_names con una sola riga
479
- branch = ''
480
-
481
- project.each_key do |project_key|
482
- branch += "#{project_key}:#{project[project_key][:name]}:#{project[project_key][:revision]}:#{project[project_key][:default_branch]}"
483
- end
479
+ branch = "#{project}:#{project_definition[:name]}:#{project_definition[:revision]}:#{project_definition[:default_branch]}"
484
480
 
485
481
  File.open('branch_names', 'w') { |file| file.write(branch) }
486
482
 
487
483
  `git add projects && \
488
484
  git add branch_names && \
489
- git commit -m '#{feature_number}' && \
485
+ git commit -m 'minimal_#{feature_number}' && \
490
486
  git push --set-upstream origin #{feature_number} && \
491
487
  git checkout master`
492
488
  end
493
489
 
494
490
  def qainit_deploy_update!
495
491
  `git checkout master && git pull`
492
+ # cancelliamo tutti i branch che non sono più sul repo remoto
496
493
  `git fetch -p && for branch in \`git branch -vv | grep ': gone]' | awk '{print $1}'\`; do git branch -D $branch; done`
497
- # leggiamo i nomi dei branch
494
+ # leggiamo i nomi dei branch superstiti
498
495
  former_branches = `git branch -a | grep remotes/ | grep -v HEAD | sed 's/ remotes\\/origin\\///g'`.split "\n"
499
496
  # stampiamo la lista
500
497
  chosen_branch = choose do |menu|
@@ -601,13 +598,17 @@ class Release
601
598
  output "Finito!".green
602
599
 
603
600
  if @qainit
604
- `mkdir /drone/src/github.com/project/primait/qainit/#{ENV["DRONE_BRANCH"]}`
605
- qa_file_name = "/drone/src/github.com/project/primait/qainit/#{ENV["DRONE_BRANCH"]}/output"
606
- File.open(qa_file_name, 'w') { |file| file.write("QA #{ENV["DRONE_BRANCH"]} spento.") }
607
- output "Indirizzi scritti su #{qa_file_name}".green
601
+ qainit_write_output("QA #{ENV["DRONE_BRANCH"]} spento.", 'Indirizzi scritti su ')
608
602
  end
609
603
  end
610
604
 
605
+ def qainit_write_output(file_message, output_message)
606
+ `mkdir -p /drone/src/github.com/project/primait/qainit/#{ENV["DRONE_BRANCH"]}`
607
+ qa_file_name = "/drone/src/github.com/project/primait/qainit/#{ENV["DRONE_BRANCH"]}/output"
608
+ File.open(qa_file_name, 'w') { |file| file.write(file_message) }
609
+ output "#{output_message} #{qa_file_name}".green
610
+ end
611
+
611
612
  def qainit_read_config!(action)
612
613
  File.open('branch_names', 'r') do |file|
613
614
  file.each_line do |line|
@@ -621,8 +622,11 @@ class Release
621
622
  end
622
623
  get_s3_config_files
623
624
  @qainit = true
624
- if ('shutdown' == action)
625
+ case action
626
+ when 'shutdown'
625
627
  qainit_drone_shutdown!
628
+ when 'minimal'
629
+ qainit_drone_minimal_deploy!
626
630
  else
627
631
  deploy_feature!
628
632
  end
@@ -639,39 +643,207 @@ class Release
639
643
  end
640
644
 
641
645
  def calculate_deploy_id
642
- if deploy_crash?
643
- Digest::MD5.hexdigest(
644
- @projects["prima"][:name] +
645
- @projects["backoffice"][:name] +
646
- @projects["urania"][:name] +
647
- @projects["ermes"][:name] +
648
- @projects["bburago"][:name] +
649
- @projects["hal9000"][:name] +
650
- @projects["fidaty"][:name] +
651
- @projects["peano"][:name] +
652
- @projects["rogoreport"][:name] +
653
- @projects["assange"][:name] +
654
- @projects["borat"][:name] +
655
- @projects["bolla"][:name] +
656
- @projects['crash'][:name] +
657
- @projects["activia"][:name]
658
- )
659
- else
660
- Digest::MD5.hexdigest(
661
- @projects["prima"][:name] +
662
- @projects["backoffice"][:name] +
663
- @projects["urania"][:name] +
664
- @projects["ermes"][:name] +
665
- @projects["bburago"][:name] +
666
- @projects["hal9000"][:name] +
667
- @projects["fidaty"][:name] +
668
- @projects["peano"][:name] +
669
- @projects["rogoreport"][:name] +
670
- @projects["assange"][:name] +
671
- @projects["borat"][:name] +
672
- @projects["bolla"][:name] +
673
- @projects["activia"][:name]
674
- )
646
+ hashable = ''
647
+ @projects.each_key do |project_key|
648
+ if @projects[project_key][:name]
649
+ hashable += @projects[project_key][:name]
650
+ end
651
+ end
652
+ Digest::MD5.hexdigest(hashable)
653
+ end
654
+
655
+ def qainit_drone_minimal_deploy!
656
+ #check whether it's prima or crash
657
+ project = ''
658
+ @projects.each_key do |project_key|
659
+ if @projects[project_key][:revision]
660
+ project = project_key
661
+ git_checkout_version(project_key, @projects[project_key][:revision])
662
+ end
663
+ end
664
+ deploy_id = calculate_deploy_id
665
+ # servono 3 stack:
666
+ #cluster-qa
667
+ #asg
668
+ #project
669
+ @dns_record_identifier = deploy_id
670
+ hostname_pattern_priority = hostname_pattern_priority()
671
+ tags = [
672
+ {
673
+ key: project,
674
+ value: @projects[project][:name]
675
+ },
676
+ {
677
+ key: "hostname_pattern_priority",
678
+ value: hostname_pattern_priority
679
+ }
680
+ ]
681
+
682
+ cluster_stack_name = "ecs-cluster-qa-#{deploy_id}"
683
+
684
+ if stack_exists?(cluster_stack_name)
685
+ tags = get_stack_tags(cluster_stack_name)
686
+ hostname_pattern_priority = tags.detect do |tag|
687
+ tag.key == 'hostname_pattern_priority'
688
+ end.value
689
+ end
690
+
691
+ create_cluster_stack(cluster_stack_name, tags) unless stack_exists?(cluster_stack_name)
692
+ wait_for_stack_ready(cluster_stack_name) unless stack_ready?(cluster_stack_name)
693
+
694
+ create_alb_stack(@stack_name_alb, "http") unless stack_exists?(@stack_name_alb)
695
+ create_alb_stack(@stack_name_alb_ws, "websocket") unless stack_exists?(@stack_name_alb_ws)
696
+
697
+ resp = @cf.describe_stack_resource({stack_name: cluster_stack_name, logical_resource_id: 'ECSCluster'})
698
+ @ecs_cluster_name = resp.stack_resource_detail.physical_resource_id
699
+
700
+ asg_stack_name = "ecs-asg-allinone-qa-#{deploy_id}"
701
+ create_asg_stack(asg_stack_name, tags) unless stack_exists?(asg_stack_name)
702
+
703
+ case project
704
+ when 'prima'
705
+ create_prima_artifact(@projects["prima"][:revision], @projects["prima"][:name], deploy_id, true) unless artifact_exists?('prima-artifacts-encrypted', "prima/#{@projects["prima"][:revision]}-#{deploy_id}.tar.gz")
706
+ when 'crash'
707
+ create_crash_artifact(@projects['crash'][:revision], deploy_id, true) unless !deploy_crash? || artifact_exists?('prima-artifacts-encrypted', "microservices/crash/#{@projects['crash'][:revision]}-#{deploy_id}-qa.tar.gz")
708
+ end
709
+
710
+ wait_for_stack_ready(@stack_name_alb) unless stack_ready?(@stack_name_alb)
711
+ wait_for_stack_ready(@stack_name_alb_ws) unless stack_ready?(@stack_name_alb_ws)
712
+
713
+ stack_name_route53 = "ecs-route53-qa-#{deploy_id}"
714
+ stack_body = IO.read('cloudformation/stacks/route53/minimal_qa.yml') # creare
715
+ parameters = [
716
+ {
717
+ parameter_key: "DnsRecordIdentifier",
718
+ parameter_value: @dns_record_identifier
719
+ },
720
+ {
721
+ parameter_key: "PrimaElbHostname",
722
+ parameter_value: get_alb_host(@stack_name_alb)
723
+ },
724
+ {
725
+ parameter_key: 'CrashElbHostname',
726
+ parameter_value: get_alb_host(@stack_name_alb_ws)
727
+ }
728
+ ]
729
+
730
+ create_stack(stack_name_route53, stack_body, parameters, tags) unless stack_exists?(stack_name_route53)
731
+ wait_for_stack_ready(stack_name_route53) unless stack_ready?(stack_name_route53)
732
+
733
+ case project
734
+ when 'prima'
735
+ stack_name_web = "ecs-task-web-qa-#{deploy_id}"
736
+ git_checkout_version('prima', @projects["prima"][:revision])
737
+ stack_body = IO.read('projects/prima/app/cloudformation/tasks/web.yml')
738
+ parameters = [
739
+ {
740
+ parameter_key: "Environment",
741
+ parameter_value: "staging"
742
+ },
743
+ {
744
+ parameter_key: "ReleaseVersion",
745
+ parameter_value: "#{@projects["prima"][:revision]}-#{deploy_id}"
746
+ },
747
+ {
748
+ parameter_key: "TaskDesiredCount",
749
+ parameter_value: "1"
750
+ },
751
+ {
752
+ parameter_key: "ECSClusterName",
753
+ parameter_value: @ecs_cluster_name
754
+ },
755
+ {
756
+ parameter_key: "ALBShortName",
757
+ parameter_value: "web-qa-#{deploy_id}"[0..31]
758
+ },
759
+ {
760
+ parameter_key: "WebQaBaseHostname",
761
+ parameter_value: "#{@dns_record_identifier}.qa.colaster.com"
762
+ },
763
+ {
764
+ parameter_key: "HostnamePattern",
765
+ parameter_value: "ww*-#{@dns_record_identifier}.qa.colaster.com"
766
+ },
767
+ {
768
+ parameter_key: "HostnamePatternPriority",
769
+ parameter_value: hostname_pattern_priority
770
+ },
771
+ {
772
+ parameter_key: "HostnamePatternAggregatorPriority",
773
+ parameter_value: (hostname_pattern_priority.to_i + 1).to_s
774
+ }
775
+ ]
776
+ if stack_exists?(stack_name_web)
777
+ cur_version = get_currently_deployed_version(stack_name_web)
778
+ update_stack(stack_name_web, stack_body, parameters, tags) unless cur_version.include?(@projects["prima"][:revision])
779
+ else
780
+ create_stack(stack_name_web, stack_body, parameters, tags)
781
+ end
782
+ wait_for_stack_ready(stack_name_web) unless stack_ready?(stack_name_web)
783
+ update_service_defaults(stack_name_web)
784
+ prima_hostname = get_route53_hostname(stack_name_web)
785
+
786
+ # chefare? col supervisor? non dovrebbe essere un problema, tanto le feature che vengono deployate nei qa minimali
787
+ # dovrebbero essere relative solo al front end.
788
+
789
+ projects_text = "
790
+ > Prima url: https://#{prima_hostname}
791
+ > Prima RI url: https://#{prima_hostname.sub("www", "wwwri")}
792
+ > Supervisor url: http://#{ec2_ip_address(asg_stack_name)}:9001
793
+ > SSH connection: ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no githubUsername@#{ec2_ip_address(asg_stack_name)}\n"
794
+
795
+ when 'crash'
796
+ git_checkout_version('crash', @projects['crash'][:revision])
797
+ stack_name_crash = "ecs-task-crash-qa-#{deploy_id}"
798
+ stack_body = IO.read('projects/crash/deploy/task.yml')
799
+ parameters = [
800
+ {
801
+ parameter_key: 'Environment',
802
+ parameter_value: 'staging'
803
+ },
804
+ {
805
+ parameter_key: 'ReleaseVersion',
806
+ parameter_value: "#{@projects['crash'][:revision]}-#{deploy_id}"
807
+ },
808
+ {
809
+ parameter_key: 'TaskDesiredCount',
810
+ parameter_value: '1'
811
+ },
812
+ {
813
+ parameter_key: 'ECSClusterName',
814
+ parameter_value: @ecs_cluster_name
815
+ },
816
+ {
817
+ parameter_key: 'ALBShortName',
818
+ parameter_value: "crash-qa-#{deploy_id}"[0..31]
819
+ },
820
+ {
821
+ parameter_key: 'HostnamePattern',
822
+ parameter_value: "crash-#{@dns_record_identifier}.qa.colaster.com"
823
+ },
824
+ {
825
+ parameter_key: 'HostnamePatternPriority',
826
+ parameter_value: (hostname_pattern_priority.to_i + 10).to_s
827
+ }
828
+ ]
829
+ if stack_exists?(stack_name_crash)
830
+ cur_version = get_currently_deployed_version(stack_name_crash)
831
+ update_stack(stack_name_crash, stack_body, parameters, tags) unless cur_version.include?(@projects["crash"][:revision])
832
+ else
833
+ create_stack(stack_name_crash, stack_body, parameters, tags)
834
+ end
835
+ wait_for_stack_ready(stack_name_crash) unless stack_ready?(stack_name_crash)
836
+ update_service_defaults(stack_name_crash)
837
+ deploy_crash? && crash_hostname = get_route53_hostname(stack_name_crash)
838
+ projects_text = "
839
+ > Crash url: https://#{crash_hostname}
840
+ > SSH connection: ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no githubUsername@#{ec2_ip_address(asg_stack_name)}\n"
841
+ end
842
+
843
+ output projects_text.cyan
844
+ output "Deploy effettuato, everything is awesome!\n".green
845
+ if @qainit
846
+ qainit_write_output(projects_text, 'Indirizzi scritti su ')
675
847
  end
676
848
  end
677
849
 
@@ -1484,7 +1656,7 @@ class Release
1484
1656
  update_service_defaults(stack_name_borat)
1485
1657
  update_service_defaults(stack_name_bolla)
1486
1658
  update_service_defaults(stack_name_activia)
1487
- update_service_defaults(stack_name_crash) unless stack_ready?(stack_name_crash) || !deploy_crash?
1659
+ update_service_defaults(stack_name_crash) unless !deploy_crash?
1488
1660
 
1489
1661
  prima_hostname = get_route53_hostname(stack_name_web)
1490
1662
  urania_hostname = get_route53_hostname(stack_name_urania)
@@ -1527,10 +1699,7 @@ class Release
1527
1699
  output "Deploy effettuato, everything is awesome!\n".green
1528
1700
 
1529
1701
  if @qainit
1530
- `mkdir -p /drone/src/github.com/project/primait/qainit/#{ENV["DRONE_BRANCH"]}`
1531
- qa_file_name = "/drone/src/github.com/project/primait/qainit/#{ENV["DRONE_BRANCH"]}/output"
1532
- File.open(qa_file_name, 'w') { |file| file.write(projects_text) }
1533
- output "Indirizzi scritti su #{qa_file_name}".green
1702
+ qainit_write_output(projects_text, 'Indirizzi scritti su ')
1534
1703
  end
1535
1704
  end
1536
1705
 
@@ -1783,7 +1952,7 @@ class Release
1783
1952
  !@projects['crash'].empty? && (!@projects['crash'][:default_branch] || !@projects['crash'][:default_branch])
1784
1953
  end
1785
1954
 
1786
- def create_crash_artifact(revision, deploy_id)
1955
+ def create_crash_artifact(revision, deploy_id, minimal = false)
1787
1956
  output "Preparo l'artifact crash .zip\n".yellow
1788
1957
 
1789
1958
  git_checkout_version('crash', revision)
@@ -1803,26 +1972,49 @@ class Release
1803
1972
  if @qainit
1804
1973
  `mv docker-compose-ci.yml docker-compose.yml`
1805
1974
  exec_step 'prepare-docker-compose --directory crash && cp docker-compose-qainit.yml docker-compose.yml'
1806
- [
1807
- 'docker-compose build web',
1808
- "docker-compose run -w $PWD -u root -e WS_ENDPOINT=#{ws_endpoint} -e GRAPHQL_ENDPOINT=#{frontend_endpoint} -e MIX_ENV=qa web \
1809
- '-c' 'sed -i \"s/web-qa-host/#{web_qa_host}/g\" config/qa.exs && \
1810
- sed -i \"s/crash-qa-host/#{crash_qa_host}/g\" config/qa.exs && \
1811
- mix local.hex --force && mix hex.info && \
1812
- mix deps.get && \
1813
- cd assets && \
1814
- yarn --cache-folder ~/.cache/yarn && \
1815
- ./node_modules/.bin/elm-github-install && \
1816
- NODE_ENV=production sysconfcpus -n 2 ./node_modules/.bin/webpack -p --config config/webpack.config.prod.js && \
1817
- cd ../ && \
1818
- mix release.clean --implode --no-confirm && \
1819
- mix phx.digest && \
1820
- mix deps.clean --all && \
1821
- mix deps.get && \
1822
- mix compile && mix release --env=qa'",
1823
- 'docker-compose down'
1824
- ].each do |cmd|
1825
- execute_command cmd
1975
+ if minimal
1976
+ [
1977
+ 'docker-compose build web',
1978
+ "docker-compose run -w $PWD -u root -e WS_ENDPOINT=#{ws_endpoint} -e GRAPHQL_ENDPOINT=#{frontend_endpoint} -e MIX_ENV=staging web \
1979
+ '-c' 'sed -i \"s/crash-staging.prima.it/#{crash_qa_host}/g\" config/staging.exs && \
1980
+ mix local.hex --force && mix hex.info && \
1981
+ mix deps.get && \
1982
+ cd assets && \
1983
+ yarn --cache-folder ~/.cache/yarn && \
1984
+ ./node_modules/.bin/elm-github-install && \
1985
+ NODE_ENV=production sysconfcpus -n 2 ./node_modules/.bin/webpack -p --config config/webpack.config.prod.js && \
1986
+ cd ../ && \
1987
+ mix release.clean --implode --no-confirm && \
1988
+ mix phx.digest && \
1989
+ mix deps.clean --all && \
1990
+ mix deps.get && \
1991
+ mix compile && mix release --env=staging'",
1992
+ 'docker-compose down'
1993
+ ].each do |cmd|
1994
+ execute_command cmd
1995
+ end
1996
+ else
1997
+ [
1998
+ 'docker-compose build web',
1999
+ "docker-compose run -w $PWD -u root -e WS_ENDPOINT=#{ws_endpoint} -e GRAPHQL_ENDPOINT=#{frontend_endpoint} -e MIX_ENV=qa web \
2000
+ '-c' 'sed -i \"s/web-qa-host/#{web_qa_host}/g\" config/qa.exs && \
2001
+ sed -i \"s/crash-qa-host/#{crash_qa_host}/g\" config/qa.exs && \
2002
+ mix local.hex --force && mix hex.info && \
2003
+ mix deps.get && \
2004
+ cd assets && \
2005
+ yarn --cache-folder ~/.cache/yarn && \
2006
+ ./node_modules/.bin/elm-github-install && \
2007
+ NODE_ENV=production sysconfcpus -n 2 ./node_modules/.bin/webpack -p --config config/webpack.config.prod.js && \
2008
+ cd ../ && \
2009
+ mix release.clean --implode --no-confirm && \
2010
+ mix phx.digest && \
2011
+ mix deps.clean --all && \
2012
+ mix deps.get && \
2013
+ mix compile && mix release --env=qa'",
2014
+ 'docker-compose down'
2015
+ ].each do |cmd|
2016
+ execute_command cmd
2017
+ end
1826
2018
  end
1827
2019
 
1828
2020
  cleanup_containers
@@ -2401,7 +2593,7 @@ class Release
2401
2593
  Dir.chdir '../../'
2402
2594
  end
2403
2595
 
2404
- def create_prima_artifact(revision, branch_name, deploy_id)
2596
+ def create_prima_artifact(revision, branch_name, deploy_id, minimal = false)
2405
2597
  output "Preparo l'artifact prima .zip\n".yellow
2406
2598
 
2407
2599
  git_checkout_version('prima', revision)
@@ -2417,8 +2609,11 @@ class Release
2417
2609
  end
2418
2610
 
2419
2611
  backoffice_qa_host = get_route53_hostname("ecs-task-borat-qa-notneeded")
2612
+ # backoffice-staging.prima.it
2420
2613
  web_qa_host = get_route53_hostname("ecs-task-web-qa-notneeded")
2614
+ # staging.prima.it
2421
2615
  assange_qa_host = get_route53_hostname("ecs-task-assange-qa-notneeded")
2616
+ # assange-staging.prima.it
2422
2617
 
2423
2618
  if @qainit
2424
2619
  exec_step 'mv docker-compose-ci.yml docker-compose.yml'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prima-twig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.37.3
4
+ version: 0.37.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matteo Giachino
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2018-06-25 00:00:00.000000000 Z
16
+ date: 2018-06-26 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: aws-sdk