Compare commits

...

7 Commits

Author SHA1 Message Date
Frederik Ring
fa356137e8 inject proper version for mc command at compile time 2021-07-03 10:25:26 +02:00
Frederik Ring
07befda44d build mc from source, support arm/v7 2021-07-01 15:16:39 +02:00
Frederik Ring
c33ebc0c70 Merge pull request #5 from offen/multiarch
Build image for arm architectures
2021-07-01 14:22:54 +02:00
Frederik Ring
23c287bfc7 build image for arm architectures 2021-07-01 14:19:55 +02:00
Frederik Ring
5be3c36040 update alpine base image to 3.14 2021-06-28 20:25:21 +02:00
Frederik Ring
57afad5727 Merge pull request #4 from offen/stop-label
Allow for making container stop filter configurable
2021-06-26 21:19:35 +02:00
Frederik Ring
bafca7bb85 allow for making container stop filter configurable 2021-06-26 21:16:22 +02:00
6 changed files with 66 additions and 24 deletions

View File

@@ -1,40 +1,70 @@
version: 2.1 version: 2.1
jobs: jobs:
build: canary:
docker: docker:
- image: cimg/base:2020.06 - image: cimg/base:2020.06
working_directory: ~/docker-volume-backup working_directory: ~/docker-volume-backup
steps: steps:
- checkout - checkout
- setup_remote_docker - setup_remote_docker:
version: 20.10.6
- run: - run:
name: Build name: Build
command: make build
- run:
name: Check if image needs to be pushed
command: | command: |
if [[ -z "$CIRCLE_TAG" ]]; then docker build . -t offen/docker-volume-backup:canary
echo "Not a git tag, nothing to do ..." - run:
circleci-agent step halt name: Create container from image
command: |
docker run -d offen/docker-volume-backup:canary
echo "Sleeping for 30s before checking if container is still running."
sleep 30
count=$(docker ps -q | wc -l)
if [[ $count != "1" ]]; then
echo "Expected one container to be running, found $count."
exit 1
fi fi
docker stop $(docker ps -q)
build:
docker:
- image: cimg/base:2020.06
environment:
DOCKER_BUILDKIT: '1'
DOCKER_CLI_EXPERIMENTAL: enabled
working_directory: ~/docker-volume-backup
steps:
- checkout
- setup_remote_docker:
version: 20.10.6
- docker/install-docker-credential-helper - docker/install-docker-credential-helper
- docker/configure-docker-credentials-store - docker/configure-docker-credentials-store
- run: - run:
name: Push to Docker Hub name: Push to Docker Hub
command: | command: |
echo "$DOCKER_ACCESSTOKEN" | docker login --username offen --password-stdin echo "$DOCKER_ACCESSTOKEN" | docker login --username offen --password-stdin
docker tag offen/docker-volume-backup:local offen/docker-volume-backup:$CIRCLE_TAG # This is required for building ARM: https://gitlab.alpinelinux.org/alpine/aports/-/issues/12406
docker tag offen/docker-volume-backup:local offen/docker-volume-backup:latest docker run --rm --privileged linuxkit/binfmt:v0.8
docker push offen/docker-volume-backup:$CIRCLE_TAG docker context create docker-volume-backup
docker push offen/docker-volume-backup:latest docker buildx create docker-volume-backup --name docker-volume-backup --use
docker buildx inspect --bootstrap
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 \
-t offen/docker-volume-backup:$CIRCLE_TAG \
-t offen/docker-volume-backup:latest \
. --push
workflows: workflows:
version: 2 version: 2
deploy: docker_image:
jobs: jobs:
- canary:
filters:
tags:
ignore: /^v.*/
- build: - build:
filters: filters:
branches:
ignore: /.*/
tags: tags:
only: /^v.*/ only: /^v.*/

View File

@@ -1,16 +1,20 @@
# Copyright 2021 - Offen Authors <hioffen@posteo.de> # Copyright 2021 - Offen Authors <hioffen@posteo.de>
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MPL-2.0
FROM alpine:3.13 FROM golang:1.16-alpine as builder
ARG MC_VERSION=RELEASE.2021-06-13T17-48-22Z
RUN go install -ldflags "-X github.com/minio/mc/cmd.ReleaseTag=$MC_VERSION" github.com/minio/mc@$MC_VERSION
FROM alpine:3.14
WORKDIR /root WORKDIR /root
RUN apk add --update ca-certificates docker openrc gnupg RUN apk add --update ca-certificates docker openrc gnupg
RUN update-ca-certificates
RUN rc-update add docker boot RUN rc-update add docker boot
RUN wget https://dl.min.io/client/mc/release/linux-amd64/mc && \ COPY --from=builder /go/bin/mc /usr/bin/mc
chmod +x mc && \ RUN mc --version
mv mc /usr/bin/mc
COPY src/backup.sh src/entrypoint.sh /root/ COPY src/backup.sh src/entrypoint.sh /root/
RUN chmod +x backup.sh && mv backup.sh /usr/bin/backup \ RUN chmod +x backup.sh && mv backup.sh /usr/bin/backup \

View File

@@ -1,5 +0,0 @@
DOCKER_TAG ?= local
.PHONY: build
build:
@docker build -t offen/docker-volume-backup:$(DOCKER_TAG) .

View File

@@ -53,6 +53,16 @@ AWS_S3_BUCKET_NAME="<xxx>"
# GPG_PASSPHRASE="<xxx>" # GPG_PASSPHRASE="<xxx>"
########### STOPPING CONTAINERS DURING BACKUP
# Containers can be stopped by applying a
# `docker-volume-backup.stop-during-backup` label. By default, all containers
# that are labeled with `true` will be stopped. If you need more fine grained
# control (e.g. when running multiple containers based on this image), you can
# override this default by specifying a different value here.
# BACKUP_STOP_CONTAINER_LABEL="service1"
########### MINIO CLIENT CONFIGURATION ########### MINIO CLIENT CONFIGURATION
# Pass these additional flags to all MinIO client `mc` invocations. # Pass these additional flags to all MinIO client `mc` invocations.
@@ -104,3 +114,4 @@ This image is heavily inspired by the `futurice/docker-volume-backup`. We decide
- This image makes use of the MinIO client `mc` instead of the full blown AWS CLI for uploading backups. - This image makes use of the MinIO client `mc` instead of the full blown AWS CLI for uploading backups.
- The original image proposed to handle backup rotation through AWS S3 lifecycle policies. This image adds the option to rotate old backups through the same script so this functionality can also be offered for non-AWS storage backends like MinIO. - The original image proposed to handle backup rotation through AWS S3 lifecycle policies. This image adds the option to rotate old backups through the same script so this functionality can also be offered for non-AWS storage backends like MinIO.
- InfluxDB specific functionality was removed. - InfluxDB specific functionality was removed.
- `arm64` and `arm/v7` architectures are supported.

View File

@@ -19,7 +19,7 @@ if [ -S "$DOCKER_SOCK" ]; then
TEMPFILE="$(mktemp)" TEMPFILE="$(mktemp)"
docker ps \ docker ps \
--format "{{.ID}}" \ --format "{{.ID}}" \
--filter "label=docker-volume-backup.stop-during-backup=true" \ --filter "label=docker-volume-backup.stop-during-backup=$BACKUP_STOP_CONTAINER_LABEL" \
> "$TEMPFILE" > "$TEMPFILE"
CONTAINERS_TO_STOP="$(cat $TEMPFILE | tr '\n' ' ')" CONTAINERS_TO_STOP="$(cat $TEMPFILE | tr '\n' ' ')"
CONTAINERS_TO_STOP_TOTAL="$(cat $TEMPFILE | wc -l)" CONTAINERS_TO_STOP_TOTAL="$(cat $TEMPFILE | wc -l)"

View File

@@ -22,6 +22,8 @@ AWS_ENDPOINT="${AWS_ENDPOINT:-s3.amazonaws.com}"
GPG_PASSPHRASE="${GPG_PASSPHRASE:-}" GPG_PASSPHRASE="${GPG_PASSPHRASE:-}"
BACKUP_STOP_CONTAINER_LABEL="${BACKUP_STOP_CONTAINER_LABEL:-true}"
MC_GLOBAL_OPTIONS="${MC_GLOBAL_OPTIONS:-}" MC_GLOBAL_OPTIONS="${MC_GLOBAL_OPTIONS:-}"
EOF EOF
chmod a+x env.sh chmod a+x env.sh