Skip to content

Commit 3d0f5f9

Browse files
committed
#156 Add configuration for drone
1 parent fda7cb6 commit 3d0f5f9

File tree

8 files changed

+234
-108
lines changed

8 files changed

+234
-108
lines changed

.drone.yml

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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

debian.sbt

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
import Common._
1+
import Common.{stableVersion, betaVersion, snapshotVersion}
22

3-
version in Debian := getVersion(version.value) + '-' + getRelease(version.value)
3+
linuxPackageMappings in Debian += packageMapping(file("LICENSE") -> "/usr/share/doc/cortex/copyright").withPerms("644")
4+
version in Debian := {
5+
version.value match {
6+
case stableVersion(_, _) => version.value
7+
case betaVersion(v1, v2) => v1 + "-0.1RC" + v2
8+
case snapshotVersion(_, _) => version.value + "-SNAPSHOT"
9+
case _ => sys.error("Invalid version: " + version.value)
10+
}
11+
}
12+
debianPackageRecommends := Seq("elasticsearch")
413
debianPackageDependencies += "java8-runtime | java8-runtime-headless"
514
maintainerScripts in Debian := maintainerScriptsFromDirectory(
615
baseDirectory.value / "package" / "debian",

docker.sbt

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
import Common._
2-
import com.typesafe.sbt.packager.docker.{ Cmd, ExecCmd }
1+
import Common.{betaVersion, snapshotVersion, stableVersion}
2+
import com.typesafe.sbt.packager.docker.{Cmd, ExecCmd}
33

4-
version in Docker := getVersion(version.value) + '-' + getRelease(version.value)
4+
version in Docker := {
5+
version.value match {
6+
case stableVersion(_, _) => version.value
7+
case betaVersion(v1, v2) => v1 + "-0.1RC" + v2
8+
case snapshotVersion(_, _) => version.value + "-SNAPSHOT"
9+
case _ => sys.error("Invalid version: " + version.value)
10+
}
11+
}
512
defaultLinuxInstallLocation in Docker := "/opt/cortex"
613
dockerRepository := Some("thehiveproject")
7-
dockerUpdateLatest := true
14+
dockerUpdateLatest := !version.value.toUpperCase.contains("RC")
815
dockerEntrypoint := Seq("/opt/cortex/entrypoint")
9-
dockerExposedPorts := Seq(9001)
16+
dockerExposedPorts := Seq(9000)
1017
mappings in Docker ++= Seq(
1118
file("package/docker/entrypoint") -> "/opt/cortex/entrypoint",
12-
file("conf/logback.xml") -> "/etc/cortex/logback.xml",
19+
file("package/logback.xml") -> "/etc/cortex/logback.xml",
1320
file("package/empty") -> "/var/log/cortex/application.log")
1421
mappings in Docker ~= (_.filterNot {
1522
case (_, filepath) => filepath == "/opt/cortex/conf/application.conf"
1623
})
17-
1824
dockerCommands ~= { dc =>
1925
val (dockerInitCmds, dockerTailCmds) = dc
2026
.collect {

project/Common.scala

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
import sbt._
1+
import scala.util.matching.Regex
2+
23
import sbt.Keys._
4+
import sbt._
35

46
object Common {
57

68
val projectSettings = Seq(
79
organizationName := "TheHive-Project",
810
organization := "org.thehive-project",
9-
licenses += "AGPL-V3" -> url("https://www.gnu.org/licenses/agpl-3.0.html"),
11+
licenses += "AGPL-V3" url("https://www.gnu.org/licenses/agpl-3.0.html"),
1012
organizationHomepage := Some(url("http://thehive-project.org/")),
1113
resolvers += Resolver.bintrayRepo("thehive-project", "maven"),
14+
resolvers += "elasticsearch-releases" at "https://artifacts.elastic.co/maven",
1215
scalaVersion := Dependencies.scalaVersion,
1316
scalacOptions ++= Seq(
1417
"-deprecation", // Emit warning and location for usages of deprecated APIs.
@@ -22,7 +25,7 @@ object Common {
2225
"-Ywarn-nullary-override", // Warn when non-nullary overrides nullary, e.g. def foo() over def foo.
2326
"-Ywarn-numeric-widen" // Warn when numerics are widened.
2427
),
25-
scalacOptions in Test ~= { options =>
28+
scalacOptions in Test ~= { options
2629
options filterNot (_ == "-Ywarn-dead-code") // Allow dead code in tests (to support using mockito).
2730
},
2831
parallelExecution in Test := false,
@@ -34,13 +37,15 @@ object Common {
3437
excludeDependencies += "org.apache.logging.log4j" % "log4j-core"
3538
)
3639

37-
def getVersion(version: String): String = version.takeWhile(_ != '-')
38-
39-
def getRelease(version: String): String = {
40-
version.dropWhile(_ != '-').dropWhile(_ == '-') match {
41-
case "" => "1"
42-
case r if r.contains('-') => sys.error("Version can't have more than one dash")
43-
case r => s"0.1$r"
40+
val stableVersion: Regex = "(\\d+\\.\\d+\\.\\d+)-(\\d+)".r
41+
val betaVersion: Regex = "(\\d+\\.\\d+\\.\\d+)-[Rr][Cc](\\d+)".r
42+
object snapshotVersion {
43+
def unapplySeq(version: String): Option[List[String]] = {
44+
if (version.endsWith("-SNAPSHOT")) {
45+
val v = version.dropRight(9)
46+
stableVersion.unapplySeq(v) orElse betaVersion.unapplySeq(v)
47+
}
48+
else None
4449
}
4550
}
4651
}

rpm.sbt

+30-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,46 @@
1-
import Common._
1+
import Common.{stableVersion, betaVersion, snapshotVersion}
22

3-
version in Rpm := getVersion(version.value)
4-
rpmRelease := getRelease(version.value)
5-
rpmVendor := "TheHive Project"
3+
version in Rpm := {
4+
version.value match {
5+
case stableVersion(v1, v2) => v1
6+
case betaVersion(v1, v2) => v1
7+
case snapshotVersion(v1, v2) => v1
8+
case _ => sys.error("Invalid version: " + version.value)
9+
}
10+
}
11+
rpmRelease := {
12+
version.value match {
13+
case stableVersion(_, v2) => v2
14+
case betaVersion(v1, v2) => "0.1RC" + v2
15+
case snapshotVersion(v1, v2) => v2 + "-SNAPSHOT"
16+
case _ => sys.error("Invalid version: " + version.value)
17+
}
18+
}
19+
rpmVendor := organizationName.value
620
rpmUrl := organizationHomepage.value.map(_.toString)
721
rpmLicense := Some("AGPL")
822
rpmRequirements += "java-1.8.0-openjdk-headless"
23+
924
maintainerScripts in Rpm := maintainerScriptsFromDirectory(
1025
baseDirectory.value / "package" / "rpm",
1126
Seq(RpmConstants.Pre, RpmConstants.Preun, RpmConstants.Postun)
1227
)
13-
linuxPackageMappings in Rpm := configWithNoReplace((linuxPackageMappings in Rpm).value)
28+
1429
linuxPackageSymlinks in Rpm := Nil
1530
rpmPrefix := Some(defaultLinuxInstallLocation.value)
1631
linuxEtcDefaultTemplate in Rpm := (baseDirectory.value / "package" / "etc_default_cortex").asURL
32+
33+
linuxPackageMappings in Rpm := configWithNoReplace((linuxPackageMappings in Rpm).value)
34+
1735
packageBin in Rpm := {
1836
import scala.sys.process._
19-
2037
val rpmFile = (packageBin in Rpm).value
21-
s"rpm --addsign $rpmFile".!!
38+
Process("rpm" ::
39+
"--define" :: "_gpg_name TheHive Project" ::
40+
"--define" :: "_signature gpg" ::
41+
"--define" :: "__gpg_check_password_cmd /bin/true" ::
42+
"--define" :: "__gpg_sign_cmd %{__gpg} gpg --batch --no-verbose --no-armor --use-agent --no-secmem-warning -u \"%{_gpg_name}\" -sbo %{__signature_filename} %{__plaintext_filename}" ::
43+
"--addsign" :: rpmFile.toString ::
44+
Nil).!!
2245
rpmFile
2346
}

0 commit comments

Comments
 (0)