Commit 6c67b4d
committed
feat(Docker): add Docker support with multi-arch builds and automated publishing workflow
7m ago
add a awesome Dockerfile and github action that will build the image and publish it to dockerhub
only use the imapbackup38.py
I'll scan the repository to understand imapbackup38.py's dependencies and runtime requirements so the Dockerfile can be correct, and then add a Dockerfile, a .dockerignore, and a GitHub Actions workflow that builds and publishes to Docker Hub.
I'll create three files:
Dockerfile to containerize
imapbackup38.py
with sane defaults and optional GPG/AWS CLI support.
.dockerignore to keep the image small.
GitHub Actions workflow to build multi-arch images and push to Docker Hub using repo secrets.
I'll also set up a small TODO list to track progress.
1
Create Dockerfile that runs imapbackup38.py as entrypoint (non-root, tini, optional GPG and AWS CLI)
Add .dockerignore to reduce build context (ignore backups, __pycache__, VCS)
Add GitHub Actions workflow to build multi-arch image and publish to Docker Hub
I'll create three new files:
Dockerfile at the repository root that only includes and runs
imapbackup38.py
, with optional GPG and AWS CLI support.
.dockerignore to restrict build context to
imapbackup38.py
and docker files.
A GitHub Actions workflow to build multi-arch images and push to Docker Hub using repository secrets.
I'll now generate these files.
Dockerfile
new
+51
.dockerignore
new
+10
docker-publish.yml
new
+61
Added Docker support and CI publish
I created:
Dockerfile
.dockerignore
.github/workflows/docker-publish.yml
The image only includes and runs
imapbackup38.py
. Optional tools for features used by the script are preinstalled: gnupg (GPG encryption) and awscli (S3 upload).
Files
imapbackup/Dockerfile
Base: python:3.12-slim
Installs: tini, gnupg, ca-certificates, awscli
Copies only
imapbackup38.py
Runs as non-root user app
Default workdir: /data (mount your backup volume here)
Entry: tini -- /app/imapbackup38.py
Labels include repo and revision when passed via build-args
imapbackup/.dockerignore
Excludes everything by default, allows:
imapbackup38.py
,
Dockerfile
,
.dockerignore
,
LICENSE
,
README.md
imapbackup/.github/workflows/docker-publish.yml
Builds multi-arch images (linux/amd64, linux/arm64) with Buildx
Pushes to Docker Hub on pushes to
main
/master and on tags
Uses metadata-action for sensible tags (branch, tag, SHA)
Reads Docker Hub credentials from repo secrets
How to use
Build locally
bash
docker build \
--build-arg GIT_SHA=$(git rev-parse --short HEAD) \
--build-arg GITHUB_REPOSITORY=$(git config --get remote.origin.url | sed 's|.*github.com[:/]\(.*\)\.git|\1|') \
-t youruser/imapbackup:dev .
Run
bash
# Backup mboxes into ./backup on host
docker run --rm -it \
-v "$PWD/backup:/data" \
youruser/imapbackup:dev \
--ssl \
--server imap.example.com:993 \
--user you@example.com \
--pass '@/run/secrets/imap_pass' \
--mbox-dir /data \
--nospinner
GPG encryption (optional)
bash
# mount your GPG keyring so the recipient key is available inside
docker run --rm -it \
-v "$PWD/backup:/data" \
-v "$HOME/.gnupg:/home/app/.gnupg:ro" \
youruser/imapbackup:dev \
--gpg-encrypt --gpg-recipient you@example.com \
... usual flags ...
S3 upload (optional)
bash
docker run --rm -it \
-v "$PWD/backup:/data" \
youruser/imapbackup:dev \
--s3-upload \
--s3-endpoint https://s3.example.com \
--s3-bucket my-bucket \
--s3-access-key AKIA... \
--s3-secret-key SECRET... \
--s3-prefix backups/imap \
... usual flags ...
GitHub Actions setup
Create repo secrets:
DOCKERHUB_USERNAME: your Docker Hub username
DOCKERHUB_TOKEN: a Docker Hub access token with write permissions
Default image name: docker.io/${DOCKERHUB_USERNAME}/imapbackup
Pushes to
main
/master or tags will build and publish. PRs build but do not push.
Notes
The image writes mboxes to /data by default. Mount a host directory there with -v $PWD/backup:/data or another path of your choice.
Only
imapbackup38.py
is copied into the image as requested.
Summary
Implemented Dockerfile, .dockerignore, and GitHub Actions workflow for multi-arch build and automatic publish to Docker Hub.
Image runs only
imapbackup38.py
, includes optional tools needed by the script.
Provide run/build instructions and required repository secrets.1 parent 5293031 commit 6c67b4d
File tree
3 files changed
+119
-0
lines changed- .github/workflows
3 files changed
+119
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
0 commit comments