A peer-to-peer stack for code collaboration
Package infrastructure and Debian packages
Thomas Scholtese903dd832e41
diff --git a/README.md b/README.mdindex d18da88..ac1c4cc 100644--- a/README.md+++ b/README.md@@ -85,6 +85,17 @@ with the output of `docker-machine ip`.You can reset the test daemon’s machine configuration by removing the file`/tmp/radicle-machines.json`.+### Packaging++Packages can be built with the `./packaging/build-package.sh` script. Run it+with `-h` for more information. The script requires [`fpm`][fpm].++On CI a Debian package is built for every commit and uploaded to+`http://static.radicle.xyz/releases`. The package uses the commit hash as the+version.++[fpm]: https://github.com/jordansissel/fpm+### TroubleshootingYour local machine might build binaries that are incompatible with thediff --git a/bin/rad-daemon-ipfs b/bin/rad-daemon-ipfsindex 2a7f109..702a5ce 100755--- a/bin/rad-daemon-ipfs+++ b/bin/rad-daemon-ipfs@@ -1,27 +1,38 @@-#!/usr/bin/env bash+#!/usr/bin/env bash## Run the IPFS daemon with configuration for the Radicle network.set -euo pipefail+vendored_ipfs=/usr/lib/radicle/bin/ipfs+if which ipfs >/dev/null 2>/dev/null; then+ ipfs=ipfs+elif [ -f "$vendored_ipfs" ]; then+ ipfs=$vendored_ipfs+else+ echo "ERROR: Command not found: ipfs" 1>&2+ echo "To install IPFS follow the instructions here: https://docs.ipfs.io/introduction/install/" 1>&2+ exit 1+fi+export IPFS_PATH=${IPFS_PATH:-"$HOME/.local/share/radicle/ipfs"}if [[ ! -f "$IPFS_PATH/config" ]]; thenmkdir -p "$IPFS_PATH"- ipfs init+ $ipfs initcat >"$IPFS_PATH/swarm.key" <<DOC/key/swarm/psk/1.0.0//base16/420076a5ac043665bf6b78ebff1bbf17b3d5b29919e38792ff3e430cf889cef8DOC- ipfs bootstrap rm all- ipfs bootstrap add \+ $ipfs bootstrap rm all+ $ipfs bootstrap add \"/ip4/35.187.83.104/tcp/4000/ipfs/QmQqaBdD5g9o4L6KEtjL1RJbTSbb9gxUWgSF7FBxBqwvjr" \"/ip4/35.187.83.104/tcp/4001/ipfs/QmVdMvYQL6WuC4uaKV39SpQfNMmEZptzf6hoXenkcHKozU"- echo '{"radicle": true}' | ipfs dag put --pin+ echo '{"radicle": true}' | $ipfs dag put --pin- ipfs config Addresses.API "/ip4/127.0.0.1/tcp/9301"- ipfs config Addresses.Gateway "/ip4/127.0.0.1/tcp/9302"- ipfs config --json Addresses.Swarm '["/ip4/0.0.0.0/tcp/9303", "/ip6/::/tcp/9303"]'+ $ipfs config Addresses.API "/ip4/127.0.0.1/tcp/9301"+ $ipfs config Addresses.Gateway "/ip4/127.0.0.1/tcp/9302"+ $ipfs config --json Addresses.Swarm '["/ip4/0.0.0.0/tcp/9303", "/ip6/::/tcp/9303"]'fi-ipfs daemon --enable-pubsub-experiment "$@"+exec $ipfs daemon --enable-pubsub-experiment "$@"diff --git a/bin/rad-ipfs b/bin/rad-ipfsindex 5931e48..2959980 100755--- a/bin/rad-ipfs+++ b/bin/rad-ipfs@@ -7,6 +7,17 @@set -eo pipefail+vendored_ipfs=/usr/lib/radicle/bin/ipfs+if which ipfs >/dev/null 2>/dev/null; then+ ipfs=ipfs+elif [ -f "$vendored_ipfs" ]; then+ ipfs=$vendored_ipfs+else+ echo "ERROR: Command not found: ipfs" 1>&2+ echo "To install IPFS follow the instructions here: https://docs.ipfs.io/introduction/install/" 1>&2+ exit 1+fi+if [ -n "$RAD_IPFS_API_URL" ]; thenapi_url=$(echo "$RAD_IPFS_API_URL" | sed -n -E \-e "s/^http:\/\/([a-zA-Z0-9_\.\-]+):([0-9]{1,5})/\/dns4\/\1\/tcp\/\2/;tprint" \@@ -21,4 +32,4 @@ elseapi_url="/ip4/127.0.0.1/tcp/9301"fi-IPFS_PATH=${IPFS_PATH:-"$HOME/.local/share/radicle/ipfs"} exec ipfs --api "$api_url" "$@"+IPFS_PATH=${IPFS_PATH:-"$HOME/.local/share/radicle/ipfs"} exec $ipfs --api "$api_url" "$@"diff --git a/ci/Dockerfile b/ci/Dockerfileindex 9568a39..c57d0e5 100644--- a/ci/Dockerfile+++ b/ci/Dockerfile@@ -13,16 +13,24 @@ FROM haskell:8.6.3ENTRYPOINT []-# Install `gcloud` and `gsutil`+# Install `gcloud`, `gsutil` and dependencies of `fpm`.ADD https://packages.cloud.google.com/apt/doc/apt-key.gpg google-apt-key.gpgRUN \echo "deb http://packages.cloud.google.com/apt cloud-sdk-stretch main" \> /etc/apt/sources.list.d/google-cloud-sdk.list && \apt-key add google-apt-key.gpg && \apt-get update -yqq && \- apt-get -yq install google-cloud-sdk && \+ apt-get -yq install \+ build-essential \+ ruby \+ ruby-dev \+ rubygems \+ google-cloud-sdk && \rm -rf /var/lib/apt/lists/*+# Install `fpm`+RUN gem install --no-ri --no-rdoc fpm+# Install `docker`ADD https://download.docker.com/linux/static/stable/x86_64/docker-18.09.2.tgz docker.tgzRUN \diff --git a/cloudbuild.yaml b/cloudbuild.yamlindex d805751..9e84fde 100644--- a/cloudbuild.yaml+++ b/cloudbuild.yaml@@ -1,7 +1,7 @@timeout: 3600s # Cache misses are slow to rebuildsubstitutions:# Bump the version if you make changes to `ci/Dockerfile- _BUILD_IMAGE: eu.gcr.io/opensourcecoin/radicle-ci:v2+ _BUILD_IMAGE: eu.gcr.io/opensourcecoin/radicle-ci:v3options:machineType: N1_HIGHCPU_8steps:@@ -207,3 +207,18 @@ steps:stack exec -- rad-daemon-radicle &stack test :e2e++ - id: "Package"+ waitFor:+ - "Integration tests"+ name: $_BUILD_IMAGE+ env: ['STACK_ROOT=/workspace/.stack']+ entrypoint: 'bash'+ args:+ - "-c"+ - |+ set -euxo pipefail++ version="$(date +%Y.%m.%d)-$SHORT_SHA"+ VERSION=$version TARGET=debian ./packaging/build-package.sh+ ./packaging/upload.shdiff --git a/packaging/build-package.sh b/packaging/build-package.shnew file mode 100755index 0000000..1d5e220--- /dev/null+++ b/packaging/build-package.sh@@ -0,0 +1,152 @@+#!/bin/bash++set -euo pipefail++function help () {+ cat <<DOC+Usage: TARGET=<target> VERSION=<version> $0++Builds package for a given target and puts it into ./packaging/out.++ENVIRONMENT VARIABLES++ TARGET (required)+ The packaging target. Available targets are++ - debian+ - pacman++ VERSION (required)+ Version of the package.++ STACK_USE_DOCKER+ If set to '1' then 'stack' is invoked with the '--docker' flag.+ This means the build outputs from 'stack build --docker' are+ used.+DOC+}+++# Wrapper for the stack that uses docker if `STACK_USE_DOCKER` is set+# to `1`.+function stack () {+ if [ "${STACK_USE_DOCKER:-0}" = "1" ]; then+ /usr/bin/env stack --docker "$@"+ else+ /usr/bin/env stack "$@"+ fi+}++# Creates an executable file `$1` with content from stdin.+function install-stdin () {+ local target=$1+ mkdir -p $(dirname "$target")+ cat >"$target"+ chmod +x "$target"+}++# Download the `ipfs` binary and put it into the directory `$1`.+function get-ipfs () {+ local target_dir=$1+ mkdir -p "$target_dir"+ curl \+ --fail \+ --silent \+ --show-error \+ --location \+ "https://dist.ipfs.io/go-ipfs/v0.4.18/go-ipfs_v0.4.18_linux-amd64.tar.gz" \+ | tar -xz --strip-components=1 -C "$target_dir" go-ipfs/ipfs+}++function prepare-package-root () {+ install-stdin "$package_root/usr/bin/rad" <<EOF+#!/bin/sh+export radicle_bindir=$radicle_bindir+export RADPATH=\${RADPATH:-$radpath}+exec $radicle_bindir/rad "\$@"+EOF++ install-stdin "$package_root/usr/bin/radicle" <<EOF+#!/bin/sh+export radicle_bindir=$radicle_bindir+export RADPATH=\${RADPATH:-$radpath}+exec $radicle_bindir/radicle "\$@"+EOF++ install -D $(stack exec -- which git-remote-ipfs) -t "$package_root/usr/bin"++ install -D -t "$package_root/$radicle_bindir" $stack_bin_install_dir/radicle+ install -D -t "$package_root/$radicle_bindir" $stack_bin_install_dir/rad+ install -D -t "$package_root/$radicle_bindir" $stack_bin_install_dir/rad-*++ install -D --mode 0644 "$project_dir/packaging/radicle-ipfs.service" -t "$package_root/usr/lib/systemd/user"+ install -D --mode 0644 "$project_dir/packaging/radicle-daemon.service" -t "$package_root/usr/lib/systemd/user"++ mkdir -p "$package_root/$radpath"+ cp --archive $project_dir/rad -T "$package_root/$radpath"++ get-ipfs "$package_root/$radicle_bindir"+}++function package () {+ pushd $project_dir/packaging/out+ fpm \+ --verbose \+ --force \+ --input-type dir \+ --name radicle \+ --version $VERSION \+ "$@" \+ "$package_root/=/"+ popd+}++function package-pacman () {+ package \+ --output-type pacman \+ --depends git \+ --depends go-ipfs \+ --pacman-compression none+}++function package-debian () {+ package \+ --output-type deb \+ --depends git \+ --depends libgmp10 \+ --depends libc6 \+ --depends libncurses5+}+++if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then+ help+ exit 0+fi++if test -z ${TARGET:-}; then+ echo "error: TARGET is not set."+ exit 1+fi++if ! type package-$TARGET 2>/dev/null 1>/dev/null; then+ echo "error: Unknown package target \"$TARGET\""+ exit 1+fi++if test -z "${VERSION:-}"; then+ echo "error: VERSION is not set"+ exit 1+fi++set -x++project_dir=$(realpath "$(dirname $BASH_SOURCE)/..")+radicle_bindir=/usr/lib/radicle/bin+radpath=/usr/lib/radicle/modules+stack_bin_install_dir=$(stack path --local-install-root)/bin++package_root=$(mktemp -td "radicle-package.XXXX")+prepare-package-root+package-$TARGET+rm -rf "$package_root"diff --git a/packaging/out/.gitignore b/packaging/out/.gitignorenew file mode 100644index 0000000..72e8ffc--- /dev/null+++ b/packaging/out/.gitignore@@ -0,0 +1 @@+*diff --git a/packaging/radicle-daemon.service b/packaging/radicle-daemon.servicenew file mode 100644index 0000000..9fd2f07--- /dev/null+++ b/packaging/radicle-daemon.service@@ -0,0 +1,11 @@+[Unit]+Description=Radicle daemon for interacting with Radicle machines+Requires=radicle-ipfs.service++[Service]+ExecStart=/usr/bin/rad daemon-radicle+SyslogIdentifier=radicle-daemon++[Install]+WantedBy=default.target+diff --git a/packaging/radicle-ipfs.service b/packaging/radicle-ipfs.servicenew file mode 100644index 0000000..07fb9b9--- /dev/null+++ b/packaging/radicle-ipfs.service@@ -0,0 +1,10 @@+[Unit]+Description=IPFS daemon for the Radicle network++[Service]+ExecStart=/usr/bin/rad daemon-ipfs+Restart=on-failure+SyslogIdentifier=radicle-ipfs++[Install]+WantedBy=default.targetdiff --git a/packaging/upload.sh b/packaging/upload.shnew file mode 100755index 0000000..f349da0--- /dev/null+++ b/packaging/upload.sh@@ -0,0 +1,9 @@+#!/bin/bash++set -euxo pipefail++package_dir=$(realpath "$(dirname $BASH_SOURCE)/out")++for pkg in $package_dir/radicle*; do+ gsutil -m cp $pkg gs://static.radicle.xyz/releases+done