Module: Kamal::Commands::App::Assets

Included in:
Kamal::Commands::App
Defined in:
lib/kamal/commands/app/assets.rb

Instance Method Summary collapse

Instance Method Details

#clean_up_assetsObject



30
31
32
33
34
# File 'lib/kamal/commands/app/assets.rb', line 30

def clean_up_assets
  chain \
    find_and_remove_older_siblings(role.asset_extracted_directory),
    find_and_remove_older_siblings(role.asset_volume_directory)
end

#extract_assetsObject



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/kamal/commands/app/assets.rb', line 2

def extract_assets
  asset_container = "#{role.container_prefix}-assets"

  combine \
    make_directory(role.asset_extracted_directory),
    [ *docker(:stop, "-t 1", asset_container, "2> /dev/null"), "|| true" ],
    docker(:run, "--name", asset_container, "--detach", "--rm", "--entrypoint", "sleep", config.absolute_image, "1000000"),
    docker(:cp, "-L", "#{asset_container}:#{role.asset_path}/.", role.asset_extracted_directory),
    docker(:stop, "-t 1", asset_container),
    by: "&&"
end

#sync_asset_volumes(old_version: nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/kamal/commands/app/assets.rb', line 14

def sync_asset_volumes(old_version: nil)
  new_extracted_path, new_volume_path = role.asset_extracted_directory(config.version), role.asset_volume.host_path
  if old_version.present?
    old_extracted_path, old_volume_path = role.asset_extracted_directory(old_version), role.asset_volume(old_version).host_path
  end

  commands = [ make_directory(new_volume_path), copy_contents(new_extracted_path, new_volume_path) ]

  if old_version.present?
    commands << copy_contents(new_extracted_path, old_volume_path, continue_on_error: true)
    commands << copy_contents(old_extracted_path, new_volume_path, continue_on_error: true)
  end

  chain *commands
end