|
1 | 1 | --- |
2 | 2 | kind: pipeline |
3 | 3 | name: default |
4 | | - |
5 | | -# Disable default clone |
6 | | -clone: |
7 | | - disable: true |
| 4 | +type: docker |
8 | 5 |
|
9 | 6 | steps: |
10 | | - # This clone step doesn't use "root" user |
11 | | - - name: clone |
12 | | - image: plugins/git:next |
13 | | - |
14 | 7 | # Restore cache of downloaded dependencies |
15 | | - - name: restore cache |
| 8 | + - name: restore-cache |
16 | 9 | image: drillster/drone-volume-cache |
17 | 10 | settings: |
18 | 11 | restore: true |
19 | 12 | mount: |
20 | 13 | - .sbt |
21 | 14 | - .ivy2 |
22 | | - - www/node_modules |
| 15 | + - ui/node_modules |
| 16 | + - ui/bower_components |
23 | 17 | volumes: [{name: cache, path: /cache}] |
24 | 18 |
|
25 | 19 | # Run project tests |
26 | | - - name: run tests and build stage |
| 20 | + - name: run-tests |
27 | 21 | image: thehiveproject/drone-scala-node |
28 | 22 | commands: |
29 | | - - . ~/.nvm/nvm.sh |
30 | | - - sbt -Duser.home=$PWD test stage |
| 23 | + - sbt -Duser.home=$PWD test:compile test |
31 | 24 |
|
32 | 25 | # Build packages |
33 | | - - name: build packages |
| 26 | + - name: build-packages |
34 | 27 | image: thehiveproject/drone-scala-node |
35 | 28 | settings: |
36 | 29 | pgp_key: {from_secret: pgp_key} |
37 | 30 | commands: |
38 | 31 | - | |
| 32 | + V=$(sbt -no-colors --error "print cortex/version" | tail -1) |
| 33 | + if ( echo $V | grep -qi snapshot) |
| 34 | + then |
| 35 | + exit 1 |
| 36 | + fi |
39 | 37 | . ~/.nvm/nvm.sh |
40 | 38 | [ -n "$PLUGIN_PGP_KEY" ] && gpg --batch --import - <<< $PLUGIN_PGP_KEY |
41 | 39 | sbt -Duser.home=$PWD docker:stage debian:packageBin rpm:packageBin universal:packageBin |
| 40 | + if ( echo $V | grep -qi rc ) |
| 41 | + then |
| 42 | + echo $( echo $V | sed -re 's/([0-9]+.[0-9]+.[0-9]+)-RC([0-9]+)-([0-9]+)/\1-RC\2,\1-RC\2-\3/' ) > .tags |
| 43 | + else |
| 44 | + echo $( echo $V | sed -re 's/([0-9]+).([0-9]+).([0-9]+)-([0-9]+)/\1,\1.\2,\1.\2.\3,\1.\2.\3-\4,latest/' ) > .tags |
| 45 | + fi |
| 46 | + echo $V > cortex-version.txt |
| 47 | + mv target/rpm/RPMS/noarch/cortex*.rpm target/ |
| 48 | + mv target/universal/cortex*.zip target/ |
42 | 49 | when: |
43 | 50 | event: [tag] |
44 | 51 |
|
45 | 52 | # Save external libraries in cache |
46 | | - - name: save cache |
| 53 | + - name: save-cache |
47 | 54 | image: drillster/drone-volume-cache |
48 | 55 | settings: |
49 | 56 | rebuild: true |
| 57 | + backend: "filesystem" |
50 | 58 | mount: |
51 | 59 | - .sbt |
52 | 60 | - .ivy2 |
53 | | - - www/node_modules |
| 61 | + - .cache |
| 62 | + - ui/node_modules |
| 63 | + - ui/bower_components |
54 | 64 | volumes: [{name: cache, path: /cache}] |
55 | 65 |
|
| 66 | + # Send packages using scp |
| 67 | + - name: send packages |
| 68 | + image: appleboy/drone-scp |
| 69 | + settings: |
| 70 | + host: {from_secret: package_host} |
| 71 | + username: {from_secret: package_user} |
| 72 | + key: {from_secret: package_key} |
| 73 | + target: {from_secret: incoming_path} |
| 74 | + source: |
| 75 | + - target/cortex*.deb |
| 76 | + - target/cortex*.rpm |
| 77 | + - target/cortex*.zip |
| 78 | + strip_components: 1 |
| 79 | + when: |
| 80 | + event: [tag] |
| 81 | + |
| 82 | + # Publish packages |
56 | 83 | - name: publish packages |
57 | | - image: thehiveproject/drone-bintray |
| 84 | + image: appleboy/drone-ssh |
58 | 85 | settings: |
59 | | - user: {from_secret: bintray_user} |
60 | | - key: {from_secret: bintray_key} |
61 | | - subject: thehive-project |
62 | | - package: cortex |
| 86 | + host: {from_secret: package_host} |
| 87 | + user: {from_secret: package_user} |
| 88 | + key: {from_secret: package_key} |
| 89 | + publish_script: {from_secret: publish_script} |
63 | 90 | 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 | | - if $(echo $PLUGIN_VERSION | grep -qi rc) |
82 | | - then |
83 | | - CHANNEL=beta |
84 | | - V=$(echo $PLUGIN_VERSION | sed -e 's/-\([rR][cC]\)/-0.1\1/') |
85 | | - DEB_FILE=target/cortex_$${V}_all.deb |
86 | | - RPM_FILE=target/rpm/RPMS/noarch/cortex-$${V}.noarch.rpm |
87 | | - else |
88 | | - DEB_FILE=target/cortex_$${PLUGIN_VERSION}_all.deb |
89 | | - RPM_FILE=target/rpm/RPMS/noarch/cortex-$${PLUGIN_VERSION}.noarch.rpm |
90 | | - fi |
91 | | - ZIP_FILE=target/universal/cortex-$${PLUGIN_VERSION}.zip |
92 | | -
|
93 | | - upload \ |
94 | | - --file $DEB_FILE \ |
95 | | - --repo debian-beta \ |
96 | | - --extra-param deb_distribution=any \ |
97 | | - --extra-param deb_component=main \ |
98 | | - --extra-param deb_architecture=all |
99 | | -
|
100 | | - [ $CHANNEL = stable ] && upload \ |
101 | | - --file $DEB_FILE \ |
102 | | - --repo debian-stable \ |
103 | | - --extra-param deb_distribution=any \ |
104 | | - --extra-param deb_component=main \ |
105 | | - --extra-param deb_architecture=all |
106 | | -
|
107 | | - upload \ |
108 | | - --file $RPM_FILE \ |
109 | | - --repo rpm-beta |
110 | | -
|
111 | | - [ $CHANNEL = stable ] && upload \ |
112 | | - --file $RPM_FILE \ |
113 | | - --repo rpm-stable |
114 | | -
|
115 | | - upload \ |
116 | | - --file $ZIP_FILE \ |
117 | | - --repo binary |
118 | | -
|
119 | | - LATEST_VERSION=latest |
120 | | - [ $CHANNEL = beta ] && LATEST_VERSION=latest-beta |
121 | | -
|
122 | | - removeVersion \ |
123 | | - --repo binary \ |
124 | | - --version $LATEST_VERSION |
125 | | -
|
126 | | - upload \ |
127 | | - --file $ZIP_FILE \ |
128 | | - --repo binary \ |
129 | | - --version $LATEST_VERSION \ |
130 | | - --dest-file cortex-$${LATEST_VERSION}.zip |
| 91 | + - PLUGIN_SCRIPT="bash $PLUGIN_PUBLISH_SCRIPT cortex $(cat cortex-version.txt)" /bin/drone-ssh |
131 | 92 | when: |
132 | 93 | event: [tag] |
133 | 94 |
|
134 | | - # Publish docker image |
| 95 | + # Publish docker image on Docker Hub |
135 | 96 | - name: docker |
136 | 97 | image: plugins/docker |
137 | 98 | settings: |
138 | 99 | context: target/docker/stage |
139 | 100 | dockerfile: target/docker/stage/Dockerfile |
140 | 101 | repo: thehiveproject/cortex |
141 | | - auto_tag: true |
142 | 102 | username: {from_secret: docker_username} |
143 | 103 | password: {from_secret: docker_password} |
144 | 104 | when: |
145 | 105 | event: [tag] |
146 | 106 |
|
147 | | - # Deploy binaries in integration environment |
148 | | - - name: copy binaries in integration environment |
149 | | - image: appleboy/drone-scp |
150 | | - settings: |
151 | | - host: {from_secret: deploy_beta_host} |
152 | | - username: {from_secret: deploy_username} |
153 | | - key: {from_secret: deploy_key} |
154 | | - target: ./cortex-builds/${DRONE_BUILD_NUMBER} |
155 | | - source: target/universal/stage |
156 | | - strip_components: 3 |
157 | | - when: |
158 | | - branch: [develop] |
159 | | - |
160 | | - - name: deploy binaries in integration environment |
161 | | - image: appleboy/drone-ssh |
162 | | - settings: |
163 | | - host: {from_secret: deploy_beta_host} |
164 | | - username: {from_secret: deploy_username} |
165 | | - key: {from_secret: deploy_key} |
166 | | - script: |
167 | | - - ./start cortex ${DRONE_BUILD_NUMBER} |
168 | | - when: |
169 | | - branch: [develop] |
170 | | - |
171 | | - # Deploy binaries in staging environment |
172 | | - - name: copy binaries in staging environment |
173 | | - image: appleboy/drone-scp |
| 107 | + # Publish docker image on Harbor |
| 108 | + - name: harbor |
| 109 | + image: plugins/docker |
174 | 110 | settings: |
175 | | - host: {from_secret: deploy_stable_host} |
176 | | - username: {from_secret: deploy_username} |
177 | | - key: {from_secret: deploy_key} |
178 | | - target: ./cortex-builds/${DRONE_BUILD_NUMBER} |
179 | | - source: target/universal/stage |
180 | | - strip_components: 3 |
| 111 | + context: target/docker/stage |
| 112 | + dockerfile: target/docker/stage/Dockerfile |
| 113 | + registry: {from_secret: harbor_registry} |
| 114 | + repo: {from_secret: harbor_repo} |
| 115 | + username: {from_secret: harbor_username} |
| 116 | + password: {from_secret: harbor_password} |
181 | 117 | when: |
182 | | - branch: [master] |
| 118 | + event: [tag] |
183 | 119 |
|
184 | | - - name: deploy binaries in staging environment |
185 | | - image: appleboy/drone-ssh |
| 120 | + - name: send message |
| 121 | + image: thehiveproject/drone_keybase |
186 | 122 | settings: |
187 | | - host: {from_secret: deploy_stable_host} |
188 | | - username: {from_secret: deploy_username} |
189 | | - key: {from_secret: deploy_key} |
190 | | - script: |
191 | | - - ./start cortex ${DRONE_BUILD_NUMBER} |
| 123 | + username: {from_secret: keybase_username} |
| 124 | + paperkey: {from_secret: keybase_paperkey} |
| 125 | + channel: {from_secret: keybase_channel} |
| 126 | + commands: |
| 127 | + - | |
| 128 | + keybase oneshot -u "$PLUGIN_USERNAME" --paperkey "$PLUGIN_PAPERKEY" |
| 129 | + URL="$DRONE_SYSTEM_PROTO://$DRONE_SYSTEM_HOST/$DRONE_REPO/$DRONE_BUILD_NUMBER" |
| 130 | + if [ $DRONE_BUILD_STATUS = "success" ] |
| 131 | + then |
| 132 | + keybase chat send "$PLUGIN_CHANNEL" ":white_check_mark: $DRONE_REPO: build succeeded $URL" |
| 133 | + else |
| 134 | + keybase chat send "$PLUGIN_CHANNEL" ":x: $DRONE_REPO: build failed $URL" |
| 135 | + fi |
192 | 136 | when: |
193 | | - branch: [master] |
| 137 | + status: |
| 138 | + - success |
| 139 | + - failure |
194 | 140 |
|
195 | 141 | volumes: |
196 | 142 | - name: cache |
|
0 commit comments