src/Pure/Admin/build_docker.scala
changeset 64899 749d3a86c6a3
parent 64897 c3320dc731c7
child 64903 ba72a13eb78c
equal deleted inserted replaced
64898:49aa13b1b592 64899:749d3a86c6a3
     9 
     9 
    10 object Build_Docker
    10 object Build_Docker
    11 {
    11 {
    12   private lazy val default_logic = Isabelle_System.getenv("ISABELLE_LOGIC")
    12   private lazy val default_logic = Isabelle_System.getenv("ISABELLE_LOGIC")
    13 
    13 
    14   private val standard_packages =
    14   val packages: List[String] =
    15     List("less", "lib32stdc++6", "libgomp1", "libwww-perl", "rlwrap", "unzip")
    15     List("less", "lib32stdc++6", "libgomp1", "libwww-perl", "rlwrap", "unzip")
    16 
    16 
    17   private val package_collections =
    17   val package_collections: Map[String, List[String]] =
    18     Map("X11" -> List("libx11-6", "libxext6", "libxrender1", "libxtst6", "libxi6"),
    18     Map("X11" -> List("libx11-6", "libxext6", "libxrender1", "libxtst6", "libxi6"),
    19       "latex" -> List("texlive-fonts-extra", "texlive-latex-extra", "texlive-math-extra"))
    19       "latex" -> List("texlive-fonts-extra", "texlive-latex-extra", "texlive-math-extra"))
    20 
    20 
    21   def build_docker(progress: Progress,
    21   def build_docker(progress: Progress,
    22     app_archive: Path,
    22     app_archive: Path,
    23     logic: String = default_logic,
    23     logic: String = default_logic,
    24     output: Option[Path] = None,
    24     output: Option[Path] = None,
    25     packages: List[String] = Nil,
    25     more_packages: List[String] = Nil,
    26     tag: String = "",
    26     tag: String = "",
    27     verbose: Boolean = false)
    27     verbose: Boolean = false)
    28   {
    28   {
    29     val distname =
    29     val distname =
    30     {
    30     {
    41 FROM ubuntu
    41 FROM ubuntu
    42 SHELL ["/bin/bash", "-c"]
    42 SHELL ["/bin/bash", "-c"]
    43 
    43 
    44 # packages
    44 # packages
    45 RUN apt-get -y update && \
    45 RUN apt-get -y update && \
    46   apt-get install -y  """ + (standard_packages ::: packages).map(Bash.string(_)).mkString(" ") + """ && \
    46   apt-get install -y  """ + (packages ::: more_packages).map(Bash.string(_)).mkString(" ") + """ && \
    47   apt-get clean
    47   apt-get clean
    48 
    48 
    49 # user
    49 # user
    50 RUN useradd -m isabelle && (echo isabelle:isabelle | chpasswd)
    50 RUN useradd -m isabelle && (echo isabelle:isabelle | chpasswd)
    51 USER isabelle
    51 USER isabelle
    83   val isabelle_tool =
    83   val isabelle_tool =
    84     Isabelle_Tool("build_docker", "build Isabelle docker image", args =>
    84     Isabelle_Tool("build_docker", "build Isabelle docker image", args =>
    85     {
    85     {
    86       var logic = default_logic
    86       var logic = default_logic
    87       var output: Option[Path] = None
    87       var output: Option[Path] = None
    88       var packages: List[String] = Nil
    88       var more_packages: List[String] = Nil
    89       var verbose = false
    89       var verbose = false
    90       var tag = ""
    90       var tag = ""
    91 
    91 
    92       val getopts =
    92       val getopts =
    93         Getopts("""
    93         Getopts("""
   109 
   109 
   110     isabelle build_docker -t test/isabelle:Isabelle2016-1 Isabelle2016-1_app.tar.gz
   110     isabelle build_docker -t test/isabelle:Isabelle2016-1 Isabelle2016-1_app.tar.gz
   111 """,
   111 """,
   112           "P:" -> (arg =>
   112           "P:" -> (arg =>
   113             package_collections.get(arg) match {
   113             package_collections.get(arg) match {
   114               case Some(ps) => packages :::= ps
   114               case Some(ps) => more_packages :::= ps
   115               case None => error("Unknown package collection " + quote(arg))
   115               case None => error("Unknown package collection " + quote(arg))
   116             }),
   116             }),
   117           "l:" -> (arg => logic = arg),
   117           "l:" -> (arg => logic = arg),
   118           "o:" -> (arg => output = Some(Path.explode(arg))),
   118           "o:" -> (arg => output = Some(Path.explode(arg))),
   119           "p:" -> (arg => packages ::= arg),
   119           "p:" -> (arg => more_packages ::= arg),
   120           "t:" -> (arg => tag = arg),
   120           "t:" -> (arg => tag = arg),
   121           "v" -> (_ => verbose = true))
   121           "v" -> (_ => verbose = true))
   122 
   122 
   123       val more_args = getopts(args)
   123       val more_args = getopts(args)
   124       val app_archive =
   124       val app_archive =
   126           case List(arg) => Path.explode(arg)
   126           case List(arg) => Path.explode(arg)
   127           case _ => getopts.usage()
   127           case _ => getopts.usage()
   128         }
   128         }
   129 
   129 
   130       build_docker(new Console_Progress(), app_archive, logic = logic, output = output,
   130       build_docker(new Console_Progress(), app_archive, logic = logic, output = output,
   131         packages = packages, tag = tag, verbose = verbose)
   131         more_packages = more_packages, tag = tag, verbose = verbose)
   132     }, admin = true)
   132     }, admin = true)
   133 }
   133 }