Skip to content

Instantly share code, notes, and snippets.

@mcrosson
Last active May 4, 2024 18:04
Show Gist options
  • Save mcrosson/b54f3092cd0d262dd59f2336fb2f3474 to your computer and use it in GitHub Desktop.
Save mcrosson/b54f3092cd0d262dd59f2336fb2f3474 to your computer and use it in GitHub Desktop.
imap-backup with email-oauth2-proxy
https://github.com/joeyates/imap-backup
https://github.com/simonrob/email-oauth2-proxy
https://joeyates.info/posts/back-up-gmail-accounts-with-imap-backup-using-email-oauth2-proxy/
use s6-overlay to run email-oauth2-proxy in background as a support app w/ various tuning to ensure its up and running ahead of running any backup commands
replace `_` in filenames with `/` to find paths relative to the `Dockerfile` directory
IMPORTANT: create config for email-oauth2-proxy before setting up imap-backup
# run in dedicated terminal
# be sure to test the connection so oauth gets initialized
# use 'mirror' if youre looking for deletes from upstream to happen locally
docker run --rm -ti -e S6_CMD_USE_TERMINAL=1 \
-v /var/imapbackup/config:/config \
-v /var/imapbackup/data:/data \
imap-backup-kmn:latest \
imap-backup setup -c /config/imap-backup.json
#!/bin/bash
cd /var/imapbackup
docker build --pull --no-cache -t imap-backup-kmn:latest .
# base imap-backup container image (this is being extended for oauth2 support)
FROM ghcr.io/joeyates/imap-backup:latest
# volumes for config and data
VOLUME /config
VOLUME /data
# init pkg mgr repo & update installed apps
RUN apk update && apk upgrade
# setup s6-overlay (needed for email-oauth2-proxy service/helper)
RUN apk add jq xz curl && \
export S6_RELEASE=$(curl -sX GET "https://api.github.com/repos/just-containers/s6-overlay/tags") && \
curl -L https://github.com/just-containers/s6-overlay/releases/latest/download/s6-overlay-x86_64.tar.xz \
-o /opt/s6-overlay-x86_64.tar.xz && \
curl -L https://github.com/just-containers/s6-overlay/releases/latest/download/s6-overlay-noarch.tar.xz \
-o /opt/s6-overlay-noarch.tar.xz && \
tar -C / -Jxpf /opt/s6-overlay-x86_64.tar.xz && \
tar -C / -Jxpf /opt/s6-overlay-noarch.tar.xz && \
rm /opt/s6-overlay*.tar.xz
# Ensure s6 doesnt pave env vars needed for ruby and more
ENV S6_KEEP_ENV 1
# Ensure oauth2 proxy is started /before/ CMD is executed
ENV S6_CMD_WAIT_FOR_SERVICES 1
# Copy the s6 related items to the container
ADD /root/ /
# install email-oauth2-proxy
RUN apk add python3 py3-pip \
&& python -m pip install emailproxy
# runtime setup
# s6-init will run the oauth2 proxy in the bg
# while allowing the imap-backup command to run as a one-shot
ENTRYPOINT ["/init"]
CMD ["imap-backup", "-c", "/config/imap-backup.json"]
#!/bin/sh
# must be executable (chmod a+x)
if [ `netstat -ln | grep 1993 | wc -l` -gt 0 ]; then exit 0; fi
exit 1
# simply touch this file, leave it empty (s6-overlay related setup)
#!/command/with-contenv sh
echo 3 > /run/service/email-oauth2-proxy/notification-fd
s6-notifyoncheck -d python -m emailproxy --no-gui --log-file /data/emailproxy.log --external-auth --cache-store /data/oauth.cache --config-file /config/emailproxy.config
# simply touch this file, leave it empty (s6-overlay related setup)
#!/bin/bash
#./build.sh
docker run --rm \
-v /var/imapbackup/config:/config \
-v /var/imapbackup/data:/data \
imap-backup-kmn:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment