Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Gradleからsbtへの移行

 Gradleからsbtへの移行

Naohiro Hasegawa

December 27, 2016
Tweet

Other Decks in Programming

Transcript

  1. 目次 step1 - init step2 - fatjar step3 - tomcat

    step4 - multi-project step5 - docker step6 - custom plugin
  2. build.sbt name := "chiken" version := "1.0" scalaVersion := "2.11.8"

    libraryDependencies += "javax.servlet" % "javax.servlet-api" % "3.0.1" % "provided" enablePlugins(TomcatPlugin)
  3. ChikenServlet.scala package chiken import javax.servlet.http.{HttpServlet, HttpServletRequest, HttpServletResponse class ChikenServlet extends

    HttpServlet { override def doGet(request: HttpServletRequest, response: HttpServletResponse val s = response.getOutputStream s.print("CHIKEN DESU") s.flush() } }
  4. web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml id="serv"

    version="3.0"> <servlet> <servlet-name>ChikenServlet</servlet-name> <servlet-class>chiken.ChikenServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>ChikenServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app>
  5. 実行 $ sbt ~tomcat:start 1. Waiting for source changes... (press

    enter to interrupt) Adding Context for /Users/a14344/dev/sbt-chiken/target/webapp 12 15, 2016 9:52:45 午後 org.apache.coyote.AbstractProtocol init 情報: Initializing ProtocolHandler ["http-nio-8080"] 12 15, 2016 9:52:46 午後 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector 情報: Using a shared selector for servlet write/read 12 15, 2016 9:52:46 午後 org.apache.catalina.core.StandardService startInternal 情報: Starting service Tomcat 12 15, 2016 9:52:46 午後 org.apache.catalina.core.StandardEngine startInternal 情報: Starting Servlet Engine: Apache Tomcat/7.0.34 12 15, 2016 9:52:46 午後 org.apache.catalina.startup.ContextConfig getDefaultWebXmlFra 情報: No global web.xml found 12 15, 2016 9:52:48 午後 org.apache.coyote.AbstractProtocol start 情報: Starting ProtocolHandler ["http-nio-8080"]
  6. ディレクトリ構成 app/ ├ batch/ │ └ src/main/scala/batch/ChikenBatch.scala ├ lib/ │

    └ src/main/scala/lib/Chilen.scala ├ project/plugins.sbt └ build.sbt
  7. ChikenBatch.scala package batch import lib._ object ChikenBatch extends App {

    println(Chiken.get) } Chilen.scala package lib object Chiken { def get = " 知見" }
  8. build.sbt lazy val root = (project in file(".")) .aggregate(batch, lib)

    lazy val batch = (project in file("batch")) .dependsOn(lib) lazy val lib = (project in file("lib"))
  9. build.sbt lazy val root = (project in file(".")) .aggregate(batch, lib)

    lazy val batch = (project in file("batch")) .dependsOn(lib) .enablePlugins(AshScriptPlugin, DockerPlugin) .settings( dockerRepository := Some("smalgo-docker.cyberagent.io"), dockerBaseImage := "java:8-jdk-alpine" ) lazy val lib = (project in file("lib"))
  10. 実行 $ sbt batch/docker:publishLocal # ロー カルにdocker image を作成 $

    docker run smalgo-docker.cyberagent.io/chiken:1.0 知見 $ sbt batch/docker:publish # docker リポジトリにpush
  11. BatchPlugin.scala import com.typesafe.sbt.packager.archetypes._ import com.typesafe.sbt.packager.docker._ import com.typesafe.sbt.packager.docker.DockerPlugin.autoImport._ import sbt._ object

    BatchPlugin extends AutoPlugin { // build.sbt のenablePlugins と同じ override def requires = AshScriptPlugin && DockerPlugin // build.sbt のsettings と同じ override val projectSettings = Seq( dockerRepository := Some("smalgo-docker.cyberagent.io"), dockerBaseImage := "java:8-jdk-alpine" ) }
  12. build.sbt lazy val root = (project in file(".")) .aggregate(batch, lib)

    lazy val batch = (project in file("batch")) .dependsOn(lib) .enablePlugins(BatchPlugin) // NEW! lazy val lib = (project in file("lib"))
  13. ディレクトリ構成 app/ ├ batch/ │ └ src/main/scala/batch/ChikenBatch.scala ├ lib/ │

    └ src/main/scala/lib/Chilen.scala ├ project/ │ │ BatchPlugin.scala │ └ plugins.sbt └ build.sbt
  14. 開発環境移行 docker compose CircleCI 移行 CD 高速化 chatops 移行 リリー

    ス bid パラメー ター 変更 LB 登録/ 登録解除