Skip to content

Entrypoint doesn't seem to be executed #12

Description

@wibimaster

Dockerspec Version

0.4.1

Ruby Version

ruby 2.3.4p301 (2017-03-30 revision 58214) [x86_64-linux]

Platform Details

Alpine Linux v3.4

Scenario

Try to build and test a Dockerfile with an entrypoint that create a user with Gosu.

Steps to Reproduce

Dockerfile:

FROM ubuntu:16.04

RUN apt-get update && apt-get install curl -y

RUN gpg --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4
RUN curl -o /usr/local/bin/gosu -SL "https://github.com/tianon/gosu/releases/download/1.4/gosu-$(dpkg --print-architecture)" \
    && curl -o /usr/local/bin/gosu.asc -SL "https://github.com/tianon/gosu/releases/download/1.4/gosu-$(dpkg --print-architecture).asc" \
    && gpg --verify /usr/local/bin/gosu.asc \
    && rm /usr/local/bin/gosu.asc \
    && chmod +x /usr/local/bin/gosu

COPY entrypoint.sh /usr/local/bin/entrypoint.sh

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

CMD ["bash"]

entrypoint.sh:

#!/bin/bash

# Add local user
# Either use the LOCAL_USER_ID if passed in at runtime or fallback

IFS=':' read -r -a array <<< "$LOCAL_USER_ID"
uid=$([[ ! -z ${array[0]} ]] && echo ${array[0]} || echo 9001);
gid=$([[ ! -z ${array[1]} ]] && echo ${array[1]} || echo 9001);

echo "Starting with user : UID ${uid} - GID ${gid}"

if [ ! $(getent group $gid) ]; then
    echo "GID ${gid} does not exists"
    groupadd -g $gid -o group
    echo "GID ${gid} created"
fi

useradd --shell /bin/bash -u $uid -o -c "" -m user
echo "UID ${uid} created"

export HOME=/home/user

exec /usr/local/bin/gosu $uid:$gid "$@"

spec/image_spec.rb:

require 'dockerspec/serverspec'

set :os, family: :ubuntu
set :backend, :docker

$project_root = File.expand_path(File.join(__FILE__, '..', '..'))

describe 'My Dockerfile' do
  describe docker_build($project_root) do
    it { should have_user 'nobody' }
    it { should have_entrypoint '/usr/local/bin/entrypoint.sh' }

    describe docker_run(described_image, env: {"LOCAL_USER_ID" => "6000:6000"}) do
      describe command('id -u') do
      	its(:stdout) { should match /6000/ }
      end
    end
  end
end

Expected Result

id -u command should returns 6000 (or, if env fail, 9001)

Actual Result

id -u command returns 0 (root)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions