Skip to content

Commit

Permalink
convert to alpine
Browse files Browse the repository at this point in the history
  • Loading branch information
David Personette committed Oct 21, 2017
1 parent 645927c commit e6db043
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 101 deletions.
25 changes: 15 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
FROM debian:stretch
FROM alpine
MAINTAINER David Personette <dperson@gmail.com>

# Install samba
RUN export DEBIAN_FRONTEND='noninteractive' && \
apt-get update -qq && \
apt-get install -qqy --no-install-recommends procps samba samba-vfs-modules\
$(apt-get -s dist-upgrade|awk '/^Inst.*ecurity/ {print $2}') &&\
useradd -c 'Samba User' -d /tmp -M -r smbuser && \
RUN apk --no-cache add bash samba shadow && \
adduser -D -G users -H -g 'Samba User' -h /tmp smbuser && \
sed -i 's|^\( log file = \).*|\1/dev/stdout|' /etc/samba/smb.conf && \
sed -i 's|^\( load printers = \).*|\1no|' /etc/samba/smb.conf && \
sed -i 's|^\( printcap name = \).*|\1/dev/null|' /etc/samba/smb.conf && \
sed -i 's|^;*\( printing = \).*|\1bsd|' /etc/samba/smb.conf && \
sed -i 's|^\( unix password sync = \).*|\1no|' /etc/samba/smb.conf && \
sed -i '/Share Definitions/,$d' /etc/samba/smb.conf && \
echo ' security = user' >>/etc/samba/smb.conf && \
echo ' pam password change = yes' >>/etc/samba/smb.conf && \
echo ' map to guest = bad user' >>/etc/samba/smb.conf && \
echo ' usershare allow guests = yes' >>/etc/samba/smb.conf && \
echo ' create mask = 0664' >>/etc/samba/smb.conf && \
echo ' force create mode = 0664' >>/etc/samba/smb.conf && \
echo ' directory mask = 0775' >>/etc/samba/smb.conf && \
Expand All @@ -29,12 +31,15 @@ RUN export DEBIAN_FRONTEND='noninteractive' && \
echo ' recycle:versions = yes' >>/etc/samba/smb.conf && \
echo ' min protocol = SMB2' >>/etc/samba/smb.conf && \
echo '' >>/etc/samba/smb.conf && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/*
rm -rf /tmp/*

COPY samba.sh /usr/bin/

VOLUME ["/etc/samba"]
HEALTHCHECK --interval=60s --timeout=15s \
CMD smbclient -L '\\localhost\' -U 'guest%' -m SMB3
EXPOSE 137/udp 138/udp 139 445
VOLUME ["/etc/samba"]
ENTRYPOINT ["samba.sh"]
25 changes: 15 additions & 10 deletions Dockerfile.armv7hf → Dockerfile.armhf
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
FROM resin/armv7hf-debian:stretch
FROM resin/armhf-alpine
MAINTAINER David Personette <dperson@gmail.com>

# Install samba
RUN ["cross-build-start"]
RUN export DEBIAN_FRONTEND='noninteractive' && \
apt-get update -qq && \
apt-get install -qqy --no-install-recommends procps samba samba-vfs-modules\
$(apt-get -s dist-upgrade|awk '/^Inst.*ecurity/ {print $2}') &&\
useradd -c 'Samba User' -d /tmp -M -r smbuser && \
RUN apk --no-cache add bash samba shadow && \
adduser -D -G users -H -g 'Samba User' -h /tmp smbuser && \
sed -i 's|^\( log file = \).*|\1/dev/stdout|' /etc/samba/smb.conf && \
sed -i 's|^\( load printers = \).*|\1no|' /etc/samba/smb.conf && \
sed -i 's|^\( printcap name = \).*|\1/dev/null|' /etc/samba/smb.conf && \
sed -i 's|^;*\( printing = \).*|\1bsd|' /etc/samba/smb.conf && \
sed -i 's|^\( unix password sync = \).*|\1no|' /etc/samba/smb.conf && \
sed -i '/Share Definitions/,$d' /etc/samba/smb.conf && \
echo ' security = user' >>/etc/samba/smb.conf && \
echo ' pam password change = yes' >>/etc/samba/smb.conf && \
echo ' map to guest = bad user' >>/etc/samba/smb.conf && \
echo ' usershare allow guests = yes' >>/etc/samba/smb.conf && \
echo ' create mask = 0664' >>/etc/samba/smb.conf && \
echo ' force create mode = 0664' >>/etc/samba/smb.conf && \
echo ' directory mask = 0775' >>/etc/samba/smb.conf && \
Expand All @@ -30,13 +32,16 @@ RUN export DEBIAN_FRONTEND='noninteractive' && \
echo ' recycle:versions = yes' >>/etc/samba/smb.conf && \
echo ' min protocol = SMB2' >>/etc/samba/smb.conf && \
echo '' >>/etc/samba/smb.conf && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/*
rm -rf /tmp/*
RUN ["cross-build-end"]

COPY samba.sh /usr/bin/

VOLUME ["/etc/samba"]
HEALTHCHECK --interval=60s --timeout=15s \
CMD smbclient -L '\\localhost\' -U 'guest%' -m SMB3

EXPOSE 137/udp 138/udp 139 445

VOLUME ["/etc/samba"]

ENTRYPOINT ["samba.sh"]
42 changes: 0 additions & 42 deletions Dockerfile.rpi

This file was deleted.

14 changes: 1 addition & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ OR set local storage:
[users] allowed default:'all' or list of allowed users
[admins] allowed default:'none' or list of admin users
[writelist] list of users that can write to a RO share
-t "" Configure timezone
possible arg: "[timezone]" - zoneinfo timezone for container
-u "<username;password>[;ID;group]" Add a user
required arg: "<username>;<passwd>"
<username> for user
Expand All @@ -71,7 +69,7 @@ ENVIRONMENT VARIABLES (only available with `docker run`)
* `CHARMAP` - As above, configure character mapping
* `NMBD` - As above, enable nmbd
* `SMB` - As above, disable SMB2 minimum version
* `TZ` - As above, set a zoneinfo timezone, IE `EST5EDT`
* `TZ` - Set a timezone, IE `EST5EDT`
* `WIDELINKS` - As above, allow access wide symbolic links
* `WORKGROUP` - As above, set workgroup
* `USERID` - Set the UID for the samba server
Expand All @@ -87,18 +85,8 @@ Any of the commands can be run at creation with `docker run` or later with

### Setting the Timezone

sudo docker run -it -p 139:139 -p 445:445 -d dperson/samba -t EST5EDT

OR using `environment variables`

sudo docker run -it -e TZ=EST5EDT -p 139:139 -p 445:445 -d dperson/samba

Will get you the same settings as

sudo docker run -it --name samba -p 139:139 -p 445:445 -d dperson/samba
sudo docker exec -it samba samba.sh -t EST5EDT ls -AlF /etc/localtime
sudo docker restart samba

### Start an instance creating users and shares:

sudo docker run -it -p 139:139 -p 445:445 -d dperson/samba \
Expand Down
31 changes: 5 additions & 26 deletions samba.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ global() { local key="${1%%=*}" value="${1#*=}" file=/etc/samba/smb.conf
# Return: user(s) added to container
import() { local name id file="$1"
while read name id; do
useradd "$name" -M -u "$id"
adduser -D -H -u "$id" "$name"
done < <(cut -d: -f1,2 --output-delimiter=' ' $file)
pdbedit -i smbpasswd:$file
}
Expand Down Expand Up @@ -117,23 +117,6 @@ smb() { local file=/etc/samba/smb.conf
sed -i '/min protocol/d' $file
}

### timezone: Set the timezone for the container
# Arguments:
# timezone) for example EST5EDT
# Return: the correct zoneinfo file will be symlinked into place
timezone() { local timezone="${1:-EST5EDT}"
[[ -e /usr/share/zoneinfo/$timezone ]] || {
echo "ERROR: invalid timezone specified: $timezone" >&2
return
}

if [[ -w /etc/timezone && $(cat /etc/timezone) != $timezone ]]; then
echo "$timezone" >/etc/timezone
ln -sf /usr/share/zoneinfo/$timezone /etc/localtime
dpkg-reconfigure -f noninteractive tzdata >/dev/null 2>&1
fi
}

### user: add a user
# Arguments:
# name) for user
Expand All @@ -142,8 +125,8 @@ timezone() { local timezone="${1:-EST5EDT}"
# group) for user
# Return: user added to container
user() { local name="${1}" passwd="${2}" id="${3:-""}" group="${4:-""}"
[[ "$group" ]] && { grep -q "^$group:" /etc/group || groupadd "$group"; }
useradd "$name" -M ${id:+-u $id} ${group:+-g $group}
[[ "$group" ]] && { grep -q "^$group:" /etc/group || addgroup "$group"; }
adduser -D -H ${group:+-G $group} ${id:+-u $id} "$name"
echo -e "$passwd\n$passwd" | smbpasswd -s -a "$name"
}

Expand Down Expand Up @@ -193,8 +176,6 @@ Options (fields in '[]' are optional, '<>' are required):
[users] allowed default:'all' or list of allowed users
[admins] allowed default:'none' or list of admin users
[writelist] list of users that can write to a RO share
-t \"\" Configure timezone
possible arg: \"[timezone]\" - zoneinfo timezone for container
-u \"<username;password>[;ID;group]\" Add a user
required arg: \"<username>;<passwd>\"
<username> for user
Expand All @@ -214,7 +195,7 @@ The 'command' (if provided and valid) will be run instead of samba
[[ "${USERID:-""}" =~ ^[0-9]+$ ]] && usermod -u $USERID -o smbuser
[[ "${GROUPID:-""}" =~ ^[0-9]+$ ]] && groupmod -g $GROUPID -o smbuser

while getopts ":hc:g:i:nprs:St:u:Ww:" opt; do
while getopts ":hc:g:i:nprs:Su:Ww:" opt; do
case "$opt" in
h) usage ;;
c) charmap "$OPTARG" ;;
Expand All @@ -223,9 +204,8 @@ while getopts ":hc:g:i:nprs:St:u:Ww:" opt; do
n) NMBD="true" ;;
p) PERMISSIONS="true" ;;
r) recycle ;;
s) eval share $(sed 's/^\|$/"/g; s/;/" "/g' <<< $OPTARG) ;;
s) eval share $(sed 's/^/"/; s/$/"/; s/;/" "/g' <<< $OPTARG) ;;
S) smb ;;
t) timezone "$OPTARG" ;;
u) eval user $(sed 's|;| |g' <<< $OPTARG) ;;
w) workgroup "$OPTARG" ;;
W) widelinks ;;
Expand All @@ -238,7 +218,6 @@ shift $(( OPTIND - 1 ))
[[ "${CHARMAP:-""}" ]] && charmap "$CHARMAP"
[[ "${PERMISSIONS:-""}" ]] && perms
[[ "${RECYCLE:-""}" ]] && recycle
[[ "${TZ:-""}" ]] && timezone "$TZ"
[[ "${SMB:-""}" ]] && smb
[[ "${WORKGROUP:-""}" ]] && workgroup "$WORKGROUP"
[[ "${WIDELINKS:-""}" ]] && widelinks
Expand Down

0 comments on commit e6db043

Please sign in to comment.