github.com/cozy/cozy-stack@v0.0.0-20240603063001-31110fa4cae1/docs/registry-publish.md (about)

     1  [Table of contents](README.md#table-of-contents)
     2  
     3  # Apps registry publication
     4  
     5  ## Automate publication
     6  
     7  The following tutorial explains how to connect your continuous integration based
     8  on Travis to automatically publish new versions on the apps registry.
     9  
    10  In this tutorial, we assume:
    11  
    12  -   you have a token allowing you to publish applications for your `editor`:
    13      `AbCdEf`
    14  -   you are working on a repository plugged on travis and named on github
    15      `cozy/cozy-example`
    16  
    17  You first need to add the token to your travis configuration file `.travis.yml`.
    18  To do so, you need the
    19  [`travis` utility](https://github.com/travis-ci/travis.rb#installation) to
    20  encrypt its value.
    21  
    22  ```sh
    23  $ travis encrypt REGISTRY_TOKEN=AbCdEf --add -r cozy/cozy-example
    24  Please add the following to your .travis.yml file:
    25  
    26    secure: "jUAjkXNXfGIXyx2MKnnJ5HwCzhrQ29SaWBTmRpU6Rwi2XRieCnb2+MKZtjVcmEjfvJO38VjPozW2F4MYIxRXf9cD+ZRAEroZRcRSNHpoi/FJ6Ra767H7AbFDGpSSUSx7UDeZbSRNazCXJ55F/JaCq6F3XGeurrJbJ/tvMoIEvjg4qcOJpBgSxXEeyEnx5L3zbDoIqDo8hx9UtZoisiTC3TGq1CGFPe35VXnv/g23Uwg2Wux1drXXnMVghoVM8SDuoE9gf4LfppVHbYmowm25tylsvNKESbYiwJIkvPciPl2rABplJLJ4nuVpeWKHx1g+bChzlR5rhgXVJidua//yFD28xWS1+j+FhCGcYuPttYTntBVTiif0DVKS3gC1FFbf2ktgJVT7nYN2z0arhdPeK7Wtv8R+0SqlXUfBA/nam1pAS1xg2MTekVKxw+FmW0r6Ct4/Dta4d4XWsYiPMBrUOaCAqo+TkxBrVvM/LcM91ua33GKzMRLmKgbDY2k7lQpt3xA0Se02p4yiWcpN+3JzwVNRkuAQfw79ItJzhBP7ZTaQMwDByD/sN4ybhICWxTOLRh6kgfw+Xxv86aADvMVwfPcLljfk5Ot3kfLyaIyqrkIF9ePGSblt7RGzHiOECFr8qUtoGQAfekM+NmKzFSkeJU8t0EvHMen1NOsZhTemx9Q="
    27  ```
    28  
    29  Like said, you need to add this block of ciphered data in the `.travis.yml`.
    30  This will allow you to use the `REGISTRY_TOKEN` variable in your deployment
    31  script.
    32  
    33  Then you can adapt this script as your
    34  [`after_deploy` or `after_success`](https://docs.travis-ci.com/user/customizing-the-build#The-Build-Lifecycle)
    35  script.
    36  
    37  It contains environment variables that you can adapt as your need:
    38  
    39  -   `COZY_APP_VERSION`: the version string of the deployed version
    40  -   `COZY_APP_PARAMETERS`: an optional JSON object (string, object or array)
    41      that will parameterize the application on its execution.
    42  -   `COZY_BUILD_URL`: the URL of the deployed tarball for your application
    43  -   `COZY_BUILD_BRANCH`: the name of the build branch from which the script
    44      creates dev releases
    45  
    46  ```bash
    47  #!/bin/bash
    48  set -e
    49  
    50  # Environnment variables:
    51  #   COZY_APP_VERSION: the version string of the deployed version
    52  #   COZY_BUILD_URL: the URL of the deployed tarball for your application
    53  #   COZY_BUILD_BRANCH: the name of the build branch from which the script
    54  #                      creates dev releases
    55  
    56  [ -z "${COZY_BUILD_BRANCH}" ] && COZY_BUILD_BRANCH="master"
    57  [ -z "${COZY_APP_PARAMETERS}" ] && COZY_APP_PARAMETERS="null"
    58  
    59  if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then
    60      echo "No deployment: in pull-request"
    61      exit 0
    62  fi
    63  
    64  if [ "${TRAVIS_BRANCH}" != "${COZY_BUILD_BRANCH}" ] && [ -z "${TRAVIS_TAG}" ]; then
    65      printf 'No deployment: not in %s branch nor tag (TRAVIS_BRANCH=%s TRAVIS_TAG=%s)\n' "${COZY_BUILD_BRANCH}" "${TRAVIS_BRANCH}" "${TRAVIS_TAG}"
    66      exit 0
    67  fi
    68  
    69  if ! jq <<< "${COZY_APP_PARAMETERS}" > /dev/null; then
    70    printf "Could not parse COZY_APP_PARAMETERS=%s as JSON\n" "${COZY_APP_PARAMETERS}"
    71    exit 1
    72  fi
    73  
    74  if [ -z "${COZY_APP_VERSION}" ]; then
    75      if [ -n "${TRAVIS_TAG}" ]; then
    76          COZY_APP_VERSION="${TRAVIS_TAG}"
    77      else
    78          manfile=$(find "${TRAVIS_BUILD_DIR}" \( -name "manifest.webapp" -o -name "manifest.konnector" \) | head -n1)
    79          COZY_APP_VERSION="$(jq -r '.version' < "${manfile}")-dev.${TRAVIS_COMMIT}"
    80      fi
    81  fi
    82  
    83  if [ -z "${COZY_BUILD_URL}" ]; then
    84      url="https://github.com/${TRAVIS_REPO_SLUG}/archive"
    85      if [ -n "${TRAVIS_TAG}" ]; then
    86          COZY_BUILD_URL="${url}/${TRAVIS_TAG}.tar.gz"
    87      else
    88          COZY_BUILD_URL="${url}/${TRAVIS_COMMIT}.tar.gz"
    89      fi
    90  fi
    91  
    92  shasum=$(curl -sSL --fail "${COZY_BUILD_URL}" | shasum -a 256 | cut -d" " -f1)
    93  
    94  printf 'Publishing version "%s" from "%s" (%s)\n' "${COZY_APP_VERSION}" "${COZY_BUILD_URL}\n" "${shasum}"
    95  
    96  curl -sS --fail -X POST \
    97      -H "Content-Type: application/json" \
    98      -H "Authorization: Token ${REGISTRY_TOKEN}" \
    99      -d "{\"version\": \"${COZY_APP_VERSION}\", \"url\": \"${COZY_BUILD_URL}\", \"sha256\": \"${shasum}\", \"parameters\": ${COZY_APP_PARAMETERS}}" \
   100      "https://registry.cozy.io/registry/versions"
   101  ```
   102  
   103  ## Access to our official apps registry
   104  
   105  In order to access to our official repository, you need a token for a specific
   106  editor. To do so, concact us directly at the address contact@cozycloud.cc with a
   107  mail using the following title prefix: `[registry]` and precising the name of
   108  the editor of your application.
   109  
   110  We will provide you with the correct token.