Skip to content

Commit

Permalink
Merge pull request #8 from joez/develop
Browse files Browse the repository at this point in the history
release v0.6
  • Loading branch information
joez authored May 23, 2020
2 parents 2a14649 + 9e6fdf1 commit e2034ab
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 8 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
/MYMETA.*
/ext
/bin/cpanm
Dockerfile*
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.6 2017-09-23
- gex: add more ticket id prefix
- run container as non-root user
- fix typo in Manifest.pm

0.5 2017-08-30
- gex: support file path for manifest report
- gex: adjust column width in the meta worksheet
Expand Down
34 changes: 30 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
FROM perl:5.24

MAINTAINER Joe Zheng
# docker run -it -v $(pwd):/work -e USER_ID=$(id -u) -e GROUP_ID=$(id -g) ptk
LABEL author=joez

COPY . /var/ptk
RUN echo 'source /var/ptk/envsetup' >> ~/.bashrc && exec bash --login
# deploy gosu
RUN set -eux; \
arch=$(dpkg --print-architecture | awk -F- '{ print $NF }'); \
base="https://github.com/tianon/gosu/releases/download"; \
version=1.12; \
export GNUPGHOME="$(mktemp -d)"; \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
wget -O /usr/local/bin/gosu "${base}/${version}/gosu-${arch}"; \
wget -O /usr/local/bin/gosu.asc "${base}/${version}/gosu-${arch}.asc"; \
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
gpgconf --kill all; \
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
chmod +x /usr/local/bin/gosu; \
gosu --version; \
gosu nobody true

# deploy ptk
COPY . /opt/ptk
RUN ["/bin/bash", "-c", "source /opt/ptk/envsetup"]

# add user, its uid/gid will be modified by docker-entry later
RUN groupadd -g 1000 -r joe \
&& useradd -u 1000 -l -m -r -g joe -s /bin/bash -d /home/joe joe
RUN echo 'source /opt/ptk/envsetup' >> /home/joe/.bashrc

# here is the workspace
RUN mkdir -p /work && chown joe:joe /work
VOLUME ["/work"]
WORKDIR /work

CMD ["bash"]
ENTRYPOINT ["/opt/ptk/docker-entry"]
CMD ["bash"]
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ Build a Docker image named `ptk`

Start a container and mount current directory as the workspace

docker run -it --rm -v `pwd`:/work ptk
docker run -it --rm -v $(pwd):/work -e USER_ID=$(id -u) -e GROUP_ID=$(id -g) ptk

The `USER_ID` and `GROUP_ID` are used to make the uid/gid of the container matching the current host user, so that the files created has the right ownership

# See also

Expand Down
2 changes: 1 addition & 1 deletion bin/gex
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@ sub parse_commit_message {
next;
}

if (/^(?:Bug|Issue|UTP-Id):\s*(.+)$/) {
if (/^(?:Bug|Issue|UTP-Id|Tracked-On):\s*(.+)$/) {
for (split /\s/, $1) {
if (/([A-Z-]*\d+)/) {
push @{$d->{ticket_ids}}, $1;
Expand Down
28 changes: 28 additions & 0 deletions docker-entry
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
set -e

# This allows the docker container manipulating files in the shared
# volume owned by the USER_ID:GROUP_ID, e.g.
#
# docker run -it -e USER_ID=$(id -u) -e GROUP_ID=$(id -g) ptk
#
# See also: https://github.com/moby/moby/issues/7198

# allow the container to be started with "--user"
if [[ "$(id -u)" == '0' ]]; then
# if the user is not specified, default as 1000:1000
[[ -z $USER_ID ]] && USER_ID=1000
[[ -z $GROUP_ID ]] && GROUP_ID=1000

NAME=joe

echo "Modify uid/gid of $NAME to $USER_ID:$GROUP_ID"
groupmod -g $GROUP_ID $NAME
usermod -u $USER_ID $NAME
chown -R $NAME:$NAME /home/$NAME

exec gosu $NAME:$NAME "$@"
else
# do as-is as the user required
exec "$@"
fi
2 changes: 1 addition & 1 deletion lib/Ptk.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package Ptk;
use Ptk::Base -base;

our $VERSION = '0.5';
our $VERSION = '0.6';

1;
__END__
2 changes: 1 addition & 1 deletion lib/Ptk/Manifest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ sub _parse {
my $self = shift;
my $file = shift or croak('no file');

crock("can't access manifest: $file") unless -e $file;
croak("can't access manifest: $file") unless -e $file;

my $dom = Mojo::DOM->new(_p($file)->slurp);
for my $e (_AM($dom)->children->each) {
Expand Down

0 comments on commit e2034ab

Please sign in to comment.