Skip to content

Commit

Permalink
docker: Build and start AppleTalk services, GitHub #1447
Browse files Browse the repository at this point in the history
  • Loading branch information
rdmark committed Sep 11, 2024
1 parent 9bdcc1c commit 0b554ba
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 20 deletions.
51 changes: 35 additions & 16 deletions DOCKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ For simplicity, exactly one user, one shared volume, and one Time Machine volume
Make sure you have Docker Engine installed, then build the netatalk container:

```
docker build -t netatalk3 .
docker build -t netatalk:latest .
```

Alternatively, fetch a pre-built docker container from [Docker Hub](https://hub.docker.com/u/netatalk).
Alternatively, pull a pre-built Docker container from [Docker Hub](https://hub.docker.com/u/netatalk).

## How to Run

Expand All @@ -23,7 +23,9 @@ Without this, the shared volume be stored in volatile storage that is lost upon

You can use the sample [docker-compose.yml](https://github.com/Netatalk/netatalk/blob/main/docker-compose.yml) that is distributed with this source code.

Below follows a sample `docker run` command. Substitute `/path/to/share` with an actual path on your file system with appropriate permissions, and `AFP_USER` and `AFP_PASS` with the appropriate user and password.
Below follows a sample `docker run` command. Substitute `/path/to/share` with an actual path on your file system with appropriate permissions, and `AFP_USER` and `AFP_PASS` with the appropriate user and password, and `ATALKD_INTERFACE` with the network interface to use for AppleTalk.

You also need to set the timezone with `TZ` to the [IANA time zone ID](https://nodatime.org/TimeZones) for your location, in order to get the correct time synchronized with the Timelord time server.

```
docker run --rm \
Expand All @@ -34,33 +36,50 @@ docker run --rm \
--volume "/var/run/dbus:/var/run/dbus" \
--env AFP_USER= \
--env AFP_PASS= \
--name netatalk netatalk3:latest
--env ATALKD_INTERFACE= \
--env TZ= \
--name netatalk netatalk:latest
```

## Constraints

In order to use Zeroconf service discovery, the container requires the "host" network driver and NET_ADMIN capabilities.
In order to use Zeroconf service discovery and the AppleTalk transport layer, the container requires the "host" network driver and NET_ADMIN capabilities.

Additionally, we rely on the host's DBUS for Zeroconf, achieved with a bind mount for `/var/run/dbus:/var/run/dbus`.

Note that the Dockerfile currently only supports Avahi for Zeroconf; no mDNS support at present.
## Printing

The CUPS administrative web app is running on port 631 in the container, which is exposed to the host machine by default when using the `host` network driver. This is used to configure CUPS compatible printers for printing from an old Mac or Apple IIGS.

You may have to restart papd (or the entire container) after adding a CUPS printer for it to be picked up as an AppleTalk printer.

## Environment Variables

### Mandatory

These are required to set the credentials used to authenticate with the file server.

- `AFP_USER`
- `AFP_PASS`
| Variable | Description |
| --- | --- |
| `AFP_USER` | Username to authenticate with the file server |
| `AFP_PASS` | Password to authenticate with the file server |

### Mandatory for AppleTalk

| Variable | Description |
| --- | --- |
| `ATALKD_INTERFACE` | The network interface to use for AppleTalk |
| `TZ` | The timezone to use for the container; must be a [IANA time zone ID](https://nodatime.org/TimeZones) |

### Optional

- `AFP_GROUP` <- group that owns the shared volume, and that AFP_USER gets assigned to
- `AFP_UID` <- specify user id of AFP_USER
- `AFP_GID` <- specify group id of AFP_GROUP
- `SERVER_NAME` <- the name of the server reported to Zeroconf
- `SHARE_NAME` <- the name of the file sharing volume
- `AFP_LOGLEVEL` <- the verbosity of logs; default is "info"
- `INSECURE_AUTH` <- when non-zero, enable the "Clear Text" and "Guest" UAMs
- `MANUAL_CONFIG` <- when non-zero, skip netatalk config file modification, allowing you to manually manage them
| Variable | Description |
|-----------------|----------------------------------------------------------------|
| `AFP_GROUP` | `AFP_USER`'s group that owns the shared volume |
| `AFP_UID` | Specify user id of `AFP_USER` |
| `AFP_GID` | Specify group id of `AFP_GROUP` |
| `SERVER_NAME` | The name of the server reported to Zeroconf |
| `SHARE_NAME` | The name of the file sharing volume |
| `AFP_LOGLEVEL` | The verbosity of logs; default is "info" |
| `INSECURE_AUTH` | When non-zero, enable the "ClearTxt" and "Guest" UAMs |
| `MANUAL_CONFIG` | When non-zero, enable manual management of config files |
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ENV LIB_DEPS \
avahi \
avahi-compat-libdns_sd \
bash \
cups \
db \
dbus \
dbus-glib \
Expand All @@ -22,6 +23,7 @@ ENV BUILD_DEPS \
acl-dev \
avahi-dev \
bison \
cups-dev \
curl \
db-dev \
dbus-dev \
Expand Down Expand Up @@ -61,6 +63,7 @@ USER builder

RUN meson setup build \
-Dwith-afpstats=false \
-Dwith-appletalk=true \
-Dwith-dbus-daemon-path=/usr/bin/dbus-daemon \
-Dwith-dbus-sysconf-path=/etc \
-Dwith-dtrace=false \
Expand Down
24 changes: 21 additions & 3 deletions contrib/shell_utils/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ elif [ ! -z "${AFP_USER}" ]; then
chown "${AFP_USER}:${AFP_USER}" /mnt/afpbackup
fi

if [ -f "/var/lock/netatalk" ]; then
echo "*** Removing residual lock files"
rm -f /var/lock/netatalk
fi

UAMS="uams_dhx.so uams_dhx2.so uams_randnum.so"

if [ ! -z "${INSECURE_AUTH}" ]; then
Expand All @@ -97,6 +102,7 @@ if [ -z "${MANUAL_CONFIG}" ]; then
echo "*** Configuring Netatalk"
cat <<EOF > /usr/local/etc/afp.conf
[Global]
appletalk = yes
log file = /var/log/afpd.log
log level = default:${AFP_LOGLEVEL:-info}
spotlight = yes
Expand All @@ -112,9 +118,21 @@ valid users = ${AFP_USER}
EOF
fi

if [ -f "/var/lock/netatalk" ]; then
echo "*** Removing residual lock file"
rm -f /var/lock/netatalk
if [ -z "${ATALKD_INTERFACE}" ]; then
echo "WARNING The AppleTalk services will NOT be started. The requirements are:"
echo "- The host OS has an AppleTalk networking stack, e.g. Linux or NetBSD."
echo "- The Docker container uses the \`host' network driver with the \`NET_ADMIN' capability."
echo "- The \`ATALKD_INTERFACE' environment variable is set to a valid host network interface."
else
echo "*** Configuring AppleTalk"
echo "${ATALKD_INTERFACE} ${ATALKD_OPTIONS}" > /usr/local/etc/atalkd.conf
echo "cupsautoadd:op=root:" > /usr/local/etc/papd.conf

echo "*** Starting AppleTalk services (this will take a minute)"
atalkd
papd
timelord -l
a2boot
fi

echo "*** Starting AFP server"
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
netatalk:
image: netatalk/netatalk3:latest
image: netatalk:latest
network_mode: "host"
cap_add:
- NET_ADMIN
Expand All @@ -11,6 +11,8 @@ services:
environment:
- "AFP_USER="
- "AFP_PASS="
- "ATALKD_INTERFACE="
- "TZ="
volumes:
afpshare:
afpbackup:

0 comments on commit 0b554ba

Please sign in to comment.