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

change of user inside container possible #9

Closed
wants to merge 15 commits into from
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ RUN ./build.sh -v


FROM debian
RUN apt update && apt install -y login mono-devel passwd && apt-get clean all

RUN apt update && apt install -y mono-devel && apt-get clean all
COPY --from=builder /usr/local/src/choco/build_output/chocolatey /opt/chocolatey
COPY bin/choco /usr/bin/choco
COPY bin/entrypoint.sh /root/entrypoint.sh

ENTRYPOINT ["/usr/bin/choco"]
CMD ["-h"]
ENTRYPOINT ["/root/entrypoint.sh"]
CMD ["-h"]
2 changes: 1 addition & 1 deletion bin/choco
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ function cleanup {
trap cleanup EXIT

# Wrap the mono choco.exe command
mono /opt/chocolatey/choco.exe "$@" --allow-unofficial
mono /opt/chocolatey/choco.exe "$@" --allow-unofficial
22 changes: 22 additions & 0 deletions bin/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
set -e

USER=root
if [ -n "$UID" ] && [ "$UID" -gt "100" ]; then
USER=chocolatey
GROUP=chocolatey

if [ -z "$GID" ] || [ "$GID" -lt "101" ]; then
GID=$UID
fi
groupadd -g $GID $GROUP

if [ "$UID" -lt "1000" ]; then
useradd -r -N -g $GID -s /bin/sh -u $UID $USER > /dev/null 2>&1
else
useradd -M -N -e '' -g $GID -s /bin/sh -u $UID $USER > /dev/null 2>&1
fi
fi

command="/usr/bin/choco $@"
su -c "$command" $USER
6 changes: 3 additions & 3 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ This directory contains an example package and Dockerfile.

## Generating a new package

The **mypackage** directory was generated using the following command. Note you will need to fix the ownership of these files as they are generated as the root user inside the container.
The **mypackage** directory was generated using the following command. Note, if you omit `-e UID=$UID` you will need to fix the ownership of these files as they are generated as the root user inside the container.

```bash
docker run --rm -v $PWD:$PWD -w $PWD linuturk/mono-choco new mypackage --version 1.0.0 --maintainer "Justin Phelps"
docker run --rm -e UID=$UID -v $PWD:$PWD -w $PWD linuturk/mono-choco new mypackage --version 1.0.0 --maintainer "Justin Phelps"
```

There are some modifications necessary to the generated nuspec file before it will generate a package. Check the file's git history to see those changes.
Expand All @@ -18,7 +18,7 @@ I recommend you use the Dockerfile example in this directory to pack your nuget

```bash
cd /path/to/mypackage
docker run --rm -v $PWD:$PWD -w $PWD linuturk/mono-choco pack mypackage.nuspec
docker run --rm -e UID=$UID -v $PWD:$PWD -w $PWD linuturk/mono-choco pack mypackage.nuspec
Chocolatey v0.10.9.0
Directory 'opt/chocolatey/lib' does not exist.

Expand Down
2 changes: 1 addition & 1 deletion example/mypackage/mypackage.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ This is a nuspec. It mostly adheres to https://docs.nuget.org/create/Nuspec-Refe
<files>
<!-- this section controls what actually gets packaged into the Chocolatey package -->
<file src="tools/**" target="tools" />
<!--Building from Linux? You may need this instead: <file src="tools/**" target="tools" />-->
<!--Building from Windows? You may need this instead: <file src="tools\**" target="tools" />-->
</files>
</package>