Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cache-from option #159

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,16 @@ RUN --mount=type=secret,id=GITHUB_TOKEN \
rm -rf /usr/local/bundle/cache
```

### Using cache at image build

Specifying a Docker tag allows you to use the cache to save container build time:

```yaml
builder:
cache_from:
- latest # 37s/hey:latest
```

### Using command arguments for Traefik

You can customize the traefik command line:
Expand Down
10 changes: 9 additions & 1 deletion lib/mrsk/commands/builder/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def pull
end

def build_options
[ *build_tags, *build_labels, *build_args, *build_secrets, *build_dockerfile ]
[ *build_tags, *build_labels, *build_args, *build_secrets, *build_cache_from, *build_dockerfile ]
end

def build_context
Expand All @@ -35,6 +35,10 @@ def build_secrets
argumentize "--secret", secrets.collect { |secret| [ "id", secret ] }
end

def build_cache_from
argumentize "--cache-from", cache_from_tags.collect { |tag| "#{config.repository}:#{tag}" }
end

def build_dockerfile
argumentize "--file", dockerfile
end
Expand All @@ -47,6 +51,10 @@ def secrets
(config.builder && config.builder["secrets"]) || []
end

def cache_from_tags
(config.builder && config.builder["cache_from"]) || []
end

def dockerfile
(config.builder && config.builder["dockerfile"]) || "Dockerfile"
end
Expand Down
7 changes: 7 additions & 0 deletions test/commands/builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ class CommandsBuilderTest < ActiveSupport::TestCase
builder.push.join(" ")
end

test "build cache_from" do
builder = new_builder_command(builder: { "cache_from" => ["master", "1.0.0"] })
assert_equal \
"-t dhh/app:123 -t dhh/app:latest --label service=\"app\" --cache-from dhh/app:master --cache-from dhh/app:1.0.0 --file Dockerfile",
builder.target.build_options.join(" ")
end

private
def new_builder_command(additional_config = {})
Mrsk::Commands::Builder.new(Mrsk::Configuration.new(@config.merge(additional_config), version: "123"))
Expand Down