prima-twig 0.38.3 → 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/bin/twig-feature +308 -59
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 86b3b2b5faba0876e281785a2a444f92413950a51258d938ff55daeec770b46a
4
- data.tar.gz: 4f9be7d9f4e7d9c2404afee609cd9a92c5941737953e3cb79916b032d2f0d81c
2
+ SHA1:
3
+ metadata.gz: de22a45b28f8be6eea8717ce6bc7313486a6c20b
4
+ data.tar.gz: bd93c0683872852f9bdd179f92c18ded8668c29b
5
5
  SHA512:
6
- metadata.gz: 7f3714fb07cbf0d9ea6a79bbef37417d5816ba4e7c67263d4744d92ab3cfe5380e22cd53fa58294ab2bb3caa6637e5c71eb6db9d0e920a57842a6a3babab6fbe
7
- data.tar.gz: 8a29bd36112eda317fa7681a7daa6a28bb36c4f28a5e2f1238aedc2c1986df7714c5859a8480bb09eee1d23252bc37303fde833f67d84be59c451b2691975323
6
+ metadata.gz: de91cbbf78cf375cd870f3b79d018fad8a6a40abe5dea223c073be3784d332b6aa44073344226a541e4a5a9ac4455436bc4266278c6dc0b78d1025085b7f810c
7
+ data.tar.gz: 7bcb97c3c706cc4186fdd9ef7364fb285d643d5b11acbc89280c3f5fa735baa31273f56f6a17cba99d3beaf4f59a7c0248685f8dd66eef192ece7f89d5a1ea9d
@@ -66,6 +66,8 @@ class Release
66
66
  qainit_deploy_update!
67
67
  elsif 'read' == args[1]
68
68
  qainit_read_config! args[2]
69
+ elsif 'minimal' == args[1]
70
+ qainit_minimal_deploy! args[2]
69
71
  else
70
72
  if args[1]
71
73
  select_branches(args[1])
@@ -82,6 +84,8 @@ class Release
82
84
  deploy_update!
83
85
  elsif 'lock' == args[1]
84
86
  deploy_lock!
87
+ elsif 'minimal'
88
+ qainit_drone_minimal_deploy!
85
89
  else
86
90
  if args[1]
87
91
  select_branches(args[1])
@@ -456,9 +460,40 @@ class Release
456
460
  git checkout master`
457
461
  end
458
462
 
459
- def qainit_deploy_update!
463
+ def qainit_minimal_deploy!(project)
464
+ abort('Gli unici progetti permessi sono prima e crash') unless ['prima', 'crash'].include? project
465
+ project_definition = choose_branch_to_deploy(project)
466
+
460
467
  `git checkout master && git pull && git remote prune origin`
461
- # leggiamo i nomi dei branch
468
+
469
+ default_name = get_default_name @projects
470
+ output "Inserisci la feature a cui si riferisce il QA: [#{default_name}]".cyan
471
+ feature_number = String(STDIN.gets.chomp)
472
+ feature_number = default_name if feature_number.empty?
473
+
474
+ if `git branch -l | grep #{feature_number}`.size > 0
475
+ `git checkout #{feature_number} && git pull`
476
+ else
477
+ `git checkout -b #{feature_number}`
478
+ end
479
+
480
+ # così recupero le informazioni sul branch, poi vado a scrivere il file branch_names con una sola riga
481
+ branch = "#{project}:#{project_definition[:name]}:#{project_definition[:revision]}:#{project_definition[:default_branch]}"
482
+
483
+ File.open('branch_names', 'w') { |file| file.write(branch) }
484
+
485
+ `git add projects && \
486
+ git add branch_names && \
487
+ git commit -m 'minimal_#{feature_number}' && \
488
+ git push --set-upstream origin #{feature_number} && \
489
+ git checkout master`
490
+ end
491
+
492
+ def qainit_deploy_update!
493
+ `git checkout master && git pull`
494
+ # cancelliamo tutti i branch che non sono più sul repo remoto
495
+ `git fetch -p && for branch in \`git branch -vv | grep ': gone]' | awk '{print $1}'\`; do git branch -D $branch; done`
496
+ # leggiamo i nomi dei branch superstiti
462
497
  former_branches = `git branch -a | grep remotes/ | grep -v HEAD | sed 's/ remotes\\/origin\\///g'`.split "\n"
463
498
  # stampiamo la lista
464
499
  chosen_branch = choose do |menu|
@@ -589,8 +624,11 @@ class Release
589
624
  end
590
625
  get_s3_config_files
591
626
  @qainit = true
592
- if ('shutdown' == action)
627
+ case action
628
+ when 'shutdown'
593
629
  qainit_drone_shutdown!
630
+ when 'minimal'
631
+ qainit_drone_minimal_deploy!
594
632
  else
595
633
  deploy_feature!
596
634
  end
@@ -608,37 +646,208 @@ class Release
608
646
  end
609
647
 
610
648
  def calculate_deploy_id
611
- if deploy_crash?
612
- Digest::MD5.hexdigest(
613
- @projects["prima"][:name] +
614
- @projects["backoffice"][:name] +
615
- @projects["urania"][:name] +
616
- @projects["ermes"][:name] +
617
- @projects["bburago"][:name] +
618
- @projects["hal9000"][:name] +
619
- @projects["fidaty"][:name] +
620
- @projects["peano"][:name] +
621
- @projects["rogoreport"][:name] +
622
- @projects["assange"][:name] +
623
- @projects["borat"][:name] +
624
- @projects['crash'][:name] +
625
- @projects["activia"][:name]
626
- )
627
- else
628
- Digest::MD5.hexdigest(
629
- @projects["prima"][:name] +
630
- @projects["backoffice"][:name] +
631
- @projects["urania"][:name] +
632
- @projects["ermes"][:name] +
633
- @projects["bburago"][:name] +
634
- @projects["hal9000"][:name] +
635
- @projects["fidaty"][:name] +
636
- @projects["peano"][:name] +
637
- @projects["rogoreport"][:name] +
638
- @projects["assange"][:name] +
639
- @projects["borat"][:name] +
640
- @projects["activia"][:name]
641
- )
649
+ hashable = ''
650
+ @projects.each_key do |project_key|
651
+ if @projects[project_key][:name]
652
+ hashable += @projects[project_key][:name]
653
+ end
654
+ end
655
+ Digest::MD5.hexdigest(hashable)
656
+ end
657
+
658
+ def qainit_drone_minimal_deploy!
659
+ # binding.pry
660
+ # tenere solo il project da deployare (l'unico project è prima/crash)
661
+ project = ''
662
+ @projects.each_key do |project_key|
663
+ if @projects[project_key][:revision]
664
+ project = project_key
665
+ git_checkout_version(project_key, @projects[project_key][:revision])
666
+ end
667
+ end
668
+ deploy_id = calculate_deploy_id
669
+
670
+ @dns_record_identifier = deploy_id
671
+ hostname_pattern_priority = hostname_pattern_priority()
672
+ tags = [
673
+ {
674
+ key: project,
675
+ value: @projects[project][:name]
676
+ },
677
+ {
678
+ key: "hostname_pattern_priority",
679
+ value: hostname_pattern_priority
680
+ }
681
+ ]
682
+
683
+ cluster_stack_name = "ecs-cluster-qa-#{deploy_id}"
684
+
685
+ if stack_exists?(cluster_stack_name)
686
+ tags = get_stack_tags(cluster_stack_name)
687
+ hostname_pattern_priority = tags.detect do |tag|
688
+ tag.key == 'hostname_pattern_priority'
689
+ end.value
690
+ end
691
+
692
+ stack_name_alb = @base_stack_name_alb + deploy_id[0..5]
693
+ stack_name_alb_ws = @base_stack_name_alb_ws + deploy_id[0..5]
694
+
695
+ create_cluster_stack(cluster_stack_name, tags) unless stack_exists?(cluster_stack_name)
696
+ wait_for_stack_ready(cluster_stack_name) unless stack_ready?(cluster_stack_name)
697
+
698
+ create_alb_stack(stack_name_alb, "http", deploy_id, 'qa-minimal') unless stack_exists?(stack_name_alb)
699
+ create_alb_stack(stack_name_alb_ws, "websocket", deploy_id, 'qa-minimal') unless stack_exists?(stack_name_alb_ws)
700
+
701
+ resp = @cf.describe_stack_resource({stack_name: cluster_stack_name, logical_resource_id: 'ECSCluster'})
702
+ @ecs_cluster_name = resp.stack_resource_detail.physical_resource_id
703
+
704
+ asg_stack_name = "ecs-asg-allinone-qa-#{deploy_id}"
705
+ create_asg_stack(asg_stack_name, tags) unless stack_exists?(asg_stack_name)
706
+
707
+ case project
708
+ when 'prima'
709
+ 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")
710
+ when 'crash'
711
+ create_crash_artifact(@projects['crash'][:revision], deploy_id, true) unless artifact_exists?('prima-artifacts-encrypted', "microservices/crash/#{@projects['crash'][:revision]}-#{deploy_id}-qa.tar.gz")
712
+ end
713
+
714
+ wait_for_stack_ready(stack_name_alb) unless stack_ready?(stack_name_alb)
715
+ wait_for_stack_ready(stack_name_alb_ws) unless stack_ready?(stack_name_alb_ws)
716
+
717
+ stack_name_route53 = "ecs-route53-qa-#{deploy_id}"
718
+ stack_body = IO.read('cloudformation/stacks/route53/minimal_qa.yml')
719
+ parameters = [
720
+ {
721
+ parameter_key: "DnsRecordIdentifier",
722
+ parameter_value: @dns_record_identifier
723
+ },
724
+ {
725
+ parameter_key: "PrimaElbHostname",
726
+ parameter_value: get_alb_host(stack_name_alb)
727
+ },
728
+ {
729
+ parameter_key: 'CrashElbHostname',
730
+ parameter_value: get_alb_host(stack_name_alb_ws)
731
+ }
732
+ ]
733
+
734
+ create_stack(stack_name_route53, stack_body, parameters, tags) unless stack_exists?(stack_name_route53)
735
+ wait_for_stack_ready(stack_name_route53) unless stack_ready?(stack_name_route53)
736
+
737
+ case project
738
+ when 'prima'
739
+ stack_name_web = "ecs-task-web-qa-#{deploy_id}"
740
+ git_checkout_version('prima', @projects["prima"][:revision])
741
+ stack_body = IO.read('projects/prima/app/cloudformation/tasks/web.yml')
742
+ parameters = [
743
+ {
744
+ parameter_key: "Environment",
745
+ parameter_value: "qa-minimal"
746
+ },
747
+ {
748
+ parameter_key: "ReleaseVersion",
749
+ parameter_value: "#{@projects["prima"][:revision]}-#{deploy_id}"
750
+ },
751
+ {
752
+ parameter_key: "TaskDesiredCount",
753
+ parameter_value: "1"
754
+ },
755
+ {
756
+ parameter_key: "ECSClusterName",
757
+ parameter_value: @ecs_cluster_name
758
+ },
759
+ {
760
+ parameter_key: "ALBShortName",
761
+ parameter_value: "web-qa-#{deploy_id}"[0..31]
762
+ },
763
+ {
764
+ parameter_key: "WebQaBaseHostname",
765
+ parameter_value: "#{@dns_record_identifier}.qa.colaster.com"
766
+ },
767
+ {
768
+ parameter_key: "HostnamePattern",
769
+ parameter_value: "ww*-#{@dns_record_identifier}.qa.colaster.com"
770
+ },
771
+ {
772
+ parameter_key: "HostnamePatternPriority",
773
+ parameter_value: hostname_pattern_priority
774
+ },
775
+ {
776
+ parameter_key: "HostnamePatternAggregatorPriority",
777
+ parameter_value: (hostname_pattern_priority.to_i + 1).to_s
778
+ },
779
+ {
780
+ parameter_key: "EnvHash",
781
+ parameter_value: deploy_id
782
+ }
783
+ ]
784
+ if stack_exists?(stack_name_web)
785
+ cur_version = get_currently_deployed_version(stack_name_web)
786
+ update_stack(stack_name_web, stack_body, parameters, tags) unless cur_version.include?(@projects["prima"][:revision])
787
+ else
788
+ create_stack(stack_name_web, stack_body, parameters, tags)
789
+ end
790
+ wait_for_stack_ready(stack_name_web) unless stack_ready?(stack_name_web)
791
+ update_service_defaults(stack_name_web)
792
+ prima_hostname = get_route53_hostname(stack_name_web)
793
+
794
+ projects_text = "
795
+ > Prima url: https://#{prima_hostname}
796
+ > Prima RI url: https://#{prima_hostname.sub("www", "wwwri")}
797
+ > SSH connection: ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no githubUsername@#{ec2_ip_address(asg_stack_name)}\n"
798
+
799
+ when 'crash'
800
+ git_checkout_version('crash', @projects['crash'][:revision])
801
+ stack_name_crash = "ecs-task-crash-qa-#{deploy_id}"
802
+ stack_body = IO.read('projects/crash/deploy/task.yml')
803
+ parameters = [
804
+ {
805
+ parameter_key: 'Environment',
806
+ parameter_value: 'qa'
807
+ },
808
+ {
809
+ parameter_key: 'ReleaseVersion',
810
+ parameter_value: "#{@projects['crash'][:revision]}-#{deploy_id}"
811
+ },
812
+ {
813
+ parameter_key: 'TaskDesiredCount',
814
+ parameter_value: '1'
815
+ },
816
+ {
817
+ parameter_key: 'ECSClusterName',
818
+ parameter_value: @ecs_cluster_name
819
+ },
820
+ {
821
+ parameter_key: 'ALBShortName',
822
+ parameter_value: "crash-qa-#{deploy_id}"[0..31]
823
+ },
824
+ {
825
+ parameter_key: 'HostnamePattern',
826
+ parameter_value: "crash-#{@dns_record_identifier}.qa.colaster.com"
827
+ },
828
+ {
829
+ parameter_key: 'HostnamePatternPriority',
830
+ parameter_value: (hostname_pattern_priority.to_i + 10).to_s
831
+ }
832
+ ]
833
+ if stack_exists?(stack_name_crash)
834
+ cur_version = get_currently_deployed_version(stack_name_crash)
835
+ update_stack(stack_name_crash, stack_body, parameters, tags) unless cur_version.include?(@projects["crash"][:revision])
836
+ else
837
+ create_stack(stack_name_crash, stack_body, parameters, tags)
838
+ end
839
+ wait_for_stack_ready(stack_name_crash) unless stack_ready?(stack_name_crash)
840
+ update_service_defaults(stack_name_crash)
841
+ crash_hostname = get_route53_hostname(stack_name_crash)
842
+ projects_text = "
843
+ > Crash url: https://#{crash_hostname}
844
+ > SSH connection: ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no githubUsername@#{ec2_ip_address(asg_stack_name)}\n"
845
+ end
846
+
847
+ output projects_text.cyan
848
+ output "Deploy effettuato, everything is awesome!\n".green
849
+ if @qainit
850
+ qainit_write_output(projects_text, 'Indirizzi scritti su ')
642
851
  end
643
852
  end
644
853
 
@@ -1687,7 +1896,7 @@ class Release
1687
1896
  !@projects['crash'].empty? && (!@projects['crash'][:default_branch] || !@projects['crash'][:default_branch])
1688
1897
  end
1689
1898
 
1690
- def create_crash_artifact(revision, deploy_id)
1899
+ def create_crash_artifact(revision, deploy_id, minimal = false)
1691
1900
  output "Preparo l'artifact crash .zip\n".yellow
1692
1901
 
1693
1902
  git_checkout_version('crash', revision)
@@ -1707,26 +1916,49 @@ class Release
1707
1916
  if @qainit
1708
1917
  `mv docker-compose-ci.yml docker-compose.yml`
1709
1918
  exec_step 'prepare-docker-compose --directory crash && cp docker-compose-qainit.yml docker-compose.yml'
1710
- [
1711
- 'docker-compose build web',
1712
- "docker-compose run -w $PWD -u root -e WS_ENDPOINT=#{ws_endpoint} -e GRAPHQL_ENDPOINT=#{frontend_endpoint} -e MIX_ENV=qa web \
1713
- '-c' 'sed -i \"s/web-qa-host/#{web_qa_host}/g\" config/qa.exs && \
1714
- sed -i \"s/crash-qa-host/#{crash_qa_host}/g\" config/qa.exs && \
1715
- mix local.hex --force && mix hex.info && \
1716
- mix deps.get && \
1717
- cd assets && \
1718
- yarn --cache-folder ~/.cache/yarn && \
1719
- ./node_modules/.bin/elm-github-install && \
1720
- NODE_ENV=production sysconfcpus -n 2 ./node_modules/.bin/webpack -p --config config/webpack.config.prod.js && \
1721
- cd ../ && \
1722
- mix release.clean --implode --no-confirm && \
1723
- mix phx.digest && \
1724
- mix deps.clean --all && \
1725
- mix deps.get && \
1726
- mix compile && mix release --env=qa'",
1727
- 'docker-compose down'
1728
- ].each do |cmd|
1729
- execute_command cmd
1919
+ if minimal
1920
+ [
1921
+ 'docker-compose build web',
1922
+ "docker-compose run -w $PWD -u root -e WS_ENDPOINT=#{ws_endpoint} -e GRAPHQL_ENDPOINT=#{frontend_endpoint} -e MIX_ENV=staging web \
1923
+ '-c' 'sed -i \"s/crash-staging.prima.it/#{crash_qa_host}/g\" config/staging.exs && \
1924
+ mix local.hex --force && mix hex.info && \
1925
+ mix deps.get && \
1926
+ cd assets && \
1927
+ yarn --cache-folder ~/.cache/yarn && \
1928
+ ./node_modules/.bin/elm-github-install && \
1929
+ NODE_ENV=production sysconfcpus -n 2 ./node_modules/.bin/webpack -p --config config/webpack.config.prod.js && \
1930
+ cd ../ && \
1931
+ mix release.clean --implode --no-confirm && \
1932
+ mix phx.digest && \
1933
+ mix deps.clean --all && \
1934
+ mix deps.get && \
1935
+ mix compile && mix release --env=staging'",
1936
+ 'docker-compose down'
1937
+ ].each do |cmd|
1938
+ execute_command cmd
1939
+ end
1940
+ else
1941
+ [
1942
+ 'docker-compose build web',
1943
+ "docker-compose run -w $PWD -u root -e WS_ENDPOINT=#{ws_endpoint} -e GRAPHQL_ENDPOINT=#{frontend_endpoint} -e MIX_ENV=qa web \
1944
+ '-c' 'sed -i \"s/web-qa-host/#{web_qa_host}/g\" config/qa.exs && \
1945
+ sed -i \"s/crash-qa-host/#{crash_qa_host}/g\" config/qa.exs && \
1946
+ mix local.hex --force && mix hex.info && \
1947
+ mix deps.get && \
1948
+ cd assets && \
1949
+ yarn --cache-folder ~/.cache/yarn && \
1950
+ ./node_modules/.bin/elm-github-install && \
1951
+ NODE_ENV=production sysconfcpus -n 2 ./node_modules/.bin/webpack -p --config config/webpack.config.prod.js && \
1952
+ cd ../ && \
1953
+ mix release.clean --implode --no-confirm && \
1954
+ mix phx.digest && \
1955
+ mix deps.clean --all && \
1956
+ mix deps.get && \
1957
+ mix compile && mix release --env=qa'",
1958
+ 'docker-compose down'
1959
+ ].each do |cmd|
1960
+ execute_command cmd
1961
+ end
1730
1962
  end
1731
1963
 
1732
1964
  cleanup_containers
@@ -2262,7 +2494,8 @@ class Release
2262
2494
  Dir.chdir '../../'
2263
2495
  end
2264
2496
 
2265
- def create_prima_artifact(revision, branch_name, deploy_id)
2497
+ def create_prima_artifact(revision, branch_name, deploy_id, minimal = false)
2498
+ # @projects["prima"][:revision], @projects["prima"][:name], deploy_id, true
2266
2499
  output "Preparo l'artifact prima .zip\n".yellow
2267
2500
 
2268
2501
  git_checkout_version('prima', revision)
@@ -2278,10 +2511,26 @@ class Release
2278
2511
  end
2279
2512
 
2280
2513
  backoffice_qa_host = get_route53_hostname("ecs-task-borat-qa-notneeded")
2514
+ # backoffice-staging.prima.it
2281
2515
  web_qa_host = get_route53_hostname("ecs-task-web-qa-notneeded")
2516
+ # staging.prima.it
2282
2517
  assange_qa_host = get_route53_hostname("ecs-task-assange-qa-notneeded")
2518
+ # assange-staging.prima.it
2519
+ if minimal
2520
+ backoffice_qa_host = 'backoffice-staging.prima.it'
2521
+ assange_qa_host = 'assange-staging.prima.it'
2522
+ end
2283
2523
 
2284
- if @qainit
2524
+ if minimal # passare Environment=qa al task.yml, ma mettere i puntamenti verso staging
2525
+ exec_step 'mv docker-compose-ci.yml docker-compose.yml'
2526
+ exec_step 'prepare-docker-compose --directory prima'
2527
+ exec_step 'sed -i "s/\\/home\\/app/\\/root/g" docker-compose.yml'
2528
+ [
2529
+ "bin/minimal_local_build_artifact.sh #{branch_name} #{web_qa_host} #{backoffice_qa_host} #{assange_qa_host} #{deploy_id} #{'update' if @deploy_update}"
2530
+ ].each do |cmd|
2531
+ execute_command cmd
2532
+ end
2533
+ elsif @qainit
2285
2534
  exec_step 'mv docker-compose-ci.yml docker-compose.yml'
2286
2535
  exec_step 'prepare-docker-compose --directory prima'
2287
2536
  exec_step 'sed -i "s/\\/home\\/app/\\/root/g" docker-compose.yml'
@@ -2343,12 +2592,12 @@ class Release
2343
2592
  update_stack(stack_name, stack_body, [], tags)
2344
2593
  end
2345
2594
 
2346
- def create_alb_stack(stack_name, role, hash)
2595
+ def create_alb_stack(stack_name, role, hash, environment = 'qa')
2347
2596
  stack_body = IO.read('cloudformation/stacks/elb/alb-public-qa.yml')
2348
2597
  parameters = [
2349
2598
  {
2350
2599
  parameter_key: "Environment",
2351
- parameter_value: "qa"
2600
+ parameter_value: environment
2352
2601
  },
2353
2602
  {
2354
2603
  parameter_key: "Role",
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.38.3
4
+ version: 0.39.0
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-07-17 00:00:00.000000000 Z
16
+ date: 2018-07-19 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: aws-sdk
@@ -214,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
214
  version: '0'
215
215
  requirements: []
216
216
  rubyforge_project:
217
- rubygems_version: 2.7.7
217
+ rubygems_version: 2.6.11
218
218
  signing_key:
219
219
  specification_version: 4
220
220
  summary: The Prima twig toolbelt