Skip to content

Commit

Permalink
Merge pull request #14 from theohbrothers/feature/add-pingme-variants…
Browse files Browse the repository at this point in the history
…-for-notifications

Feature: Add `pingme` variants for notifications
  • Loading branch information
leojonathanoh authored Apr 15, 2023
2 parents ff1cb6f + ef0e434 commit 6fef260
Show file tree
Hide file tree
Showing 17 changed files with 613 additions and 36 deletions.
246 changes: 243 additions & 3 deletions .github/workflows/ci-master-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,126 @@ jobs:
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
build-1-4-4-pingme:
runs-on: ubuntu-latest
env:
VARIANT: 1.4.4-pingme
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Display system info (linux)
run: |
set -e
hostname
whoami
cat /etc/*release
lscpu
free
df -h
pwd
docker info
docker version
# See: https://github.com/docker/build-push-action/blob/v2.6.1/docs/advanced/cache.md#github-cache
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ env.VARIANT }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ env.VARIANT }}-
${{ runner.os }}-buildx-
# This step generates the docker tags
- name: Prepare
id: prep
run: |
set -e
# Get ref, i.e. <branch_name> from refs/heads/<branch_name>, or <tag-name> from refs/tags/<tag_name>. E.g. 'master' or 'v0.0.0'
REF=$( echo "${GITHUB_REF}" | rev | cut -d '/' -f 1 | rev )
# Get short commit hash E.g. 'abc0123'
SHA=$( echo "${GITHUB_SHA}" | cut -c1-7 )
# Generate docker image tags
# E.g. 'v0.0.0-<variant>' and 'v0.0.0-abc0123-<variant>'
# E.g. 'master-<variant>' and 'master-abc0123-<variant>'
REF_VARIANT="${REF}-${VARIANT}"
REF_SHA_VARIANT="${REF}-${SHA}-${VARIANT}"
# Pass variables to next step
echo "VARIANT_BUILD_DIR=$VARIANT_BUILD_DIR" >> $GITHUB_ENV
echo "VARIANT=$VARIANT" >> $GITHUB_ENV
echo "REF_VARIANT=$REF_VARIANT" >> $GITHUB_ENV
echo "REF_SHA_VARIANT=$REF_SHA_VARIANT" >> $GITHUB_ENV
- name: Login to Docker Hub registry
# Run on master and tags
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_REGISTRY_USER }}
password: ${{ secrets.DOCKERHUB_REGISTRY_PASSWORD }}

- name: Build (PRs)
# Run only on pull requests
if: github.event_name == 'pull_request'
uses: docker/build-push-action@v3
with:
context: variants/1.4.4-pingme
platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm64
push: false
tags: |
${{ github.repository }}:${{ env.REF_VARIANT }}
${{ github.repository }}:${{ env.REF_SHA_VARIANT }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

- name: Build and push (master)
# Run only on master
if: github.ref == 'refs/heads/master'
uses: docker/build-push-action@v3
with:
context: variants/1.4.4-pingme
platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm64
push: true
tags: |
${{ github.repository }}:${{ env.REF_VARIANT }}
${{ github.repository }}:${{ env.REF_SHA_VARIANT }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

- name: Build and push (release)
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v3
with:
context: variants/1.4.4-pingme
platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm64
push: true
tags: |
${{ github.repository }}:${{ env.VARIANT }}
${{ github.repository }}:${{ env.REF_VARIANT }}
${{ github.repository }}:${{ env.REF_SHA_VARIANT }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
build-1-4-4-restic:
runs-on: ubuntu-latest
env:
Expand Down Expand Up @@ -273,8 +393,128 @@ jobs:
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
build-1-4-4-restic-pingme:
runs-on: ubuntu-latest
env:
VARIANT: 1.4.4-restic-pingme
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Display system info (linux)
run: |
set -e
hostname
whoami
cat /etc/*release
lscpu
free
df -h
pwd
docker info
docker version
# See: https://github.com/docker/build-push-action/blob/v2.6.1/docs/advanced/cache.md#github-cache
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ env.VARIANT }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ env.VARIANT }}-
${{ runner.os }}-buildx-
# This step generates the docker tags
- name: Prepare
id: prep
run: |
set -e
# Get ref, i.e. <branch_name> from refs/heads/<branch_name>, or <tag-name> from refs/tags/<tag_name>. E.g. 'master' or 'v0.0.0'
REF=$( echo "${GITHUB_REF}" | rev | cut -d '/' -f 1 | rev )
# Get short commit hash E.g. 'abc0123'
SHA=$( echo "${GITHUB_SHA}" | cut -c1-7 )
# Generate docker image tags
# E.g. 'v0.0.0-<variant>' and 'v0.0.0-abc0123-<variant>'
# E.g. 'master-<variant>' and 'master-abc0123-<variant>'
REF_VARIANT="${REF}-${VARIANT}"
REF_SHA_VARIANT="${REF}-${SHA}-${VARIANT}"
# Pass variables to next step
echo "VARIANT_BUILD_DIR=$VARIANT_BUILD_DIR" >> $GITHUB_ENV
echo "VARIANT=$VARIANT" >> $GITHUB_ENV
echo "REF_VARIANT=$REF_VARIANT" >> $GITHUB_ENV
echo "REF_SHA_VARIANT=$REF_SHA_VARIANT" >> $GITHUB_ENV
- name: Login to Docker Hub registry
# Run on master and tags
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_REGISTRY_USER }}
password: ${{ secrets.DOCKERHUB_REGISTRY_PASSWORD }}

- name: Build (PRs)
# Run only on pull requests
if: github.event_name == 'pull_request'
uses: docker/build-push-action@v3
with:
context: variants/1.4.4-restic-pingme
platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm64
push: false
tags: |
${{ github.repository }}:${{ env.REF_VARIANT }}
${{ github.repository }}:${{ env.REF_SHA_VARIANT }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

- name: Build and push (master)
# Run only on master
if: github.ref == 'refs/heads/master'
uses: docker/build-push-action@v3
with:
context: variants/1.4.4-restic-pingme
platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm64
push: true
tags: |
${{ github.repository }}:${{ env.REF_VARIANT }}
${{ github.repository }}:${{ env.REF_SHA_VARIANT }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

- name: Build and push (release)
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v3
with:
context: variants/1.4.4-restic-pingme
platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm64
push: true
tags: |
${{ github.repository }}:${{ env.VARIANT }}
${{ github.repository }}:${{ env.REF_VARIANT }}
${{ github.repository }}:${{ env.REF_SHA_VARIANT }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
update-draft-release:
needs: [build-1-4-4, build-1-4-4-restic]
needs: [build-1-4-4, build-1-4-4-pingme, build-1-4-4-restic, build-1-4-4-restic-pingme]
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
Expand All @@ -287,7 +527,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish-draft-release:
needs: [build-1-4-4, build-1-4-4-restic]
needs: [build-1-4-4, build-1-4-4-pingme, build-1-4-4-restic, build-1-4-4-restic-pingme]
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
Expand All @@ -302,7 +542,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

update-dockerhub-description:
needs: [build-1-4-4, build-1-4-4-restic]
needs: [build-1-4-4, build-1-4-4-pingme, build-1-4-4-restic, build-1-4-4-restic-pingme]
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
Expand Down
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,32 @@ All images contain `curl` and `jq`, which are useful for sending notifications i
| Tag | Dockerfile Build Context |
|:-------:|:---------:|
| `:1.4.4`, `:latest` | [View](variants/1.4.4) |
| `:1.4.4-pingme` | [View](variants/1.4.4-pingme) |
| `:1.4.4-restic` | [View](variants/1.4.4-restic) |
| `:1.4.4-restic-pingme` | [View](variants/1.4.4-restic-pingme) |

- `restic`: Includes [`restic`](https://github.com/restic/restic). This is useful for [cron-based backups](#cron).
- `restic`: Includes [`restic`](https://github.com/restic/restic). Useful for [cron-based backups](#cron-and-notifications).
- `pingme`: Includes [`pingme`](https://github.com/kha7iq/pingme). Useful for sending notifications to [well-known services](https://pingme.lmno.pk/#/services).
- Note: `pingme` images has fewer architectures than non-`pingme` variants. More architectures will be added.

## Usage

> Note: `isync` the project name, `mbsync` is the tool
> Note: `isync` the project name, `mbsync` is the tool.
The config file used in this image is `/mbsyncrc`.

The volume used to store local Maildir is `/mail`.

The main sync script is `/sync`.
The `mbsync` config file used in this image is `/mbsyncrc`. The volume used to store local Maildir is `/mail`. The main sync script is `/sync`.

Here are three common sync cases:

- [IMAP to Maildir](#imap-to-maildir) - One-way sync of IMAP server to local Maildir
- [Maildir to IMAP](#maildir-to-imap) - One-way sync of local Maildir to IMAP server
- [IMAP to IMAP](#imap-to-imap) - One-way sync of IMAP server to another IMAP server

For cron-based examples, see [below](#cron).
For cron-based examples, see [below](#cron-and-notifications).

For a simple demo of the three sync cases, see this `docker-compose` [demo](docs/examples/demo).

If needed, see [official docs](https://isync.sourceforge.io/).

### IMAP to Maildir

This syncs `[email protected]` to a local Maildir `/mail`. Sync state is kept in each folder in `/mail`.
Expand Down Expand Up @@ -159,13 +161,14 @@ Sync:
docker run --rm -it -v $(pwd)/mbsyncrc:/mbsyncrc:ro -v mbsync:/mbsync theohbrothers/docker-isync:latest
```

### Cron
### Cron and notifications

For cron-based sync and cron-based backup with notifications, see `docker-compose` example(s):
For cron-based sync and backup with notifications, see `docker-compose` example(s):

- [Cron-based sync with notifications](docs/examples/cron-sync)
- [Cron-based sync and backup with notifications in the same container](docs/examples/cron-sync-backup)
- [Cron-based sync and backup with notifications in separate containers](docs/examples/cron-sync-backup-separate)
- [Cron-based sync with curl notifications](docs/examples/cron-sync)
- [Cron-based sync with pingme notifications](docs/examples/cron-sync-pingme)
- [Cron-based sync and backup (same container) with curl notifications](docs/examples/cron-sync-backup)
- [Cron-based sync and backup (separate containers) with curl notifications](docs/examples/cron-sync-backup-separate)

### Command line usage

Expand Down
4 changes: 2 additions & 2 deletions docs/examples/cron-sync-backup-separate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ snapshot c9ed53b0 saved

Now, wait out for `00:00` of tomorrow.

At `00:00`, the incremental sync would have run very quickly.
At `00:00`, the incremental sync would run very quickly. A notification of the cron status would be sent to `https://example.com` using `curl`.

List synced files:

Expand All @@ -87,7 +87,7 @@ docker-compose exec isync find /mail

Now, wait out for `00:05` of tomorrow.

At `00:05`, the `restic` incremental backup would have run very quickly.
At `00:05`, the `restic` incremental backup would run very quickly. A notification of the cron status would be sent to `https://example.com`.

List synced files:

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/cron-sync-backup-separate/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ services:
exec crond -f
restic:
image: restic/restic:0.15.1
image: theohbrothers/docker-isync:1.4.4-restic
environment:
- RESTIC_REPOSITORY=/backup
- RESTIC_PASSWORD=test
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/cron-sync-backup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ snapshot c9ed53b0 saved

Now, wait out for `00:00` of tomorrow.

At `00:00`, the incremental sync and incremental backup would have run very quickly.
At `00:00`, the incremental sync and incremental backup would run very quickly. A notification of the cron status would be sent to `https://example.com` using `curl`.

List synced files:

Expand All @@ -83,7 +83,7 @@ List backup files:
docker-compose exec isync find /backup
```

## 5. Restore a backup
## 4. Restore a backup

If `/mail` is ever lost, `restic restore` can easily restore the data.

Expand Down
Loading

0 comments on commit 6fef260

Please sign in to comment.