capistrano-lameco 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d6527abe614407da679c10cfa4efa45c31d9669f5cb6333fa2071bc87f503a3b
4
+ data.tar.gz: b369ef888e9f441f853faea5aa5bb3fd20543166737c8b01ec95048592bd59f4
5
+ SHA512:
6
+ metadata.gz: 56d0ef89e5b9a252a82e342aa93ac636727ed5cf1a663391f180e1aa0fb54b2614507b4b4cb829229aadd9e53e733e06cfd462e566e421c429eda865edb672c4
7
+ data.tar.gz: b88f644dcbf65ca5cf0993b899c13744bba4e9857140939a36a7ee66beecc274506c5bda806a90368c914eecfc7b2dd5615fe9a96cd2f26ea59aaf1ee0f2d3cc
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in capistrano-lameco.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Capistrano::Lameco
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/capistrano/lameco`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'capistrano-lameco'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install capistrano-lameco
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/capistrano-lameco.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "capistrano/lameco"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "capistrano-lameco"
6
+ spec.version = "0.1.0"
7
+ spec.authors = ["Laméco Development B.V."]
8
+ spec.email = ["development@lameco.nl"]
9
+ spec.summary = %q{Common Laméco helpers for Capistrano}
10
+ spec.homepage = "https://www.lameco.nl"
11
+
12
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
13
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
14
+ if spec.respond_to?(:metadata)
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = spec.homepage
17
+ else
18
+ raise "RubyGems 2.0 or newer is required to protect against " \
19
+ "public gem pushes."
20
+ end
21
+
22
+ spec.files = `git ls-files`.split($/)
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "capistrano", "~> 3.1"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.17"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ end
@@ -0,0 +1,30 @@
1
+ # Project Type
2
+ project_type = if File.exist?('bin/console') && File.exist?('src/Kernel.php')
3
+ 'symfony'
4
+ elsif File.exist?('craft')
5
+ 'craftcms'
6
+ elsif File.exist?('artisan')
7
+ 'laravel'
8
+ else
9
+ fail "Unknown project type"
10
+ end
11
+ set :lameco_project_type, project_type
12
+ puts "Project type: #{fetch(:lameco_project_type)}"
13
+
14
+ # Database dump directory
15
+ dump_dir = case project_type
16
+ when 'symfony' then 'var'
17
+ when 'craftcms' then 'storage'
18
+ else ''
19
+ end
20
+ set :lameco_dump_dir, dump_dir
21
+ puts "Dump directory: #{fetch(:lameco_dump_dir)}"
22
+
23
+ # Public directory
24
+ public_dir = case project_type
25
+ when 'symfony' then 'public'
26
+ when 'craftcms' then 'web'
27
+ else ''
28
+ end
29
+ set :lameco_public_dir, public_dir
30
+ puts "Public directory: #{fetch(:lameco_public_dir)}"
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/lameco.rake", __FILE__)
@@ -0,0 +1,9 @@
1
+ require "capistrano/plugin"
2
+
3
+ load File.expand_path("../tasks/lameco.rake", __FILE__)
4
+
5
+ namespace :load do
6
+ task :defaults do
7
+ load File.expand_path("../lameco/defaults.rb", __FILE__)
8
+ end
9
+ end
@@ -0,0 +1,81 @@
1
+ namespace :lameco do
2
+ task :db_download_current do
3
+ on roles(:app) do
4
+ # TODO: Make sure keep_database is read from the command line
5
+ puts "Keep database: #{fetch(:keep_database)}"
6
+
7
+ remote_env_content = capture("cat #{fetch(:deploy_to)}/shared/.env")
8
+ remote_env = fetch_env(remote_env_content)
9
+ remote_database_user, remote_database_password, remote_database_name = extract_db_credentials(remote_env)
10
+
11
+ if remote_database_user && remote_database_password && remote_database_name
12
+ dump_file = "current_#{remote_database_name}.sql.gz"
13
+ set :dump_file, dump_file
14
+
15
+ execute "mysqldump --quick --single-transaction -u #{remote_database_user} -p#{remote_database_password} #{remote_database_name} | gzip > ~/#{dump_file}"
16
+ download! dump_file, "#{fetch(:lameco_dump_dir)}/#{dump_file}"
17
+ else
18
+ error "Remote database credentials could not be extracted."
19
+ end
20
+ end
21
+ run_locally do
22
+ local_env_content = capture("cat .env")
23
+ local_env = fetch_env(local_env_content)
24
+ local_database_user, local_database_password, local_database_name = extract_db_credentials(local_env)
25
+
26
+ if local_database_user && local_database_password && local_database_name
27
+ execute "gunzip -c #{fetch(:lameco_dump_dir)}/#{fetch(:dump_file)} | mysql -u #{local_database_user} -p#{local_database_password} #{local_database_name}"
28
+
29
+ #if not fetch(:keep_database, false)
30
+ # execute "rm #{fetch(:lameco_dump_dir)}/#{fetch(:dump_file)}"
31
+ #end
32
+ else
33
+ error "Local database credentials could not be extracted."
34
+ end
35
+ end
36
+ end
37
+
38
+ task :download do
39
+ run_locally do
40
+ execute "rsync -azh --partial --append --progress -e 'ssh -p #{fetch(:ssh_options)[:port]}' #{fetch:lameco_user}@#{fetch(:server)}:#{fetch(:deploy_to)}/shared/#{fetch(:lameco_public_dir)}/uploads #{fetch(:lameco_public_dir)}"
41
+ end
42
+ end
43
+
44
+ task :upload do
45
+ run_locally do
46
+ execute "rsync -azh --partial --inplace --progress -e 'ssh -p #{fetch(:ssh_options)[:port]}' #{fetch(:lameco_public_dir)}/uploads/* #{fetch(:lameco_user)}@#{fetch(:server)}:#{fetch(:deploy_to)}/shared/#{fetch(:lameco_public_dir)}/uploads"
47
+ end
48
+ end
49
+
50
+ task :db_credentials do
51
+ on roles(:app) do
52
+ remote_env_content = capture("cat #{fetch(:deploy_to)}/shared/.env")
53
+ remote_env = fetch_env(remote_env_content)
54
+ remote_database_user, remote_database_password, remote_database_name = extract_db_credentials(remote_env)
55
+
56
+ if remote_database_user && remote_database_password
57
+ puts "Username: #{remote_database_user}"
58
+ puts "Password: #{remote_database_password}"
59
+ else
60
+ error "Remote database credentials could not be extracted."
61
+ end
62
+ end
63
+ end
64
+
65
+ def fetch_env(env_content)
66
+ env_content.each_line.with_object({}) do |line, hash|
67
+ kv = line.strip.match(/^([^=]+)=(?:['"]?)(.+?)(?:['"]?)$/)
68
+ hash[kv[1]] = kv[2] if kv
69
+ end
70
+ end
71
+
72
+ def extract_db_credentials(env)
73
+ if env['DATABASE_URL']
74
+ db_match = env['DATABASE_URL'].match(%r{mysql://([^:]+):([^@]+)@[^/]+/([^?]+)})
75
+ return [db_match[1], db_match[2], db_match[3]] if db_match
76
+ elsif env['CRAFT_DB_DATABASE']
77
+ return [env['CRAFT_DB_USER'], env['CRAFT_DB_PASSWORD'], env['CRAFT_DB_DATABASE']]
78
+ end
79
+ [nil, nil, nil]
80
+ end
81
+ end
File without changes
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-lameco
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Laméco Development B.V.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-02-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description:
56
+ email:
57
+ - development@lameco.nl
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - README.md
65
+ - Rakefile
66
+ - bin/console
67
+ - bin/setup
68
+ - capistrano-lameco.gemspec
69
+ - lib/capistrano-lameco.rb
70
+ - lib/capistrano/lameco.rb
71
+ - lib/capistrano/lameco/defaults.rb
72
+ - lib/capistrano/lameco/lameco.rb
73
+ - lib/capistrano/tasks/lameco.rake
74
+ homepage: https://www.lameco.nl
75
+ licenses: []
76
+ metadata:
77
+ homepage_uri: https://www.lameco.nl
78
+ source_code_uri: https://www.lameco.nl
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubygems_version: 3.0.3.1
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Common Laméco helpers for Capistrano
98
+ test_files: []