Skip to content

Commit

Permalink
Add CI/CD (closes #8)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenFradet committed Nov 2, 2018
1 parent 8ff4b40 commit 2230b86
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 4 deletions.
34 changes: 34 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions .travis/deploy_docker.sh
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions .travis/deploy_template.sh
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions .travis/release.yml
Original file line number Diff line number Diff line change
@@ -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"
12 changes: 9 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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. <[email protected]>"
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(
Expand All @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 2230b86

Please sign in to comment.