Skip to content
This repository has been archived by the owner on Oct 30, 2019. It is now read-only.

Commit

Permalink
(MAINT) allow specifying container user
Browse files Browse the repository at this point in the history
Extracted out of PR with multiple features in
5c194e4
and added tests and doc.
  • Loading branch information
garethr committed Feb 20, 2017
1 parent efe178e commit 8a40e09
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -322,6 +322,7 @@ USAGE: puppet docker <action> [--from STRING]
[--[no-]inventory]
[--hiera-config STRING]
[--hiera-data STRING]
[--image-user STRING]
[--puppetfile STRING]
[--image-name STRING]
[--config-file STRING]
Expand All @@ -347,6 +348,8 @@ OPTIONS:
--hiera-config STRING - Hiera config file to use
--hiera-data STRING - Hieradata directory to use
--image-name STRING - The name of the resulting image
--image-user STRING - Specify a user to be used to run the
container process
--[no-]inventory - Enable or disable the generation of an
inventory file at /inventory.json
--labels KEY=VALUE - A set of labels to be applied to the
Expand Down
4 changes: 4 additions & 0 deletions lib/puppet_x/puppetlabs/imagebuilder_face.rb
Expand Up @@ -46,6 +46,10 @@ class ImageBuilder::Face < Puppet::Face
summary 'The default entrypoint for the resulting image'
end

option '--image-user STRING' do
summary 'Specify a user to be used to run the container process'
end

option '--labels KEY=VALUE' do
summary 'A set of labels to be applied to the resulting image'
end
Expand Down
17 changes: 17 additions & 0 deletions spec/support/examples/imagebuilder.rb
Expand Up @@ -20,6 +20,9 @@
it 'the original from value' do
expect(context).to include(from: args[:from])
end
it 'no user set' do
expect(context[:image_user]).to be_nil
end
it 'the original image_name value' do
expect(context).to include(image_name: args[:image_name])
end
Expand Down Expand Up @@ -51,6 +54,20 @@
end
end

context 'with a user set' do
let(:user) { 'diane' }
let(:args) do
{
from: from,
image_name: image_name,
image_user: user,
}
end
it 'should by include some label-schema labels' do
expect(context[:image_user]).to eq(user)
end
end

context 'with a single env value specified' do
let(:args) do
{
Expand Down
4 changes: 4 additions & 0 deletions templates/Dockerfile.erb
@@ -1,6 +1,8 @@
<% if from %>FROM <%= from %><% end %>
<% if maintainer %>MAINTAINER <%= maintainer %><% end %>
<% if image_user && !image_user.empty? %>USER root<% end %>
<% if environment %>ENV <% environment.each do |name, value| %><%= name.upcase %>="<%= value %>" <% end %><% end %>
<% if rocker %>MOUNT /opt/puppetlabs /etc/puppetlabs /root/.gem<% end %>
Expand Down Expand Up @@ -138,4 +140,6 @@ RUN <%= puppet_path %> module install puppetlabs-inventory && \
<% if entrypoint && !entrypoint.empty? %>ENTRYPOINT <%= entrypoint.to_s %><% end %>
<% if cmd && !cmd.empty? %>CMD <%= cmd.to_s %><% end %>
<% if image_user && !image_user.empty? %>USER <%= image_user.to_s %><% end %>
<% if rocker %>TAG <%= image_name %><% end %>

0 comments on commit 8a40e09

Please sign in to comment.