Class: Wellcar::Commands::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/wellcar/commands/base.rb

Direct Known Subclasses

Dock, New

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



4
5
6
# File 'lib/wellcar/commands/base.rb', line 4

def app_name
  @app_name
end

#domain_nameObject

Returns the value of attribute domain_name.



4
5
6
# File 'lib/wellcar/commands/base.rb', line 4

def domain_name
  @domain_name
end

#github_accountObject

Returns the value of attribute github_account.



4
5
6
# File 'lib/wellcar/commands/base.rb', line 4

def 
  
end

#ruby_versionObject

Returns the value of attribute ruby_version.



4
5
6
# File 'lib/wellcar/commands/base.rb', line 4

def ruby_version
  @ruby_version
end

#use_bundler_2Object

Returns the value of attribute use_bundler_2.



4
5
6
# File 'lib/wellcar/commands/base.rb', line 4

def use_bundler_2
  @use_bundler_2
end

Instance Method Details

#build_development_environmentObject



70
71
72
# File 'lib/wellcar/commands/base.rb', line 70

def build_development_environment
  exit 128 unless system "docker-compose build web webpack-dev-server database"
end

#clean_dockerObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/wellcar/commands/base.rb', line 52

def clean_docker
  # Make sure that no pre-existing containers are running. Although 
  # very unlikely, it's worth being thorough. This makes the command
  # slow but for the time being this ensures the containers and images
  # are as expected.
  exit 8 unless system "docker-compose down --remove-orphans"

  removable_volumes = ["#{app_name}_gem_cache", "#{app_name}_node_modules"]
  volumes_to_remove = %x(docker volume ls --format='{{.Name}}')
    .split("\n") & removable_volumes

  return if volumes_to_remove.empty?

  puts "Removing the following volumes: #{volumes_to_remove.join(", ")}"

  system "docker volume rm #{volumes_to_remove.join(" ")}"
end

#core_docker_templatesObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/wellcar/commands/base.rb', line 10

def core_docker_templates
   master_key = File.exist?("config/credentials/production.key") ?
     File.read("config/credentials/production.key") :
     nil

  [
    Wellcar::Templates::Dockerfile.new(ruby_version, app_name, use_bundler_2),
    Wellcar::Templates::DockerStack.new(app_name, ),
    Wellcar::Templates::EnvDevelopmentDatabase.new(app_name),
    Wellcar::Templates::EnvDevelopmentWeb.new,
    Wellcar::Templates::EnvProductionWeb.new(master_key),
    Wellcar::Templates::EnvProductionDatabase.new(app_name),
    Wellcar::Templates::Dockerignore.new,
    Wellcar::Templates::DockerEntrypoint.new,
    Wellcar::Templates::BuildProductionImage.new(app_name, ),
    Wellcar::Templates::ReverseProxyConf.new(domain_name)
  ]
end

#create_directoriesObject



29
30
31
32
33
34
# File 'lib/wellcar/commands/base.rb', line 29

def create_directories
  FileUtils.mkdir_p "config"
  FileUtils.mkdir_p "bin"
  FileUtils.mkdir_p ".env/development"
  FileUtils.mkdir_p ".env/production"
end

#create_wellcar_folderObject



45
46
47
48
49
50
# File 'lib/wellcar/commands/base.rb', line 45

def create_wellcar_folder
  return if Dir.exist? ".wellcar"

  Dir.mkdir ".wellcar"
  FileUtils.touch ".wellcar/.keep"
end

#write_filesObject



36
37
38
39
40
41
42
43
# File 'lib/wellcar/commands/base.rb', line 36

def write_files
  files_before_docker = Dir['*']
  
  system "curl -o bin/wait-for https://raw.githubusercontent.com/mrako/wait-for/master/wait-for"

  docker_files.each(&:write)
  puts "Wellcar created:\n#{Dir['*'] - files_before_docker}\n"
end