From 9e0321be58a0827dc7641fdded68d15b3b43b789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20L=C3=BCscher?= Date: Sun, 7 Oct 2018 14:01:05 +0000 Subject: [PATCH] Gitlab ci tests --- .gitlab-ci.yml | 41 +++++++++++++++++++++++++++++++++++++++ .travis.yml | 16 ---------------- Dockerfile | 6 +++--- README.md | 10 +++++----- build.sh | 8 +++++--- ci/bintray.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ extract.sh | 29 ++++++++++++++++------------ 7 files changed, 123 insertions(+), 39 deletions(-) create mode 100644 .gitlab-ci.yml delete mode 100644 .travis.yml create mode 100755 ci/bintray.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..22f013c --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,41 @@ +variables: + VERSION: $CI_COMMIT_TAG + +stages: + - build + - deploy + +armv5: + extends: .main + variables: {ARCH: armel, NAME: "borg-${VERSION}-armv5"} + +armv7: + extends: .main + variables: {ARCH: armv7hf, NAME: "borg-${VERSION}-armv7"} + +arm64: + extends: .main + variables: {ARCH: aarch64, NAME: "borg-${VERSION}-arm64"} + +.main: + stage: build + only: [tags] + variables: {NAME: "borg-${VERSION}-${ARCH}"} + script: + - ./build.sh $ARCH $VERSION + - ./extract.sh $ARCH $VERSION $NAME + artifacts: + expire_in: 1 day + paths: [$NAME] + +deploy artifacts to bintray: + stage: deploy + only: [tags] + script: + - md5sum borg-${VERSION}-* + - apk add curl + - ci/bintray.sh + dependencies: + - armv5 + - armv7 + - arm64 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 5bb6002..0000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -sudo: required -language: bash -services: - - docker -before_install: - - docker -v - - mkdir /tmp/borg-binaries -script: - - ./build.sh $ARCH - - ./extract.sh $ARCH /tmp/borg-binaries/$NAME -after_script: - - md5sum /tmp/borg-binaries/* -env: - - ARCH="armel" NAME="armv5" - - ARCH="armv7hf" NAME="armv7" - - ARCH="aarch64" NAME="arm64" diff --git a/Dockerfile b/Dockerfile index 682b39b..21723a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,12 +19,12 @@ RUN set -ex; \ zlib1g-dev liblz4-dev; \ rm -rf /var/lib/apt/lists/*; -# install borg + dependencies +# fetch borg source code and update pip RUN set -ex; \ - git clone https://github.com/borgbackup/borg.git .; \ - git checkout ${BORG_VERSION}; \ + git clone -b ${BORG_VERSION} https://github.com/borgbackup/borg.git .; \ pip install --upgrade pip; +# install borg + dependencies RUN set -ex; pip install -r requirements.d/development.txt; RUN set -ex; pip install -r requirements.d/fuse.txt; RUN set -ex; pip install -e .; diff --git a/README.md b/README.md index 2d84043..00ad5d8 100644 --- a/README.md +++ b/README.md @@ -19,16 +19,16 @@ See the [list of available architectures] ([on GitHub][available-architectures-g ### Extract borg binary -`./extract.sh []` +`./extract.sh [] []` **Note:** This will overwrite the file at `binary_save_location` if it already exists! *Examples:* -- Extract borg binary for `aarch64` to `borg-aarch64` in current folder -`./extract.sh aarch64 borg-aarch64` +- Extract borg `1.1.7` binary for `aarch64` to `borg-aarch64` in current folder +`./extract.sh aarch64 1.1.7 borg-aarch64` -- Extract borg binary for Raspberry Pi 3 to `/homes/lemoi/borg` -`./extract.sh raspberrypi3 /homes/lemoi/borg` +- Extract borg `1.1.5` binary for Raspberry Pi 3 to `/homes/lemoi/borg` +`./extract.sh raspberrypi3 1.1.5 /homes/lemoi/borg` ## How this works diff --git a/build.sh b/build.sh index a051c69..fe3e0e5 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh # Usage: ./build.sh [] @@ -8,9 +8,11 @@ BORG_ARCH=${1} BORG_VERSION=${2:-1.1.7} +DOCKER_IMAGE=borg:${BORG_VERSION}-${BORG_ARCH} + if [ -z "${BORG_ARCH}" ]; then echo "Usage: ./build.sh []"; - echo "- No arch provided -"; + echo "No arch provided"; exit 1; fi @@ -22,4 +24,4 @@ docker run --rm --privileged multiarch/qemu-user-static:register --reset docker build \ --build-arg "BORG_ARCH=${BORG_ARCH}" \ --build-arg "BORG_VERSION=${BORG_VERSION}" \ - -t "borg:${BORG_ARCH}" . + -t "${DOCKER_IMAGE}" . diff --git a/ci/bintray.sh b/ci/bintray.sh new file mode 100755 index 0000000..eaa3357 --- /dev/null +++ b/ci/bintray.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env sh + +# Based on bintray.sh by Lukas Matt (@zauberstuhl) +# https://git.feneas.org/ganggo/ganggo/blob/master/ci/scripts/bintray.sh + +# Note: Set via GitLab protected vars! +# BINTRAY_USER=$1 +# BINTRAY_API_KEY=$2 +# BINTRAY_REPO=$3 + +PKG_NAME=borg-binaries + +API=https://api.bintray.com +CURL="curl -u${BINTRAY_USER}:${BINTRAY_API_KEY} -H Content-Type:application/json -H Accept:application/json" + +DATA="{ + \"name\": \"${PKG_NAME}\", + \"desc\": \"BorgBackup binaries for various architectures\", + \"vcs_url\": \"${CI_PROJECT_URL}\", + \"licenses\": [\"WTFPL\"], + \"issue_tracker_url\": \"${CI_PROJECT_URL}/issues\", + \"website_url\": \"${CI_PROJECT_URL}\", + \"desc_url\": \"${CI_PROJECT_URL}\", + \"labels\": [\"borg\", \"borgbackup\", \"binaries\"], + \"public_download_numbers\": true, + \"public_stats\": true +}" + +echo "Creating package ${PKG_NAME}..." +${CURL} -X POST -d "${DATA}" "${API}/packages/${BINTRAY_REPO}" + +for BIN in $(ls borg-${VERSION}-*); do + LOG=$(mktemp) + ARCH=$(echo "${BIN}" | cut -d/ -f4 | cut -d- -f3) + UPSTREAM="borg-${VERSION}-${ARCH}" + STATUS_CODE=$( + ${CURL} --write-out %{http_code} --silent --output "${LOG}" \ + -T "${BIN}" -H X-Bintray-Package:"${PKG_NAME}" -H X-Bintray-Version:"${VERSION}" \ + "${API}/content/${BINTRAY_REPO}/${UPSTREAM}" + ) + + if [ $STATUS_CODE -eq 201 ]; then + echo "Publishing ${UPSTREAM}..." + echo $( + ${CURL} -X POST -d "{ \"discard\": \"false\" }" \ + ${API}/content/${BINTRAY_REPO}/${PKG_NAME}/${VERSION}/publish + ) + else + echo "Cannot publish ${UPSTREAM}!" && cat ${LOG} && exit 1 + fi + rm "${LOG}" +done diff --git a/extract.sh b/extract.sh index b053c67..9ac1cb0 100755 --- a/extract.sh +++ b/extract.sh @@ -1,19 +1,24 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh -# Usage: ./extract.sh [] +# Usage: ./extract.sh [] [] -BORG_ARCH=${1:-aarch64} -BORG_BINARY=${2:-borg-${BORG_ARCH}} +BORG_ARCH=${1} +BORG_VERSION=${2:-1.1.7} +BORG_BINARY=${3:-borg-${BORG_VERSION}-${BORG_ARCH}} -#if [[ "$(docker images -q "borg:${BORG_ARCH}" 2> /dev/null)" == "" ]]; then -if ! docker inspect "borg:${BORG_ARCH}" >/dev/null 2>&1; then - echo "Couldn't find the 'borg:${BORG_ARCH}' image!" - echo "Create the image first, using './build.sh ${BORG_ARCH}'" - exit 1 +DOCKER_IMAGE=borg:${BORG_VERSION}-${BORG_ARCH} + +if [ -z "${BORG_ARCH}" ]; then + echo "Usage: ./build.sh []"; + echo "No arch provided"; + exit 1; fi -#docker run -v "${PWD}":"/opt/mount" --rm --entrypoint \ -# cp "borg:${BORG_ARCH}" "/usr/bin/borg" "/opt/mount/${BORG_BINARY}" +if ! docker inspect "${DOCKER_IMAGE}" >/dev/null 2>&1; then + echo "Couldn't find the '${DOCKER_IMAGE}' docker image!" + echo "Create the image first, using './build.sh ${BORG_ARCH} ${BORG_VERSION}'" + exit 1 +fi -docker run --rm --entrypoint cat "borg:${BORG_ARCH}" /usr/bin/borg > "${BORG_BINARY}" +docker run --rm --entrypoint cat "${DOCKER_IMAGE}" /usr/bin/borg > "${BORG_BINARY}" chmod +x "${BORG_BINARY}" -- GitLab