From 026ef778b6b99f926d1cde82e96b5dcd3e414638 Mon Sep 17 00:00:00 2001 From: 1O <2408212-1O@users.noreply.gitlab.com> Date: Sun, 24 Jan 2021 19:49:51 +0100 Subject: [PATCH 1/3] Added buildx to allow multi-arch builds Squashed commit of the following: commit f3d42ceebe3f209645dc44b9e1ea956339c32968 Author: 1O <2408212-1O@users.noreply.gitlab.com> Date: Sun Jan 24 19:48:23 2021 +0100 Only build master since rpi3 is no longer needed commit 32e213d65955291fa38d20c77e74aa30cf25cd24 Author: 1O <2408212-1O@users.noreply.gitlab.com> Date: Sun Jan 24 19:46:40 2021 +0100 Added dockerhub login commit 960c44c7148073cfbee617be3019fb399d1fc0b1 Author: 1O <2408212-1O@users.noreply.gitlab.com> Date: Sun Jan 24 19:38:21 2021 +0100 Added ARCH to Dockerfile commit fad35cd700dcf7a4c4ee5ac7eeea89f33871eaab Author: 1O <2408212-1O@users.noreply.gitlab.com> Date: Sun Jan 24 19:30:30 2021 +0100 don't push in buildx commit 9cd85b6787ec552d5dee393a40137fa3ed9cb94e Author: 1O <2408212-1O@users.noreply.gitlab.com> Date: Sun Jan 24 19:28:09 2021 +0100 added context commit 07fb2b320463dc495c4e69f40bb524bcc0ebd15a Author: 1O <2408212-1O@users.noreply.gitlab.com> Date: Sun Jan 24 19:20:02 2021 +0100 Added experimental commit 99b352dad13aca54f49fb56f0fb19a921cd81c9d Author: 1O <2408212-1O@users.noreply.gitlab.com> Date: Sun Jan 24 19:16:59 2021 +0100 Added buildx --- .gitlab-ci.yml | 46 +++++++++++++++++++++------------------------- Dockerfile | 3 ++- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5d7e18a..7f03aff 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,6 +7,9 @@ variables: # see https://gitlab.com/gitlab-org/gitlab-runner/issues/4501 DOCKER_DRIVER: overlay2 DOCKER_TLS_CERTDIR: "/certs" + # See https://github.com/docker/buildx/releases + BUILDX_VERSION: v0.5.1 + BUILDX_ARCH: linux-amd64 .docker_login: &docker_login docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY @@ -18,37 +21,29 @@ variables: stage: build:docker image: docker:latest services: - - docker:dind + - name: docker:dind + command: ["--experimental"] tags: - shared + before_script: + - apk add curl + - mkdir -p ~/.docker/cli-plugins + - curl -sSLo ~/.docker/cli-plugins/docker-buildx https://github.com/docker/buildx/releases/download/$BUILDX_VERSION/buildx-$BUILDX_VERSION.$BUILDX_ARCH + - chmod +x ~/.docker/cli-plugins/docker-buildx + - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + - docker context create my-context + - docker buildx create --use my-context + - docker info build_master: <<: *docker_build script: - *docker_login - - docker build --pull -t "$IMAGE_NAME" -t "$IMAGE_NAME_DOCKERHUB:${CI_COMMIT_TAG:-latest}" . - - docker push "$IMAGE_NAME" - *dockerhub_login - - docker push "$IMAGE_NAME_DOCKERHUB:${CI_COMMIT_TAG:-latest}" - only: - refs: - - master - - tags - changes: - - Dockerfile - - backup.sh - - entrypoint.sh - -build_master_rpi3: - <<: *docker_build - script: - - *docker_login - - docker build --pull -t "$IMAGE_NAME:rpi3" -t "$IMAGE_NAME_DOCKERHUB:${CI_COMMIT_TAG:-latest}-rpi3" . - - docker push "$IMAGE_NAME:rpi3" - - *dockerhub_login - - docker push "$IMAGE_NAME_DOCKERHUB:${CI_COMMIT_TAG:-latest}-rpi3" - tags: - - rpi3 + #- docker build --pull -t "$IMAGE_NAME" -t "$IMAGE_NAME_DOCKERHUB:${CI_COMMIT_TAG:-latest}" . + - docker buildx build --push --platform linux/arm/v7,linux/arm64/v8,linux/amd64 -t "$IMAGE_NAME" -t "$IMAGE_NAME_DOCKERHUB:${CI_COMMIT_TAG:-latest}" . + #- docker push "$IMAGE_NAME" + #- docker push "$IMAGE_NAME_DOCKERHUB:${CI_COMMIT_TAG:-latest}" only: refs: - master @@ -62,8 +57,9 @@ build: <<: *docker_build script: - *docker_login - - docker build --pull -t "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/bw_backup:${CI_COMMIT_TAG:-latest}" . - - docker push "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/bw_backup:${CI_COMMIT_TAG:-latest}" + #- docker build --pull -t "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/bw_backup:${CI_COMMIT_TAG:-latest}" . + - docker buildx build --push --platform linux/arm/v7,linux/arm64/v8,linux/amd64 --tag "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/bw_backup:${CI_COMMIT_TAG:-latest}" . + #- docker push "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/bw_backup:${CI_COMMIT_TAG:-latest}" except: - master diff --git a/Dockerfile b/Dockerfile index 93c6564..9650b01 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ -FROM alpine:latest +ARG ARCH= +FROM ${ARCH}alpine:latest RUN addgroup -S app && adduser -S -G app app From 41c2ffe08616eb9d2bf07e244da61fe0a75db4db Mon Sep 17 00:00:00 2001 From: 1O <2408212-1O@users.noreply.gitlab.com> Date: Sun, 24 Jan 2021 19:59:39 +0100 Subject: [PATCH 2/3] Added tzdata fixes #14 --- Dockerfile | 3 ++- README.md | 29 ++++++++++++++++------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9650b01..dfc498a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,8 @@ RUN addgroup -S app && adduser -S -G app app RUN apk add --no-cache \ sqlite \ busybox-suid \ - su-exec + su-exec \ + tzdata ENV DB_FILE /data/db.sqlite3 ENV BACKUP_FILE /data/db_backup/backup.sqlite3 diff --git a/README.md b/README.md index c117fae..c3bbde1 100644 --- a/README.md +++ b/README.md @@ -40,20 +40,22 @@ docker run --rm --volumes-from=bitwarden -e UID=0 -e BACKUP_FILE=/myBackup/backu ``` ## Environment variables -| ENV | Description | -| ----- | ----- | -| DB_FILE | Path to the Bitwarden sqlite3 database *inside* the container | -| BACKUP_FILE | Path to the desired backup location *inside* the container | -| BACKUP_FILE_PERMISSIONS | Sets the permissions of the backup file (**CAUTION** [^1]) | -| CRON_TIME | Cronjob format "Minute Hour Day_of_month Month_of_year Day_of_week Year" | -| TIMESTAMP | Set to `true` to append timestamp to the `BACKUP_FILE` | -| UID | User ID to run the cron job with | -| GID | Group ID to run the cron job with | -| LOGFILE | Path to the logfile *inside* the container | -| CRONFILE | Path to the cron file *inside* the container | -| DELETE_AFTER | Delete old backups after X many days | +| ENV | Description | +| ----------------------- | ------------------------------------------------------------------------ | +| DB_FILE | Path to the Bitwarden sqlite3 database *inside* the container | +| BACKUP_FILE | Path to the desired backup location *inside* the container | +| BACKUP_FILE_PERMISSIONS | Sets the permissions of the backup file (**CAUTION** [^1]) | +| CRON_TIME | Cronjob format "Minute Hour Day_of_month Month_of_year Day_of_week Year" | +| TIMESTAMP | Set to `true` to append timestamp to the `BACKUP_FILE` | +| UID | User ID to run the cron job with | +| GID | Group ID to run the cron job with | +| LOGFILE | Path to the logfile *inside* the container | +| CRONFILE | Path to the cron file *inside* the container | +| DELETE_AFTER | Delete old backups after X many days | +| TZ | Set the timezone inside the container [^2] [^1]: The permissions should at least be 700 since the backup folder itself gets the same permissions and with 600 it would not be accessible. +[^2]: see for more information ## Common erros ### Wrong permissions @@ -64,4 +66,5 @@ via the `UID` and `GID` environment variables like described above. ### Wrong timestamp If you need timestamps in your local timezone you should mount `/etc/timezone:/etc/timezone:ro` and `/etc/localtime:/etc/localtime:ro` -like it's done in the [docker-compose.yml](docker-compose.yml). +like it's done in the [docker-compose.yml](docker-compose.yml). An other possible solution is to set the environment variable accordingly (like `TZ=Europe/Berlin`) +(see for more information). From c5285747360a7273755a2e2a9b62f2f378b5e0cb Mon Sep 17 00:00:00 2001 From: 10 <2408212-10@users.noreply.gitlab.com> Date: Sun, 24 Jan 2021 23:06:41 +0100 Subject: [PATCH 3/3] fixed image tagging --- .gitlab-ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7f03aff..bd8219d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,6 @@ stages: - build:docker variables: - IMAGE_NAME: "$CI_REGISTRY_IMAGE" IMAGE_NAME_DOCKERHUB: "index.docker.io/bruceforce/bw_backup" # see https://gitlab.com/gitlab-org/gitlab-runner/issues/4501 DOCKER_DRIVER: overlay2 @@ -41,7 +40,7 @@ build_master: - *docker_login - *dockerhub_login #- docker build --pull -t "$IMAGE_NAME" -t "$IMAGE_NAME_DOCKERHUB:${CI_COMMIT_TAG:-latest}" . - - docker buildx build --push --platform linux/arm/v7,linux/arm64/v8,linux/amd64 -t "$IMAGE_NAME" -t "$IMAGE_NAME_DOCKERHUB:${CI_COMMIT_TAG:-latest}" . + - docker buildx build --push --platform linux/arm/v7,linux/arm64/v8,linux/amd64 -t "$CI_REGISTRY_IMAGE:${CI_COMMIT_TAG:-latest}" -t "$IMAGE_NAME_DOCKERHUB:${CI_COMMIT_TAG:-latest}" . #- docker push "$IMAGE_NAME" #- docker push "$IMAGE_NAME_DOCKERHUB:${CI_COMMIT_TAG:-latest}" only: @@ -58,7 +57,7 @@ build: script: - *docker_login #- docker build --pull -t "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/bw_backup:${CI_COMMIT_TAG:-latest}" . - - docker buildx build --push --platform linux/arm/v7,linux/arm64/v8,linux/amd64 --tag "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/bw_backup:${CI_COMMIT_TAG:-latest}" . + - docker buildx build --push --platform linux/arm/v7,linux/arm64/v8,linux/amd64 --tag "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME" . #- docker push "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/bw_backup:${CI_COMMIT_TAG:-latest}" except: - master