Skip to content

Commit

Permalink
Updated to run as a non-nobody user due to some build issues with tha…
Browse files Browse the repository at this point in the history
…t. Added ability to specify UID and GID to chown ouput package as. Set dmakepkg to use this mode by default
  • Loading branch information
justin8 committed Jul 5, 2015
1 parent 177fd14 commit 48fca53
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 8 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ RUN mkdir -p /build
WORKDIR /build
RUN pacman -Syuq --noconfirm --needed base-devel && rm -rf /var/cache/pacman/pkg/*
RUN pacman -Syuq --noconfirm --needed git mercurial bzr subversion openssh && rm -rf /var/cache/pacman/pkg/*
RUN useradd -d /build build-user
ADD sudoers /etc/sudoers
ADD run.sh /run.sh

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ the final package file will be placed in the current directory when run with dma

The default flags sent to makepkg is `--force --syncdeps --noconfirm`
Both the dmakepkg and running the image directly support overriding default flags. Any additional flags at the end will be passed directly to makepkg instead of the ones outlined above.
It is also possible to pass the word `update` as the only argument (others after are ignored in this case). This will run a pacman -Syu before building the package. Useful if you haven't updated the master image yet but need to build against the latest libraries.
Passing '-p' will run a pacman -Syu before building the package. Useful if you haven't updated the master image yet but need to build against the latest libraries.
Passing '-u' will let you specify a UID to chown the file to before outputting it again. '-g' will let you also set the group (but requires -u as well or it will be ignored'
All remaining parameters will be passed directly through to makepkg.

The image can also be run manually. You need to bind the source directory with a PKGBUILD to /src (e.g. `-v $(pwd):/src` to mount current directory). The final package file will be placed in the bound directory.
The image can also be run manually. You need to bind the source directory with a PKGBUILD to /src (e.g. `-v $(pwd):/src` to mount current directory). The final package file will be placed in the bound directory, no other files will be modified
4 changes: 2 additions & 2 deletions dmakepkg
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ cleanup() {

trap cleanup SIGINT SIGTERM
docker run --name $name \
-v $(pwd):/src \
-v $(pwd):/src \
$CACHE \
-v /etc/makepkg.conf:/etc/makepkg.conf \
justin8/makepkg $@
justin8/makepkg -u $EUID -g $(id -g $EUID) $@
rc=$?

cleanup
Expand Down
51 changes: 48 additions & 3 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,46 @@
#!/bin/bash
set -x

usage() {
cat <<-EOF
usage: $(basename "$0") [OPTIONS] [makepkg parameters]
This wrapper for makepkg will default to running with '--force --syncdesp --noconfirm'.
Any unrecognized parameters will be passed directly through to makepkg.
OPTIONS:
-h Display this help
-p Run a pacman -Syu before building
-u UID to own any created package
-g GID to own any created package (Ignored unless UID is also provided)
EOF
}

while getopts ":g:hpu:" OPTION
do
case $OPTION in
g)
group=$OPTARG
;;
h)
usage
exit 0
;;
p)
update=true
;;
u)
user="$OPTARG"
;;
esac
done
shift $(( OPTIND -1 ))

# cp errors if there is a directory, even though we don't want to copy directories
cp /src/* /build
set -e
chown -R nobody. /build
if [[ $1 == update ]]
chown -R build-user. /build
if [[ -n $update ]]
then
pacman -Syu
else
Expand All @@ -18,7 +53,17 @@ else
fi
fi

su nobody -s /bin/bash -c "makepkg $flags"
su build-user -s /bin/bash -c "makepkg $flags"

if [[ -n $user ]]
then
chown="$user"
if [[ -n $group ]]
then
chown="${chown}:${group}"
fi
chown -R $chown /build
fi

# Don't fail if there is no pkg but custom flags were specified. i.e. -cors will only test, but not create a package
cp /build/*pkg.tar* /src &>/dev/null || [[ -n $@ ]]
2 changes: 1 addition & 1 deletion sudoers
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
root ALL=(ALL) ALL
nobody ALL=(ALL) NOPASSWD: ALL
build-user ALL=(ALL) NOPASSWD: ALL

0 comments on commit 48fca53

Please sign in to comment.