diff --git a/.woodpecker/build_bin.yml b/.woodpecker/build_bin.yml index 5de56b2..4ce4725 100644 --- a/.woodpecker/build_bin.yml +++ b/.woodpecker/build_bin.yml @@ -1,9 +1,13 @@ pipeline: bin-pack: - image: debian:stable-slim + image: debian-pack:0.1 + secrets: + - WEBDAV_USER + - WEBDAV_PASS + - WEBDAV_HOST + - WEBDAV_REPOPATH commands: - - source script/build_single.sh - - build_single ${BIN_PACK} + - ./script/build_single.sh $BIN_PACK matrix: BIN_PACK: diff --git a/.woodpecker/build_other.yml b/.woodpecker/build_other.yml index 1f00c3f..3904905 100644 --- a/.woodpecker/build_other.yml +++ b/.woodpecker/build_other.yml @@ -1,13 +1,21 @@ pipeline: dendrite: image: golang + secrets: + - WEBDAV_USER + - WEBDAV_PASS + - WEBDAV_HOST + - WEBDAV_REPOPATH commands: - - source script/build_single.sh - - build_single dendrite + - ./script/build_single.sh dendrite static-deployer-git: - image: debian:stable-slim + image: debian-pack:0.1 + secrets: + - WEBDAV_USER + - WEBDAV_PASS + - WEBDAV_HOST + - WEBDAV_REPOPATH commands: - - source script/build_single.sh - - build_single static-deployer-git + - ./script/build_single.sh static-deployer-git diff --git a/.woodpecker/debian-pack.df b/.woodpecker/debian-pack.df new file mode 100644 index 0000000..57748af --- /dev/null +++ b/.woodpecker/debian-pack.df @@ -0,0 +1,6 @@ +FROM debian:bullseye-slim + +RUN apt update && \ + apt install --yes curl ca-certificates && \ + apt clean && \ + rm -rf /var/lib/apt/lists/* diff --git a/script/build_all.sh b/script/build_all.sh old mode 100644 new mode 100755 index f5a9377..e4b9445 --- a/script/build_all.sh +++ b/script/build_all.sh @@ -1,53 +1,6 @@ #!/usr/bin/evn bash -# -set -o pipefail -set -o errexit -set -o errtrace - -WEBDAV_USER=${WEBDAV_USER:?WEBDAV_USER not set} -WEBDAV_PASS=${WEBDAV_PASS:?WEBDAV_PASS not set} -WEBDAV_HOST=${WEBDAV_HOST:?WEBDAV_HOST not set} -WEBDAV_REPOPATH=${WEBDAV_REPOPATH:?WEBDAV_REPOPATH not set} - -function curl_alias { - curl --show-error --silent --user "${WEBDAV_USER}:${WEBDAV_PASS}" "$@" -} - -function webdav_is_file_exists { - local target="${1%/}" - local target="${target#/}" - local resp=$(curl_alias --head --write-out "%{http_code}" "${WEBDAV_HOST}/${WEBDAV_REPOPATH}/${target}" | tail -n 1) - [[ "${resp}" == "200" ]] -} - -function webdav_mkcol { - local dirname="${1#/}" - curl_alias --request MKCOL "${WEBDAV_HOST}/${dirname}" -} - -function webdav_upload_file { - curl_alias --silent --upload-file "$1" "${WEBDAV_HOST}/${WEBDAV_REPOPATH}/$2" - echo "file $1 uploaded to ${WEBDAV_HOST}/${WEBDAV_REPOPATH}/$2" -} - -function build_single { - ( - local package_name="$1" - local package_path="$(realpath "$1")" - cd "$package_path" - local target_filename="$(../makedeb/makedeb -STF | tail -n 1)" - - if webdav_is_file_exists "${target_filename}" ; then - echo "${package_name} already built, skipped." - return - fi - - ../makedeb/makedeb - - webdav_upload_file "${target_filename}" "${target_filename}" - ) -} +source $(dirname $0)/util.sh for i in $(find . -maxdepth 1 -mindepth 1 -type d -not -path './script' -not -path './makedeb' -not -name '.*') do diff --git a/script/build_single.sh b/script/build_single.sh new file mode 100755 index 0000000..0a44f67 --- /dev/null +++ b/script/build_single.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +source $(dirname $0)/util.sh + +build_single $1 diff --git a/script/util.sh b/script/util.sh new file mode 100644 index 0000000..8abae24 --- /dev/null +++ b/script/util.sh @@ -0,0 +1,49 @@ +#!/usr/bin/evn bash +# +set -o pipefail +set -o errexit +set -o errtrace + +WEBDAV_USER=${WEBDAV_USER:?WEBDAV_USER not set} +WEBDAV_PASS=${WEBDAV_PASS:?WEBDAV_PASS not set} +WEBDAV_HOST=${WEBDAV_HOST:?WEBDAV_HOST not set} +WEBDAV_REPOPATH=${WEBDAV_REPOPATH:?WEBDAV_REPOPATH not set} + +function curl_alias { + curl --show-error --silent --user "${WEBDAV_USER}:${WEBDAV_PASS}" "$@" +} + +function webdav_is_file_exists { + local target="${1%/}" + local target="${target#/}" + local resp=$(curl_alias --head --write-out "%{http_code}" "${WEBDAV_HOST}/${WEBDAV_REPOPATH}/${target}" | tail -n 1) + [[ "${resp}" == "200" ]] +} + +function webdav_mkcol { + local dirname="${1#/}" + curl_alias --request MKCOL "${WEBDAV_HOST}/${dirname}" +} + +function webdav_upload_file { + curl_alias --silent --upload-file "$1" "${WEBDAV_HOST}/${WEBDAV_REPOPATH}/$2" + echo "file $1 uploaded to ${WEBDAV_HOST}/${WEBDAV_REPOPATH}/$2" +} + +function build_single { + ( + local package_name="$1" + local package_path="$(realpath "$1")" + cd "$package_path" + local target_filename="$(../makedeb/makedeb -STF | tail -n 1)" + + if webdav_is_file_exists "${target_filename}" ; then + echo "${package_name} already built, skipped." + return + fi + + ../makedeb/makedeb + + webdav_upload_file "${target_filename}" "${target_filename}" + ) +}