|
| 1 | +--- |
| 2 | +kind: pipeline |
| 3 | +name: default |
| 4 | + |
| 5 | +# Disable default clone |
| 6 | +clone: |
| 7 | + disable: true |
| 8 | + |
| 9 | +steps: |
| 10 | + # This clone step doesn't use "root" user |
| 11 | + - name: clone |
| 12 | + image: plugins/git:next |
| 13 | + |
| 14 | + # Restore cache of downloaded dependencies |
| 15 | + - name: restore cache |
| 16 | + image: drillster/drone-volume-cache |
| 17 | + settings: |
| 18 | + restore: true |
| 19 | + mount: |
| 20 | + - .sbt |
| 21 | + - .ivy2 |
| 22 | + - www/node_modules |
| 23 | + volumes: [{name: cache, path: /cache}] |
| 24 | + |
| 25 | + # Run project tests |
| 26 | + - name: run tests and build stage |
| 27 | + image: thehiveproject/drone-scala-node |
| 28 | + commands: |
| 29 | + - . ~/.nvm/nvm.sh |
| 30 | + - sbt -Duser.home=$PWD test stage |
| 31 | + |
| 32 | + # Build packages |
| 33 | + - name: build packages |
| 34 | + image: thehiveproject/drone-scala-node |
| 35 | + settings: |
| 36 | + pgp_key: {from_secret: pgp_key} |
| 37 | + commands: |
| 38 | + - | |
| 39 | + . ~/.nvm/nvm.sh |
| 40 | + [ -n "$PLUGIN_PGP_KEY" ] && gpg --batch --import - <<< $PLUGIN_PGP_KEY |
| 41 | + sbt -Duser.home=$PWD docker:stage debian:packageBin rpm:packageBin universal:packageBin |
| 42 | + when: |
| 43 | + event: [tag] |
| 44 | + |
| 45 | + # Save external libraries in cache |
| 46 | + - name: save cache |
| 47 | + image: drillster/drone-volume-cache |
| 48 | + settings: |
| 49 | + rebuild: true |
| 50 | + mount: |
| 51 | + - .sbt |
| 52 | + - .ivy2 |
| 53 | + - www/node_modules |
| 54 | + volumes: [{name: cache, path: /cache}] |
| 55 | + |
| 56 | + - name: publish packages |
| 57 | + image: thehiveproject/drone-bintray |
| 58 | + settings: |
| 59 | + user: {from_secret: bintray_user} |
| 60 | + key: {from_secret: bintray_key} |
| 61 | + subject: thehive-project |
| 62 | + package: cortex |
| 63 | + commands: |
| 64 | + - | |
| 65 | + export PLUGIN_USER |
| 66 | + export PLUGIN_KEY |
| 67 | + export PLUGIN_SUBJECT |
| 68 | + export PLUGIN_PACKAGE |
| 69 | + export PLUGIN_VERSION=$(cut -d\" -f2 version.sbt) |
| 70 | + echo "Publishing package version $PLUGIN_VERSION" |
| 71 | +
|
| 72 | + if echo $PLUGIN_VERSION | grep -qvi -E \ |
| 73 | + -e '^[0-9]+\.[0-9]+\.[0-9]+$' \ |
| 74 | + -e '^[0-9]+\.[0-9]+\.[0-9]+-[0-9]+$' \ |
| 75 | + -e '^[0-9]+\.[0-9]+\.[0-9]+-RC[0-9]+$'; then |
| 76 | + echo The version $PLUGIN_VERSION has invalid format |
| 77 | + exit 1 |
| 78 | + fi |
| 79 | +
|
| 80 | + CHANNEL=stable |
| 81 | + echo $PLUGIN_VERSION | grep -qi rc && CHANNEL=beta |
| 82 | +
|
| 83 | + DEB_FILE=target/cortex_$${PLUGIN_VERSION}_all.deb |
| 84 | + RPM_FILE=target/rpm/RPMS/noarch/cortex-$${PLUGIN_VERSION}.noarch.rpm |
| 85 | + ZIP_FILE=target/universal/cortex-$${PLUGIN_VERSION}.zip |
| 86 | +
|
| 87 | + upload \ |
| 88 | + --file $DEB_FILE \ |
| 89 | + --repo debian-beta \ |
| 90 | + --extra-param deb_distribution=any \ |
| 91 | + --extra-param deb_component=main \ |
| 92 | + --extra-param deb_architecture=all |
| 93 | +
|
| 94 | + [ $CHANNEL = stable ] && upload \ |
| 95 | + --file $DEB_FILE \ |
| 96 | + --repo debian-stable \ |
| 97 | + --extra-param deb_distribution=any \ |
| 98 | + --extra-param deb_component=main \ |
| 99 | + --extra-param deb_architecture=all |
| 100 | +
|
| 101 | + upload \ |
| 102 | + --file $RPM_FILE \ |
| 103 | + --repo rpm-beta |
| 104 | +
|
| 105 | + [ $CHANNEL = stable ] && upload \ |
| 106 | + --file $RPM_FILE \ |
| 107 | + --repo rpm-stable |
| 108 | +
|
| 109 | + upload \ |
| 110 | + --file $ZIP_FILE \ |
| 111 | + --repo binary |
| 112 | +
|
| 113 | + LATEST_VERSION=latest |
| 114 | + [ $CHANNEL = beta ] && LATEST_VERSION=latest-beta |
| 115 | +
|
| 116 | + removeVersion \ |
| 117 | + --repo binary \ |
| 118 | + --version $LATEST_VERSION |
| 119 | +
|
| 120 | + upload \ |
| 121 | + --file $ZIP_FILE \ |
| 122 | + --repo binary \ |
| 123 | + --version $LATEST_VERSION \ |
| 124 | + --dest-file cortex-$${LATEST_VERSION}.zip |
| 125 | + when: |
| 126 | + event: [tag] |
| 127 | + |
| 128 | + # Publish docker image |
| 129 | + - name: docker |
| 130 | + image: plugins/docker |
| 131 | + settings: |
| 132 | + context: target/docker/stage |
| 133 | + dockerfile: target/docker/stage/Dockerfile |
| 134 | + repo: tooom/cortex |
| 135 | + auto_tag: true |
| 136 | + username: {from_secret: docker_username} |
| 137 | + password: {from_secret: docker_password} |
| 138 | + when: |
| 139 | + event: [tag] |
| 140 | + |
| 141 | + - name: copy binaries |
| 142 | + image: appleboy/drone-scp |
| 143 | + settings: |
| 144 | + host: {from_secret: deploy_beta_host} |
| 145 | + username: {from_secret: deploy_username} |
| 146 | + key: {from_secret: deploy_key} |
| 147 | + target: ./cortex-builds/${DRONE_BUILD_NUMBER} |
| 148 | + source: target/universal/stage |
| 149 | + strip_components: 3 |
| 150 | + |
| 151 | + - name: deploy binaries |
| 152 | + image: appleboy/drone-ssh |
| 153 | + settings: |
| 154 | + host: {from_secret: deploy_beta_host} |
| 155 | + username: {from_secret: deploy_username} |
| 156 | + key: {from_secret: deploy_key} |
| 157 | + script: |
| 158 | + - ./start cortex ${DRONE_BUILD_NUMBER} |
| 159 | + |
| 160 | +volumes: |
| 161 | + - name: cache |
| 162 | + host: |
| 163 | + path: /opt/drone/cache |
0 commit comments