diff --git a/.github/workflows/ci-master-pr.yml b/.github/workflows/ci-master-pr.yml index d630d32..63f5828 100644 --- a/.github/workflows/ci-master-pr.yml +++ b/.github/workflows/ci-master-pr.yml @@ -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. from refs/heads/, or from refs/tags/. 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-' and 'v0.0.0-abc0123-' + # E.g. 'master-' and 'master-abc0123-' + 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: @@ -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. from refs/heads/, or from refs/tags/. 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-' and 'v0.0.0-abc0123-' + # E.g. 'master-' and 'master-abc0123-' + 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: @@ -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: @@ -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: diff --git a/README.md b/README.md index 4f15203..b1c86ad 100644 --- a/README.md +++ b/README.md @@ -15,19 +15,19 @@ 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: @@ -35,10 +35,12 @@ Here are three common sync cases: - [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 `test@example.com` to a local Maildir `/mail`. Sync state is kept in each folder in `/mail`. @@ -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 diff --git a/docs/examples/cron-sync-backup-separate/README.md b/docs/examples/cron-sync-backup-separate/README.md index 7c09578..9f4c313 100644 --- a/docs/examples/cron-sync-backup-separate/README.md +++ b/docs/examples/cron-sync-backup-separate/README.md @@ -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: @@ -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: diff --git a/docs/examples/cron-sync-backup-separate/docker-compose.yml b/docs/examples/cron-sync-backup-separate/docker-compose.yml index aa10611..6a4190e 100644 --- a/docs/examples/cron-sync-backup-separate/docker-compose.yml +++ b/docs/examples/cron-sync-backup-separate/docker-compose.yml @@ -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 diff --git a/docs/examples/cron-sync-backup/README.md b/docs/examples/cron-sync-backup/README.md index b5d18e5..92cb673 100644 --- a/docs/examples/cron-sync-backup/README.md +++ b/docs/examples/cron-sync-backup/README.md @@ -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: @@ -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. diff --git a/docs/examples/cron-sync-pingme/README.md b/docs/examples/cron-sync-pingme/README.md new file mode 100644 index 0000000..9a9edff --- /dev/null +++ b/docs/examples/cron-sync-pingme/README.md @@ -0,0 +1,42 @@ +# Cron sync + +This demo shows a cron-based sync of IMAP to a local Maildir in `/mail`. + +Start the container(s): + +```sh +docker-compose up +``` + +`isync` service is now running: + +- `/mbsyncrc` config file is created +- `/notify.sh` is created +- A crontab is created that runs `/sync` and `/notify.sh` daily at `00:00` +- `crond` is started + +## 1. Perform first-time sync + +View `/mbsyncrc` config: + +```sh +docker-compose exec isync cat /mbsyncrc +``` + +Run a first-time sync (this will fail, because `test@example.com` is not a real account): + +```sh +docker-compose exec isync /sync +``` + +## 2. Wait for cron sync + +Now, wait out for `00:00` of tomorrow. + +At `00:00`, the incremental sync would run very quickly. A notification of the cron status would be sent to Discord and Mattermost using `pingme`. + +List synced files: + +```sh +docker-compose exec isync find /mail +``` diff --git a/docs/examples/cron-sync-pingme/docker-compose.yml b/docs/examples/cron-sync-pingme/docker-compose.yml new file mode 100644 index 0000000..40a9456 --- /dev/null +++ b/docs/examples/cron-sync-pingme/docker-compose.yml @@ -0,0 +1,67 @@ +version: '2' +services: + isync: + image: theohbrothers/docker-isync:1.4.4-pingme + volumes: + - mail:/mail + networks: + - default + restart: unless-stopped + stop_signal: SIGKILL + entrypoint: + - /bin/sh + command: + - -c + - | + set -eu + + echo "Creating /mbsyncrc" + cat - > /mbsyncrc <<'EOF' + IMAPStore example-remote + Host imap.example.com + User test@example.com + Pass test + AuthMechs LOGIN + SSLType IMAPS + # Limit the number of simultaneous IMAP commands + PipelineDepth 30 + + MaildirStore example-local + SubFolders Verbatim + # The trailing '/' is important for Path + Path /mail/ + Inbox /mail/INBOX + + Channel example + Far :example-remote: + Near :example-local: + Patterns * + Create Near + Expunge Near + SyncState * + Sync Pull + EOF + + echo "Creating /notify.sh" + touch /notify.sh && chmod 700 /notify.sh + cat - > /notify.sh <<'EOF' + echo "Sending notification" + pingme discord --token '123' --channel '1234567890' --msg $${1:-empty} + pingme mattermost --token '123' --channel '12345,567' --url 'mattermost.example.com' --scheme 'https' --msg $${1:-empty} + EOF + + # Run at 00:00 daily. To customize the cron schedule, use https://crontab.guru + echo "Creating crontab" + crontab - <<'EOF' + 0 0 * * * /sync && /notify.sh sync-success|| /notify.sh sync-failed + EOF + crontab -l + + echo "Running crond" + exec crond -f + +networks: + default: + +volumes: + mail: diff --git a/docs/examples/cron-sync/README.md b/docs/examples/cron-sync/README.md index b2a124a..bbff340 100644 --- a/docs/examples/cron-sync/README.md +++ b/docs/examples/cron-sync/README.md @@ -33,7 +33,7 @@ docker-compose exec isync /sync 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: diff --git a/generate/definitions/VARIANTS.ps1 b/generate/definitions/VARIANTS.ps1 index aa6110e..26ec869 100644 --- a/generate/definitions/VARIANTS.ps1 +++ b/generate/definitions/VARIANTS.ps1 @@ -8,7 +8,9 @@ $local:VARIANTS_MATRIX = @( package_version = $v subvariants = @( @{ components = @() } + @{ components = @('pingme') } @{ components = @('restic') } + @{ components = @('restic', 'pingme') } ) } } @@ -21,7 +23,13 @@ $VARIANTS = @( # Metadata object _metadata = @{ package_version = $variant['package_version'] - platforms = 'linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x' + platforms = & { + if ( $subVariant['components'] -contains 'pingme') { + 'linux/386,linux/amd64,linux/arm/v7,linux/arm64' + }else { + 'linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x' + } + } components = $subVariant['components'] } # Docker image tag. E.g. '3.8-curl' diff --git a/generate/templates/Dockerfile.ps1 b/generate/templates/Dockerfile.ps1 index f3f0e5c..699ee4c 100644 --- a/generate/templates/Dockerfile.ps1 +++ b/generate/templates/Dockerfile.ps1 @@ -31,6 +31,38 @@ RUN set -eux; \ "@ foreach ($c in $VARIANT['_metadata']['components']) { + if ($c -eq 'pingme') { +@' +# Install pingme +RUN set -eux; \ + export PINGME_VERSION="0.2.5"; \ + OS=$( uname -o ); \ + # The naming conventions of the binaries is not consistent, hence the need for ARCH workaround + ARCH=$( \ + if [ "$TARGETARCH" = 'amd64' ]; then \ + uname -m; \ + elif [ "$TARGETARCH" = '386' ]; then \ + echo "i$TARGETARCH"; \ + else \ + echo "$TARGETARCH"; \ + fi; \ + ); \ + FILE=pingme_${OS}_${ARCH}${TARGETVARIANT}.tar.gz; \ + wget https://github.com/kha7iq/pingme/releases/download/v$PINGME_VERSION/pingme_checksums.txt; \ + wget -q https://github.com/kha7iq/pingme/releases/download/v${PINGME_VERSION}/$FILE; \ + cat pingme_checksums.txt | grep "$FILE" | sha256sum -c -; \ + tar -xvf "$FILE" -- pingme LICENSE.md; \ + chmod +x pingme; \ + mv pingme /usr/local/bin/pingme; \ + mv LICENSE.md /usr/local/bin/pingme.LICENSE; \ + pingme --version | grep "$PINGME_VERSION"; \ + rm -f pingme_checksums.txt; \ + rm -f "$FILE"; + + +'@ + } + if ($c -eq 'restic') { @' # Install restic diff --git a/generate/templates/README.md.ps1 b/generate/templates/README.md.ps1 index 02f1609..7441bd6 100644 --- a/generate/templates/README.md.ps1 +++ b/generate/templates/README.md.ps1 @@ -30,7 +30,9 @@ $( } }) -join '' ) -- ``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. "@ @@ -38,13 +40,9 @@ $( @' ## 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: @@ -52,10 +50,12 @@ Here are three common sync cases: - [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 `test@example.com` to a local Maildir `/mail`. Sync state is kept in each folder in `/mail`. @@ -176,13 +176,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 diff --git a/variants/1.4.4-pingme/Dockerfile b/variants/1.4.4-pingme/Dockerfile new file mode 100644 index 0000000..0b6ac71 --- /dev/null +++ b/variants/1.4.4-pingme/Dockerfile @@ -0,0 +1,68 @@ +# syntax=docker/dockerfile:1 +FROM alpine:3.17 +ARG TARGETPLATFORM +ARG TARGETOS +ARG TARGETARCH +ARG TARGETVARIANT +ARG BUILDPLATFORM +ARG BUILDOS +ARG BUILDARCH +ARG BUILDVARIANT +RUN set -eu; \ + echo "TARGETPLATFORM="; \ + echo "TARGETOS="; \ + echo "TARGETARCH="; \ + echo "TARGETVARIANT="; \ + echo "BUILDPLATFORM="; \ + echo "BUILDOS="; \ + echo "BUILDARCH="; \ + echo "BUILDVARIANT="; + +# Install isync +RUN apk add --no-cache ca-certificates +RUN set -eux; \ + apk add --no-cache isync~1.4.4; \ + # For mbsync-get-cert to get a self-signed certificate + apk add --no-cache openssl; \ + mbsync --version + +# Install pingme +RUN set -eux; \ + export PINGME_VERSION="0.2.5"; \ + OS=$( uname -o ); \ + # The naming conventions of the binaries is not consistent, hence the need for ARCH workaround + ARCH=$( \ + if [ "$TARGETARCH" = 'amd64' ]; then \ + uname -m; \ + elif [ "$TARGETARCH" = '386' ]; then \ + echo "i$TARGETARCH"; \ + else \ + echo "$TARGETARCH"; \ + fi; \ + ); \ + FILE=pingme_${OS}_${ARCH}${TARGETVARIANT}.tar.gz; \ + wget https://github.com/kha7iq/pingme/releases/download/v$PINGME_VERSION/pingme_checksums.txt; \ + wget -q https://github.com/kha7iq/pingme/releases/download/v${PINGME_VERSION}/$FILE; \ + cat pingme_checksums.txt | grep "$FILE" | sha256sum -c -; \ + tar -xvf "$FILE" -- pingme LICENSE.md; \ + chmod +x pingme; \ + mv pingme /usr/local/bin/pingme; \ + mv LICENSE.md /usr/local/bin/pingme.LICENSE; \ + pingme --version | grep "$PINGME_VERSION"; \ + rm -f pingme_checksums.txt; \ + rm -f "$FILE"; + +# Install notification tools +RUN apk add --no-cache curl jq + +# Install helper scripts +COPY sync /sync +RUN chmod +x /sync + +WORKDIR /mail +VOLUME /mail + +COPY docker-entrypoint.sh /docker-entrypoint.sh +RUN chmod +x /docker-entrypoint.sh +ENTRYPOINT [ "/docker-entrypoint.sh" ] +CMD [ "/sync" ] diff --git a/variants/1.4.4-pingme/docker-entrypoint.sh b/variants/1.4.4-pingme/docker-entrypoint.sh new file mode 100644 index 0000000..f3c3abf --- /dev/null +++ b/variants/1.4.4-pingme/docker-entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/sh +set -eu + +if [ "$#" -eq 0 ] || [ "${1#-}" != "$1" ]; then + set -- mbsync "$@" +fi + +if [ "$1" = 'mbsync' ]; then + exec "$@" +fi + +exec "$@" diff --git a/variants/1.4.4-pingme/sync b/variants/1.4.4-pingme/sync new file mode 100644 index 0000000..2e6f344 --- /dev/null +++ b/variants/1.4.4-pingme/sync @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu + +mbsync --config /mbsyncrc --all --verbose diff --git a/variants/1.4.4-restic-pingme/Dockerfile b/variants/1.4.4-restic-pingme/Dockerfile new file mode 100644 index 0000000..51ac631 --- /dev/null +++ b/variants/1.4.4-restic-pingme/Dockerfile @@ -0,0 +1,84 @@ +# syntax=docker/dockerfile:1 +FROM alpine:3.17 +ARG TARGETPLATFORM +ARG TARGETOS +ARG TARGETARCH +ARG TARGETVARIANT +ARG BUILDPLATFORM +ARG BUILDOS +ARG BUILDARCH +ARG BUILDVARIANT +RUN set -eu; \ + echo "TARGETPLATFORM="; \ + echo "TARGETOS="; \ + echo "TARGETARCH="; \ + echo "TARGETVARIANT="; \ + echo "BUILDPLATFORM="; \ + echo "BUILDOS="; \ + echo "BUILDARCH="; \ + echo "BUILDVARIANT="; + +# Install isync +RUN apk add --no-cache ca-certificates +RUN set -eux; \ + apk add --no-cache isync~1.4.4; \ + # For mbsync-get-cert to get a self-signed certificate + apk add --no-cache openssl; \ + mbsync --version + +# Install restic +# These packages are needed for all restic features to work. See: https://github.com/restic/restic/blob/0.15.1/docker/Dockerfile +RUN apk add --update --no-cache ca-certificates fuse openssh-client tzdata jq +RUN set -eux; \ + RESTIC_VERSION=0.15.1; \ + FILE=restic_${RESTIC_VERSION}_${TARGETOS}_${TARGETARCH}.bz2; \ + wget -q https://github.com/restic/restic/releases/download/v${RESTIC_VERSION}/$FILE; \ + wget -q https://github.com/restic/restic/releases/download/v${RESTIC_VERSION}/SHA256SUMS; \ + SHA=$( sha256sum "$FILE" ); \ + cat SHA256SUMS | grep "$FILE" | sha256sum -c -; \ + rm -f SHA256SUMS; \ + bzip2 -d "$FILE"; \ + mv restic_${RESTIC_VERSION}_${TARGETOS}_${TARGETARCH} /usr/local/bin/restic; \ + chmod +x /usr/local/bin/restic; \ + restic version | grep "^restic $RESTIC_VERSION"; + +# Install pingme +RUN set -eux; \ + export PINGME_VERSION="0.2.5"; \ + OS=$( uname -o ); \ + # The naming conventions of the binaries is not consistent, hence the need for ARCH workaround + ARCH=$( \ + if [ "$TARGETARCH" = 'amd64' ]; then \ + uname -m; \ + elif [ "$TARGETARCH" = '386' ]; then \ + echo "i$TARGETARCH"; \ + else \ + echo "$TARGETARCH"; \ + fi; \ + ); \ + FILE=pingme_${OS}_${ARCH}${TARGETVARIANT}.tar.gz; \ + wget https://github.com/kha7iq/pingme/releases/download/v$PINGME_VERSION/pingme_checksums.txt; \ + wget -q https://github.com/kha7iq/pingme/releases/download/v${PINGME_VERSION}/$FILE; \ + cat pingme_checksums.txt | grep "$FILE" | sha256sum -c -; \ + tar -xvf "$FILE" -- pingme LICENSE.md; \ + chmod +x pingme; \ + mv pingme /usr/local/bin/pingme; \ + mv LICENSE.md /usr/local/bin/pingme.LICENSE; \ + pingme --version | grep "$PINGME_VERSION"; \ + rm -f pingme_checksums.txt; \ + rm -f "$FILE"; + +# Install notification tools +RUN apk add --no-cache curl jq + +# Install helper scripts +COPY sync /sync +RUN chmod +x /sync + +WORKDIR /mail +VOLUME /mail + +COPY docker-entrypoint.sh /docker-entrypoint.sh +RUN chmod +x /docker-entrypoint.sh +ENTRYPOINT [ "/docker-entrypoint.sh" ] +CMD [ "/sync" ] diff --git a/variants/1.4.4-restic-pingme/docker-entrypoint.sh b/variants/1.4.4-restic-pingme/docker-entrypoint.sh new file mode 100644 index 0000000..f3c3abf --- /dev/null +++ b/variants/1.4.4-restic-pingme/docker-entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/sh +set -eu + +if [ "$#" -eq 0 ] || [ "${1#-}" != "$1" ]; then + set -- mbsync "$@" +fi + +if [ "$1" = 'mbsync' ]; then + exec "$@" +fi + +exec "$@" diff --git a/variants/1.4.4-restic-pingme/sync b/variants/1.4.4-restic-pingme/sync new file mode 100644 index 0000000..2e6f344 --- /dev/null +++ b/variants/1.4.4-restic-pingme/sync @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu + +mbsync --config /mbsyncrc --all --verbose