diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..08a53cd --- /dev/null +++ b/.travis.yml @@ -0,0 +1,34 @@ +language: scala +services: +- docker +scala: +- 2.11.12 +jdk: +- oraclejdk8 +script: +- sbt test +before_deploy: +- pip install --user release-manager==0.3.0 +deploy: + - provider: script + skip_cleanup: true + script: release-manager --config ./.travis/release.yml --check-version --make-version --make-artifact --upload-artifact + on: + tags: true + - provider: script + skip_cleanup: true + script: ./.travis/deploy_docker.sh $TRAVIS_TAG + on: + tags: true + - provider: script + skip_cleanup: true + script: ./.travis/deploy_template.sh $TRAVIS_TAG + on: + tags: true +env: +global: + - BINTRAY_SNOWPLOW_GENERIC_USER + - BINTRAY_SNOWPLOW_GENERIC_API_KEY + - BINTRAY_SNOWPLOW_DOCKER_USER + - BINTRAY_SNOWPLOW_DOCKER_API_KEY + - GCP_CREDENTIALS diff --git a/.travis/deploy_docker.sh b/.travis/deploy_docker.sh new file mode 100755 index 0000000..a5d1a3f --- /dev/null +++ b/.travis/deploy_docker.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +tag=$1 + +file="${HOME}/.dockercfg" +docker_repo="snowplow-docker-registry.bintray.io" +curl -X GET \ + -u${BINTRAY_SNOWPLOW_DOCKER_USER}:${BINTRAY_SNOWPLOW_DOCKER_API_KEY} \ + https://${docker_repo}/v2/auth > $file + +cd ${TRAVIS_BUILD_DIR} + +project_version=$(sbt version -dsbt.log.noformat=true | perl -ne 'print "$1\n" if /info.*(\d+\.\d+\.\d+[^\r\n]*)/' | tail -n 1 | tr -d '\n') +if [[ "${tag}" = *"${project_version}" ]]; then + sbt docker:publishlocal + docker push "${docker_repo}/snowplow/snowplow-cloud-storage-loader:${tag}" +else + echo "Tag version '${tag}' doesn't match version in scala project ('${project_version}'). aborting!" + exit 1 +fi diff --git a/.travis/deploy_template.sh b/.travis/deploy_template.sh new file mode 100755 index 0000000..f2eba0c --- /dev/null +++ b/.travis/deploy_template.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +tag=$1 + +GOOGLE_APPLICATION_CREDENTIALS="${HOME}/credentials.json" +echo ${GCP_CREDENTIALS} > ${GOOGLE_APPLICATION_CREDENTIALS} +export GOOGLE_APPLICATION_CREDENTIALS + +cd ${TRAVIS_BUILD_DIR} + +project_version=$(sbt version -dsbt.log.noformat=true | perl -ne 'print "$1\n" if /info.*(\d+\.\d+\.\d+[^\r\n]*)/' | tail -n 1 | tr -d '\n') +if [[ "${tag}" = *"${project_version}" ]]; then + sbt "runMain com.snowplowanalytics.CloudStorageLoader --project=engineering-sandbox \ + --templateLocation=gs://snowplow-hosted-assets/4-storage/cloud-storage-loader/${tag}/CloudStorageLoaderTemplate-${tag} \ + --stagingLocation=gs://snowplow-hosted-assets/4-storage/cloud-storage-loader/${tag}/staging \ + --runner=DataflowRunner \ + --tempLocation=gs://snowplow-hosted-assets/tmp" +else + echo "Tag version '${tag}' doesn't match version in scala project ('${project_version}'). aborting!" + exit 1 +fi diff --git a/.travis/release.yml b/.travis/release.yml new file mode 100644 index 0000000..49d51ce --- /dev/null +++ b/.travis/release.yml @@ -0,0 +1,32 @@ +--- +# --- Variables --- # + +local : + root_dir : <%= ENV['TRAVIS_BUILD_DIR'] %> + +# --- Release Manager Config --- # + +# Required: deployment targets +targets : + - type : "bintray" + user : <%= ENV['BINTRAY_SNOWPLOW_GENERIC_USER'] %> + password : <%= ENV['BINTRAY_SNOWPLOW_GENERIC_API_KEY'] %> + +# Required: packages to be deployed +packages : + - repo : "snowplow-generic" + name : "snowplow-cloud-storage-loader" + user_org : "snowplow" + publish : true + override : false + continue_on_conflict : false + version : <%= FUNC['sbt_version(.)'] %> + build_version : <%= ENV['TRAVIS_BUILD_RELEASE_TAG'] %> + build_commands : + - sbt universal:packageBin + artifacts : + - type : "asis" + prefix : "snowplow_cloud_storage_loader_" + suffix : ".zip" + binary_paths : + - "target/universal/cloud-storage-loader-{{ packages.0.build_version }}.zip" diff --git a/build.sbt b/build.sbt index 2a29608..83b618c 100644 --- a/build.sbt +++ b/build.sbt @@ -26,7 +26,6 @@ lazy val compilerOptions = Seq( lazy val commonSettings = Defaults.coreDefaultSettings ++ Seq( organization := "com.snowplowanalytics", - // Semantic versioning http://semver.org/ version := "0.1.0-SNAPSHOT", scalaVersion := "2.12.7", scalacOptions ++= compilerOptions, @@ -40,12 +39,19 @@ lazy val macroSettings = Seq( addCompilerPlugin(paradiseDependency) ) +import com.typesafe.sbt.packager.docker._ +dockerRepository := Some("snowplow-docker-registry.bintray.io") +dockerUsername := Some("snowplow") +dockerBaseImage := "snowplow-docker-registry.bintray.io/snowplow/base-debian:0.1.0" +maintainer in Docker := "Snowplow Analytics Ltd. " +daemonUser in Docker := "snowplow" + lazy val root: Project = project .in(file(".")) .settings(commonSettings) .settings(macroSettings) .settings( - name := "snowplow-cloud-storage-loader", + name := "cloud-storage-loader", description := "Snowplow Google Cloud Storage Loader", publish / skip := true, libraryDependencies ++= Seq( @@ -57,7 +63,7 @@ lazy val root: Project = project "org.mockito" % "mockito-core" % mockitoVersion % Test ) ) - .enablePlugins(PackPlugin) + .enablePlugins(JavaAppPackaging) lazy val repl: Project = project .in(file(".repl")) diff --git a/project/plugins.sbt b/project/plugins.sbt index e5d71fd..ef71e26 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,2 +1,2 @@ addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0") -addSbtPlugin("org.xerial.sbt" % "sbt-pack" % "0.11") +addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.12")