calevipoeg-zeus 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4f7faca906fbdbdb332cf5177b35c9f36c4bd76307b33fd2e872d5fb5d0ac1d
4
- data.tar.gz: b3ccabf7e8976d9873018fda8eee44bdab17957d86acc7f94c742a425cbda595
3
+ metadata.gz: 2ff33fd8321399b29bb46764cf8e2d84f8d5b0a0b7e2d592589718a22ccece13
4
+ data.tar.gz: 9c29313d35752a2b1423bc0aee046a0a952a18b2b5ef3d1e0af7d250aaf8e7d2
5
5
  SHA512:
6
- metadata.gz: f72d23d28600540b4167cb4a9597e5b2fb9cf5dd14f094d9b528511f886f4647df37980c49d98aa4e0ba6620dd01bb86534ee8fb51c0796936a267daaa8cd321
7
- data.tar.gz: 83d20597c19cb340d6249363ea05f28177bd966165aaaa47019a852c6b17e6a1d1bbc40d962df56f4d5db922d53da4957fe4979fe4f18674bb5740aacee2e7e4
6
+ metadata.gz: 54c626d6fbfbc1986f47eee974872976b8a89c5962d78818f199333cb081460dfefc56c217456f58d04313e778c4222f583e35841854c404119136f614ddf59d
7
+ data.tar.gz: d48d3bdcdf7d9d77489290a649cad4f113d5dd9c29b8c7c995b9b35891b222ef7c725dda8e48d9c7cca9ac288d2329d4c56af6d1011ce7b7305ec8076a2d1b36
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zeus (0.1.0)
4
+ calevipoeg-zeus (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -26,9 +26,9 @@ PLATFORMS
26
26
  ruby
27
27
 
28
28
  DEPENDENCIES
29
+ calevipoeg-zeus!
29
30
  rake
30
31
  rspec
31
- zeus!
32
32
 
33
33
  BUNDLED WITH
34
34
  2.1.4
data/README.md CHANGED
@@ -66,3 +66,33 @@ ensure
66
66
  pg.unlink
67
67
  end
68
68
  ```
69
+
70
+ ## Mina tasks
71
+
72
+ ```ruby
73
+ require 'zeus/mina/make'
74
+
75
+ invoke :make, 'docker:push'
76
+ ```
77
+
78
+ ```ruby
79
+ require 'zeus/mina/docker_service'
80
+
81
+ invoke :make, 'docker:push'
82
+ invoke :'docker_service:update', 'app', '--force --with-registry-auth --image http://example.com'
83
+ ```
84
+
85
+ ```ruby
86
+ require 'zeus/mina/s3'
87
+
88
+ set :s3_client, -> do
89
+ Aws::S3::Client.new
90
+ end
91
+
92
+ set :s3_bucket, -> do
93
+ 'hole'
94
+ end
95
+
96
+ invoke :'s3:upload', ["public/static"], "cdn/production/static"
97
+ invoke :'s3:clean', "cdn/production/static"
98
+ ```
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :docker_service do
4
+ desc 'Update a service'
5
+ task :update, %i[application arguments] do |_t, argv|
6
+ command "docker service update #{argv.application} #{argv.arguments}"
7
+ end
8
+
9
+ desc 'Create docker container'
10
+ task :create, %i[arguments] do |_t, argv|
11
+ command "docker service create #{argv.arguments.tr("\n", ' ')}"
12
+ end
13
+
14
+ # The <command> should have:
15
+ # 1) "--restart-condition none" and "--detach" arguments for docker-create
16
+ # 2) "--name $SHOT_NAME"
17
+ desc 'Execute one-time container task'
18
+ task :shot, %i[name command] do |_t, argv|
19
+ command <<~CMD
20
+ bash << "EOF"
21
+ export SHOT_NAME=#{argv.name}
22
+
23
+ docker service rm $SHOT_NAME 2>/dev/null
24
+
25
+ TASK_ID=$(#{argv.command})
26
+
27
+ echo "Waiting ${SHOT_NAME} with ID <${TASK_ID}> for being finished"
28
+
29
+ while : ; do
30
+ STOPPED_TASK=$(docker service ps --filter 'desired-state=shutdown' ${TASK_ID} -q)
31
+ [[ ${STOPPED_TASK} != "" ]] && break
32
+ echo "not finished yet $(date)"
33
+ sleep 1
34
+ done
35
+
36
+ docker service logs --raw ${TASK_ID}
37
+ docker service rm ${TASK_ID} > /dev/null
38
+ EOF
39
+ CMD
40
+ end
41
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @example invoke :make, 'docker:push'
4
+ # @example invoke :make, 'docker:push', 'APP_ENV=staging'
5
+ desc 'Execute a Make file command'
6
+ task :make, %i[command env] do |_t, argv|
7
+ system "#{argv.env} make #{argv.command}", exception: true
8
+ end
@@ -0,0 +1,39 @@
1
+ require 'aws-sdk-s3'
2
+
3
+ set :s3_client, -> { raise }
4
+ set :s3_bucket, -> { raise }
5
+
6
+ namespace :aws do
7
+ namespace :s3 do
8
+ task :upload, %i[dirs destination] do |_t, argv|
9
+ Array(argv.dirs).each do |dir|
10
+ Dir.glob(Pathname.new(dir).join('**/**')).each do |file|
11
+ next if File.directory?(file)
12
+
13
+ path = Pathname.new(file).relative_path_from(dir)
14
+ key = Pathname.new(argv.destination).join(path)
15
+
16
+ io = Zeus::S3Io.new(File.open(file))
17
+ io.upload(fetch(:s3_client), bucket: fetch(:s3_bucket), key: key) do |progress|
18
+ puts "[#{progress}%] Uploading #{file} -> #{key}"
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ # task :clean, %i[destination] => :client do |_t, argv|
25
+ # files = @s3.list_objects_v2(bucket: fetch(:s3_bucket_name), prefix: argv.destination).each_with_object([]) do |list, object|
26
+ # list.contents.each do |file|
27
+ # next if file.last_modified > fetch(:s3_clean_after)
28
+ #
29
+ # object << file
30
+ # end
31
+ # end
32
+ #
33
+ # files.each do |file|
34
+ # puts "[-] removing (last mod #{file.last_modified}) #{file.key}"
35
+ # @s3.delete_object(bucket: fetch(:s3_bucket_name), key: file.key)
36
+ # end
37
+ # end
38
+ end
39
+ end
data/lib/zeus/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zeus
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calevipoeg-zeus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aliaksandr Shylau
@@ -30,6 +30,9 @@ files:
30
30
  - bin/setup
31
31
  - exe/zeus:copy
32
32
  - lib/zeus.rb
33
+ - lib/zeus/mina/docker_service.rb
34
+ - lib/zeus/mina/make.rb
35
+ - lib/zeus/mina/s3.rb
33
36
  - lib/zeus/pg_base_backup.rb
34
37
  - lib/zeus/s3_io.rb
35
38
  - lib/zeus/s3_iterate.rb