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

switch to s6-overlay to start smbd #85

Merged
merged 1 commit into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# syntax=docker/dockerfile:1

ARG ALPINE_VERSION=3.18
ARG S6_VERSION=2.2.0.3
ARG SAMBA_VERSION=4.18.5

FROM alpine:${ALPINE_VERSION}
FROM crazymax/alpine-s6:${ALPINE_VERSION}-${S6_VERSION}
ARG SAMBA_VERSION
RUN apk --update --no-cache add \
bash \
Expand All @@ -15,15 +16,11 @@ RUN apk --update --no-cache add \
yq \
&& rm -rf /tmp/*

COPY entrypoint.sh /entrypoint.sh
ENV TZ=UTC
COPY rootfs /

EXPOSE 445

VOLUME [ "/data" ]

ENTRYPOINT [ "/entrypoint.sh" ]
CMD [ "smbd", "-F", "--debug-stdout", "--no-process-group" ]
ENTRYPOINT [ "/init" ]

HEALTHCHECK --interval=30s --timeout=10s \
CMD smbclient -L \\localhost -U % -m SMB3
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ Image: crazymax/samba:latest
## Environment variables

* `TZ`: Timezone assigned to the container (default `UTC`)
* `CONFIG_FILE`: YAML configuration path (default `/data/config.yml`)
* `SAMBA_WORKGROUP`: NT-Domain-Name or [Workgroup-Name](https://www.samba.org/samba/docs/current/man-html/smb.conf.5.html#WORKGROUP). (default `WORKGROUP`)
* `SAMBA_SERVER_STRING`: [Server string](https://www.samba.org/samba/docs/current/man-html/smb.conf.5.html#SERVERSTRING) is the equivalent of the NT Description field. (default `Docker Samba Server`)
* `SAMBA_LOG_LEVEL`: [Log level](https://www.samba.org/samba/docs/current/man-html/smb.conf.5.html#LOGLEVEL). (default `0`)
* `SAMBA_FOLLOW_SYMLINKS`: Allow to [follow symlinks](https://www.samba.org/samba/docs/current/man-html/smb.conf.5.html#FOLLOWSYMLINKS). (default `yes`)
* `SAMBA_WIDE_LINKS`: Controls whether or not links in the UNIX file system may be followed by the server. (default `yes`)
* `SAMBA_HOSTS_ALLOW`: Set of hosts which are permitted to access a service. (default `127.0.0.0/8 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16`)
* `SAMBA_INTERFACES`: Allows you to override the default network interfaces list.
* `CONFIG_FILE`: YAML configuration path (default `/data/config.yml`)

> More info: https://www.samba.org/samba/docs/current/man-html/smb.conf.5.html

Expand All @@ -109,8 +109,9 @@ Image: crazymax/samba:latest

## Configuration

Before using this image you have to create the YAML configuration file `/data/config.yml` to be able to create users,
provide global options and add shares. Here is an example:
Before using this image you have to create the YAML configuration file
`/data/config.yml` to be able to create users, provide global options and add
shares. Here is an example:

```yaml
auth:
Expand Down
22 changes: 11 additions & 11 deletions entrypoint.sh → rootfs/etc/cont-init.d/01-config.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash
#!/usr/bin/with-contenv bash
# shellcheck shell=bash

TZ=${TZ:-UTC}
CONFIG_FILE=${CONFIG_FILE:-/data/config.yml}

Expand All @@ -11,8 +13,8 @@ SAMBA_HOSTS_ALLOW=${SAMBA_HOSTS_ALLOW:-127.0.0.0/8 10.0.0.0/8 172.16.0.0/12 192.
#SAMBA_INTERFACES=${SAMBA_INTERFACES:-eth0}

echo "Setting timezone to ${TZ}"
ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime
echo ${TZ} > /etc/timezone
ln -snf "/usr/share/zoneinfo/${TZ}" /etc/localtime
echo "${TZ}" > /etc/timezone

echo "Initializing files and folders"
mkdir -p /data/cache /data/lib
Expand Down Expand Up @@ -107,8 +109,8 @@ bind interfaces only = yes
EOL
fi

if [[ "$(yq --output-format=json e '(.. | select(tag == "!!str")) |= envsubst' $CONFIG_FILE 2>/dev/null | jq '.auth')" != "null" ]]; then
for auth in $(yq -j e '(.. | select(tag == "!!str")) |= envsubst' $CONFIG_FILE 2>/dev/null | jq -r '.auth[] | @base64'); do
if [[ "$(yq --output-format=json e '(.. | select(tag == "!!str")) |= envsubst' "${CONFIG_FILE}" 2>/dev/null | jq '.auth')" != "null" ]]; then
for auth in $(yq -j e '(.. | select(tag == "!!str")) |= envsubst' "${CONFIG_FILE}" 2>/dev/null | jq -r '.auth[] | @base64'); do
_jq() {
echo "${auth}" | base64 --decode | jq -r "${1}"
}
Expand All @@ -124,17 +126,17 @@ if [[ "$(yq --output-format=json e '(.. | select(tag == "!!str")) |= envsubst' $
done
fi

if [[ "$(yq --output-format=json e '(.. | select(tag == "!!str")) |= envsubst' $CONFIG_FILE 2>/dev/null | jq '.global')" != "null" ]]; then
for global in $(yq --output-format=json e '(.. | select(tag == "!!str")) |= envsubst' $CONFIG_FILE 2>/dev/null | jq -r '.global[] | @base64'); do
if [[ "$(yq --output-format=json e '(.. | select(tag == "!!str")) |= envsubst' "${CONFIG_FILE}" 2>/dev/null | jq '.global')" != "null" ]]; then
for global in $(yq --output-format=json e '(.. | select(tag == "!!str")) |= envsubst' "${CONFIG_FILE}" 2>/dev/null | jq -r '.global[] | @base64'); do
echo "Add global option: $(echo "$global" | base64 --decode)"
cat >> /etc/samba/smb.conf <<EOL
$(echo "$global" | base64 --decode)
EOL
done
fi

if [[ "$(yq --output-format=json e '(.. | select(tag == "!!str")) |= envsubst' $CONFIG_FILE 2>/dev/null | jq '.share')" != "null" ]]; then
for share in $(yq --output-format=json e '(.. | select(tag == "!!str")) |= envsubst' $CONFIG_FILE 2>/dev/null | jq -r '.share[] | @base64'); do
if [[ "$(yq --output-format=json e '(.. | select(tag == "!!str")) |= envsubst' "${CONFIG_FILE}" 2>/dev/null | jq '.share')" != "null" ]]; then
for share in $(yq --output-format=json e '(.. | select(tag == "!!str")) |= envsubst' "${CONFIG_FILE}" 2>/dev/null | jq -r '.share[] | @base64'); do
_jq() {
echo "${share}" | base64 --decode | jq -r "${1}"
}
Expand Down Expand Up @@ -193,5 +195,3 @@ if [[ "$(yq --output-format=json e '(.. | select(tag == "!!str")) |= envsubst' $
fi

testparm -s

exec "$@"
11 changes: 11 additions & 0 deletions rootfs/etc/cont-init.d/02-svc-smbd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/with-contenv sh
# shellcheck shell=sh

mkdir -p /etc/services.d/smbd

cat > /etc/services.d/smbd/run <<EOL
#!/usr/bin/execlineb -P
with-contenv
smbd -F --debug-stdout --no-process-group
EOL
chmod +x /etc/services.d/smbd/run