Skip to content

Commit

Permalink
add dockerfile to build container
Browse files Browse the repository at this point in the history
  • Loading branch information
ansemjo committed Nov 20, 2018
2 parents 64c4842 + 0539349 commit 06f6837
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2018 Anton Semjonov
# Licensed under the MIT License

FROM python:alpine

# default cron interval
ENV MINUTES=15

# copy init script which execs crond
COPY assets/container/init.sh /init.sh
ENTRYPOINT ["/bin/ash", "/init.sh", "/usr/bin/imapfetch.py"]
CMD ["/config"]

# copy imapfetch script
COPY imapfetch/imapfetch.py /usr/bin/imapfetch.py
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ decently fast for example.
Make sure you run a decently modern Python 3 (anything newer than `3.5` _should_ work, development
was done on `3.7`).

TODO: `deb`, `rpm`

### PIP

Install the package via `pip` by running:
Expand All @@ -126,6 +124,28 @@ Or use the `PKGBUILD` in `master` to build `imapfetch-git` locally:

makepkg -i

### RPM, DEB, APK

Other packages can be built with [ansemjo/fpm](https://hub.docker.com/r/ansemjo/fpm/) using the
`makefile` or downloaded from the [releases page](https://github.com/ansemjo/imapfetch/releases).
They can then be installed locally with `yum`/`dnf`/`dpkg` etc.

make packages

## CONTAINER

The script can also be scheduled to run regularly with cron inside a container with
[ansemjo/imapfetch](https://hub.docker.com/r/ansemjo/imapfetch/). Download or build the image with
the provided `Dockerfile`, then run the container with `docker` or `podman`:

podman run -d \
-v ~/.config/imapfetch.cfg:/config \
-v ~/Documents/Email-Archive:/archive \
ansemjo/imapfetch

Mount your configuration file and the root directory of your configured archives in the container as
seen above.

## LICENSE

The script is licensed under the [MIT License](LICENSE).
24 changes: 24 additions & 0 deletions assets/container/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/ash

# Copyright (c) 2018 Anton Semjonov
# Licensed under the MIT License

# command is given as parameter
export COMMAND="${*:?command required}"

# assemble cron schedule from env
# either use '-e MINUTES=n' to run test every n minutes
# or define the complete schedule part with '-e SCHEDULE=...'
export SCHEDULE="${SCHEDULE:-"*/$MINUTES * * * *"}"

# install crontab
echo "$SCHEDULE $COMMAND" | crontab -

# run command once before schedule
${SHELL:-sh} -c "$COMMAND" || {
echo "command error. exiting."
exit 1
}

# exec crontab in foreground
exec crond -f
13 changes: 13 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,17 @@ package-% : install
--maintainer $(PKGAUTHOR) --license $(PKGLICENSE) --url $(PKGURL)

# build all package formats with fpm
.PHONY: packages
packages : $(addprefix package-,$(PKGFORMATS))

# container runtime
CONTAINER = podman
IMAGENAME = ansemjo/$(PKGNAME)

# build and tag container
.PHONY: container
container:
$(CONTAINER) build \
-t $(IMAGENAME):latest \
-t $(IMAGENAME):$(PKGVERSION) \
.

0 comments on commit 06f6837

Please sign in to comment.