Skip to content

Commit

Permalink
add new docker based sync example
Browse files Browse the repository at this point in the history
  • Loading branch information
equinox0815 committed Oct 22, 2023
1 parent b02ccfe commit 61550f4
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 5 deletions.
12 changes: 7 additions & 5 deletions contrib/sync/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
FROM golang:1.21 as builder
ARG GOKR_RSYNC_VERSION=0.1.0
RUN CGO_ENABLED=0 go install github.com/gokrazy/rsync/cmd/gokr-rsync@v${GOKR_RSYNC_VERSION} github.com/gokrazy/rsync/cmd/gokr-rsyncd@v${GOKR_RSYNC_VERSION}
FROM alpine

FROM scratch
COPY --from=builder /go/bin/ /
RUN set -x\
&& apk add --no-cache tini openssh-server openssh-client rsync nss_wrapper

COPY entrypoint.sh /

ENTRYPOINT ["/sbin/tini", "--", "/entrypoint.sh"]
1 change: 1 addition & 0 deletions contrib/sync/client/config/group
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sync:x:1000:
1 change: 1 addition & 0 deletions contrib/sync/client/config/passwd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sync:x:1000:1000::/home:/bin/sh
10 changes: 10 additions & 0 deletions contrib/sync/client/config/ssh_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Host whawty-auth-master
Hostname 192.0.2.1
Port 1234
User sync
IdentityFile /config/id_ed25519
IdentitiesOnly yes
UserKnownHostsFile /config/known_hosts
ControlMaster auto
ControlPath /run/ssh-master/whawty-auth-master
ControlPersist 300
4 changes: 4 additions & 0 deletions contrib/sync/client/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

BASE_D=$(realpath "${BASH_SOURCE%/*}")
exec docker run -it --rm -u 1000:1000 -v "$BASE_D/store:/store" -v "$BASE_D/config:/config:ro" --mount type=tmpfs,destination=/run/ssh-master whawty-auth/sync client 5
30 changes: 30 additions & 0 deletions contrib/sync/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh

MODE=$1
CLIENT_SLEEP=$2
if [ -z "$MODE" ]; then
MODE="server"
fi
if [ -z "$CLIENT_SLEEP" ]; then
CLIENT_SLEEP=60
fi

export LD_PRELOAD=libnss_wrapper.so
export NSS_WRAPPER_PASSWD=/config/passwd
export NSS_WRAPPER_GROUP=/config/group

case "$MODE" in
server)
exec /usr/sbin/sshd -D -e -f /config/sshd_config
;;
client)
while
/usr/bin/rsync -rtpW --delete --delete-delay --delay-updates --partial-dir=.tmp -e 'ssh -F /config/ssh_config' 'rsync://whawty-auth-master/store' '/store' || /bin/true
do sleep "$CLIENT_SLEEP"; done
;;
*)
echo "unknown mode $MODE, must be server or client"
;;
esac

return 1
1 change: 1 addition & 0 deletions contrib/sync/server/config/group
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sync:x:1000:
1 change: 1 addition & 0 deletions contrib/sync/server/config/passwd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sync:x:1000:1000::/home:/bin/sh
5 changes: 5 additions & 0 deletions contrib/sync/server/config/rsyncd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[store]
path = /store
comment = whawty auth store
read only = yes
use chroot = no
29 changes: 29 additions & 0 deletions contrib/sync/server/config/sshd_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Port 1234
ListenAddress 0.0.0.0
ListenAddress ::

HostKey /config/ssh_host_ed25519_key
PidFile none

PermitRootLogin no
PubkeyAuthentication yes

HostbasedAuthentication no
PasswordAuthentication no
PermitEmptyPasswords no
KbdInteractiveAuthentication no

AllowAgentForwarding no
AllowTcpForwarding no
GatewayPorts no
X11Forwarding no
PermitTTY no
UseDNS no
PermitTunnel no
AllowStreamLocalForwarding no
AllowTcpForwarding no

ForceCommand /usr/bin/rsync --server --daemon --config /config/rsyncd.conf .

AllowUsers sync
AuthorizedKeysFile /config/authorized_keys
4 changes: 4 additions & 0 deletions contrib/sync/server/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

BASE_D=$(realpath "${BASH_SOURCE%/*}")
exec docker run -it --rm -p 4022:4022 -u 1000:1000 -v "$BASE_D/store:/store:ro" -v "$BASE_D/config:/config:ro" whawty-auth/sync server

0 comments on commit 61550f4

Please sign in to comment.