calevipoeg-zeus 0.1.0 → 0.1.5

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: 6820060f9e8309528aac997df89e9724c21c8a9533d2bac39b3172b05ca6d24a
4
- data.tar.gz: 99a4d6699a253c6c8047a477294d0e2e179ce3226295051a7606c4af79aecb6b
3
+ metadata.gz: 48770f6ed5824ba412873a19fe7aaab01da99ab985b033c52ff019aa2b08473b
4
+ data.tar.gz: f09f8ee47247f313ea441dfcd3107c5a21ba6a675d345f4a4c858288b02f0142
5
5
  SHA512:
6
- metadata.gz: b6642017621bf5afe8ff790282081cab1bafac9c8973c95b5a960a542093f96c6572fbb26bdef08ab3ef632356ff80ea461546dd1c997e026bb3c02ec5e17123
7
- data.tar.gz: 8d884d1f4fc000b212fad4bcc625d091f09e1987fb151ad7723917a9ef930b7c0911f03a963beda42ef0e2aa80c8c55ae869f58e6103b5464340c3df38b3d22b
6
+ metadata.gz: 6936b0661f6e8d5a062f6101ec0ed1191b655760914e61dc28952780bcaedcc9af3819645f6e436123779384216d5e1df37c8de215aac77f912e9183bc8ac71d
7
+ data.tar.gz: 7014adc858cb7553098733ebe610deb73b8e3fde92d57aa472273bc80b8feb057393b37141567752c6821a3199c2324a0522f65b044dd9b99db395e0fc109335
@@ -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
@@ -8,6 +8,13 @@ This is a helper package for my own projects
8
8
  gem 'calevipoeg-zeus', require: 'zeus'
9
9
  ```
10
10
 
11
+ To copy `shell` scripts into the project `/bin` folder
12
+ please run:
13
+
14
+ ```bash
15
+ bundle exec zeus:copy bin/
16
+ ```
17
+
11
18
  ## SSH Tunneling
12
19
 
13
20
  ```ruby
@@ -59,3 +66,33 @@ ensure
59
66
  pg.unlink
60
67
  end
61
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', 14.days.ago
98
+ ```
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ destination = File.join(Dir.pwd, ARGV.fetch(0))
4
+ source = File.join(File.dirname(__FILE__), '../sh')
5
+
6
+ FileUtils.cp_r(Dir[File.join(source, '*')], destination)
@@ -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,30 @@
1
+ require 'aws-sdk-s3'
2
+
3
+ set :s3_client, -> { raise }
4
+ set :s3_bucket, -> { raise }
5
+
6
+ namespace :s3 do
7
+ task :upload, %i[dirs destination] do |_t, argv|
8
+ Array(argv.dirs).each do |dir|
9
+ Dir.glob(Pathname.new(dir).join('**/**')).each do |file|
10
+ next if File.directory?(file)
11
+
12
+ path = Pathname.new(file).relative_path_from(dir)
13
+ key = Pathname.new(argv.destination).join(path)
14
+
15
+ io = Zeus::S3Io.new(File.open(file))
16
+ io.upload(fetch(:s3_client), bucket: fetch(:s3_bucket), key: key) do |progress|
17
+ puts "[#{progress}%] Uploading #{file} -> #{key}"
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ task :clean, %i[prefix last_mod] => :client do |_t, argv|
24
+ Zeus::S3Iterate.new(fetch(:s3_client)).delete_if(bucket: fetch(:s3_bucket), prefix: argv.prefix) do |file|
25
+ break(false) unless argv.last_mod >= file.last_modified
26
+
27
+ puts "[-] removing (last mod #{file.last_modified}) #{file.key}"
28
+ end
29
+ end
30
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zeus
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.5'
5
5
  end
6
+
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+ # @example:
3
+ # bin/dec.sh .env.production.gpg password
4
+ # bin/dec.sh .env.production.gpg $(cat gpg.key | xargs)
5
+ echo $2 | gpg --batch --yes --passphrase-fd 0 $1
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+ # @example:
3
+ # bin/enc.sh .env.production password
4
+ # bin/enc.sh .env.production $(cat gpg.key | xargs)
5
+ echo $2 | gpg --batch --yes --passphrase-fd 0 -c $1
@@ -0,0 +1,19 @@
1
+ #!/bin/bash
2
+
3
+ # export MAXMIND_KEY=foo
4
+ # bin/geolite.sh ./tmp
5
+
6
+ if [ -z "$MAXMIND_KEY" ]
7
+ then
8
+ echo "MAXMIND_KEY is undefined"
9
+ exit
10
+ fi
11
+
12
+ DESTINATION=$1
13
+ TMP_DIR=$(mktemp -d -t maxmind)
14
+
15
+ cd $TMP_DIR
16
+ wget "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=$MAXMIND_KEY&suffix=tar.gz" -O ./GeoLite2-City.tar.gz
17
+ tar --strip=1 -zxvf GeoLite2-City.tar.gz `tar -tzf GeoLite2-City.tar.gz | grep GeoLite2-City.mmdb`
18
+ cd -
19
+ mv $TMP_DIR/GeoLite2-City.mmdb $DESTINATION/
@@ -22,7 +22,6 @@ Gem::Specification.new do |spec|
22
22
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
23
  end
24
24
  spec.bindir = 'exe'
25
- # @refs
26
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
26
  spec.require_paths = %w[lib]
28
27
  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.0
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aliaksandr Shylau
@@ -13,7 +13,8 @@ dependencies: []
13
13
  description: Helper package for own projects
14
14
  email:
15
15
  - alex.shilov.by@gmail.com
16
- executables: []
16
+ executables:
17
+ - zeus:copy
17
18
  extensions: []
18
19
  extra_rdoc_files: []
19
20
  files:
@@ -27,12 +28,19 @@ files:
27
28
  - bin/console
28
29
  - bin/release.sh
29
30
  - bin/setup
31
+ - exe/zeus:copy
30
32
  - lib/zeus.rb
33
+ - lib/zeus/mina/docker_service.rb
34
+ - lib/zeus/mina/make.rb
35
+ - lib/zeus/mina/s3.rb
31
36
  - lib/zeus/pg_base_backup.rb
32
37
  - lib/zeus/s3_io.rb
33
38
  - lib/zeus/s3_iterate.rb
34
39
  - lib/zeus/ssh_tunnel.rb
35
40
  - lib/zeus/version.rb
41
+ - sh/dec.sh
42
+ - sh/enc.sh
43
+ - sh/geolite.sh
36
44
  - zeus.gemspec
37
45
  homepage: https://github.com/calevipoeg/zeus
38
46
  licenses: