diff --git a/.github/workflows/mrd_storage_server_conda.yml b/.github/workflows/mrd_storage_server_conda.yml new file mode 100644 index 0000000..de7a3df --- /dev/null +++ b/.github/workflows/mrd_storage_server_conda.yml @@ -0,0 +1,37 @@ +on: + pull_request: + branches: + - main + release: + types: + - created + +jobs: + build-conda-packages: + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b + - uses: conda-incubator/setup-miniconda@e81abac10ce2c37423b54eae5af93aa3b4d3475c + with: + activate-environment: mrd-storage-server-build + environment-file: conda/environment.yml + python-version: 3.9 + auto-activate-base: false + - name: Build conda package + shell: bash -l {0} + working-directory: conda + run: | + export GIT_DESCRIBE_TAG="${GITHUB_REF##*/}" + ./package.sh + echo "Packages built: $(find build_pkg -name mrd-storage-server*.tar.bz2)" + - name: Push conda package + shell: bash -l {0} + if: ${{ github.event_name == 'release' }} + env: + ANACONDA_TOKEN: ${{ secrets.ANACONDA_TOKEN }} + working-directory: conda + run: | + ./publish_package.sh -u ismrmrd -t "$ANACONDA_TOKEN" -p `find build_pkg -name mrd-storage-server*.tar.bz2` diff --git a/conda/.gitignore b/conda/.gitignore new file mode 100644 index 0000000..846c4f9 --- /dev/null +++ b/conda/.gitignore @@ -0,0 +1,3 @@ +build_pkg/ +.pytest_cache/ +__pycache__/ \ No newline at end of file diff --git a/conda/build.sh b/conda/build.sh new file mode 100755 index 0000000..9571aa5 --- /dev/null +++ b/conda/build.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -euo pipefail + +go build -o "${PREFIX}/bin/mrd-storage-server" . \ No newline at end of file diff --git a/conda/environment.yml b/conda/environment.yml new file mode 100644 index 0000000..2cd260e --- /dev/null +++ b/conda/environment.yml @@ -0,0 +1,7 @@ +name: mrd-storage-server-build +channels: + - conda-forge +dependencies: + - conda-build + - anaconda-client + diff --git a/conda/meta.yaml b/conda/meta.yaml new file mode 100644 index 0000000..1c1ed3e --- /dev/null +++ b/conda/meta.yaml @@ -0,0 +1,26 @@ +package: + name: mrd-storage-server + version: {{ GIT_DESCRIBE_TAG | replace ("v","") }} + +source: + path: ../ + +requirements: + build: + - go-cgo=1.17.6 + + run: {} + +test: + requires: + - curl + +about: + home: https://github.com/ismrmrd/mrd-storage-server + license: MIT + summary: 'A simple queryable storage server' + description: | + A simple RESTful server for storing and retrieving arbitrary data during MRI reconstructions. + dev_url: https://github.com/ismrmrd/mrd-storage-server + doc_url: https://github.com/ismrmrd/mrd-storage-server + doc_source_url: https://github.com/ismrmrd/mrd-storage-server/blob/main/README.md \ No newline at end of file diff --git a/conda/package.sh b/conda/package.sh new file mode 100755 index 0000000..cd4ae34 --- /dev/null +++ b/conda/package.sh @@ -0,0 +1,24 @@ +#!/bin/bash +set -euo pipefail + +usage() +{ + cat << EOF + +Builds the mrd-storage-server conda package. + +Usage: $0 +EOF +} + +output_path="$(dirname "$0")/build_pkg" + +# Build up channel directives +channels=( + conda-forge +) + +channel_directives=$(printf -- "-c %s " "${channels[@]}") + +mkdir -p "$output_path" +bash -c "conda build --no-anaconda-upload --output-folder $output_path $channel_directives $(dirname "$0")" diff --git a/conda/publish_package.sh b/conda/publish_package.sh new file mode 100755 index 0000000..6c3b922 --- /dev/null +++ b/conda/publish_package.sh @@ -0,0 +1,77 @@ +#!/bin/bash +set -euo pipefail + +usage() +{ + cat << EOF + +Publishes a conda package. + +Usage: $0 [options] + +Options: + -p|--package_path Path to the package (tar.gz) to push + -u|--user Anaconda.org channeluser or organization + -t|--token Token for uploading to anaconda.org + -f|--force Force push even if package exists + -h| --help Brings up this menu +EOF +} + +while [[ $# -gt 0 ]]; do + key="$1" + + case $key in + -p|--package_path) + package_path="$2" + shift + shift + ;; + -u|--user) + user="$2" + shift + shift + ;; + -t|--token) + token="$2" + shift + shift + ;; + --force) + force=1 + shift + ;; + -h|--help) + usage + exit + ;; + *) + echo "ERROR: unknown option \"$key\"" + usage + exit 1 + ;; + esac +done + +if [[ -z "${package_path:-}" ]]; then + echo "You cannot push to anaconda without a package" + echo "Please supply a package path with the --package_path argument" + exit 1 +fi +if [[ -z "${token:-}" ]]; then + echo "You cannot push to anaconda without a token" + echo "Please supply a token with the --token argument" + exit 1 +fi +if [[ -z "${user:-}" ]]; then + echo "You cannot push to anaconda without a user" + echo "Please supply a user with the --user argument" + exit 1 +fi + +force_directive="--skip-existing" +if [[ -n ${force:-} ]]; then + force_directive="--force" +fi + +anaconda -t "$token" upload -u "$user" $force_directive "$package_path" diff --git a/conda/run_test.sh b/conda/run_test.sh new file mode 100644 index 0000000..8d2d270 --- /dev/null +++ b/conda/run_test.sh @@ -0,0 +1,36 @@ +#! /bin/bash + +set -euo pipefail + +trap 'kill $(jobs -p)' EXIT + +mrd-storage-server & + +url_root="http://localhost:3333" + +health_check_endpoint="${url_root}/v1/blobs?subject=123" +echo "Waiting for successful response from ${health_check_endpoint}" +for wait in {0..30}; do + if [[ "$(curl -s -o /dev/null -m 1 -w '%{http_code}' "$health_check_endpoint")" == "200" ]]; then + echo "Server ready" + break + fi + if [ "$wait" == 30 ]; then + echo "ERROR: could not reach server" + fi + echo "Waiting...$wait" + sleep 1 +done + +content='This is my content' +curl --request POST \ + "${url_root}/v1/blobs/data?subject=123&session=mysession&name=NoiseCovariance" \ + --header 'content-type: text/plain' \ + --data "$content" + +response_content=$(curl -s --request GET "${url_root}/v1/blobs/data/latest?subject=123&session=mysession&name=NoiseCovariance") + +if [[ "${response_content}" != "${content}" ]]; then + echo "ERROR: Did not get expected result from server. Response = ${response_content}" + exit 1 +fi \ No newline at end of file