command.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. package command
  2. import (
  3. "errors"
  4. "github.com/codegangsta/cli"
  5. composeApp "github.com/docker/libcompose/cli/app"
  6. "github.com/rancher/os/cmd/control/service/app"
  7. )
  8. func verifyOneOrMoreServices(c *cli.Context) error {
  9. if len(c.Args()) == 0 {
  10. return errors.New("Must specify one or more services")
  11. }
  12. return nil
  13. }
  14. func CreateCommand(factory composeApp.ProjectFactory) cli.Command {
  15. return cli.Command{
  16. Name: "create",
  17. Usage: "Create services",
  18. Before: verifyOneOrMoreServices,
  19. Action: composeApp.WithProject(factory, app.ProjectCreate),
  20. Flags: []cli.Flag{
  21. cli.BoolFlag{
  22. Name: "no-recreate",
  23. Usage: "If containers already exist, don't recreate them. Incompatible with --force-recreate.",
  24. },
  25. cli.BoolFlag{
  26. Name: "force-recreate",
  27. Usage: "Recreate containers even if their configuration and image haven't changed. Incompatible with --no-recreate.",
  28. },
  29. cli.BoolFlag{
  30. Name: "no-build",
  31. Usage: "Don't build an image, even if it's missing.",
  32. },
  33. },
  34. }
  35. }
  36. func BuildCommand(factory composeApp.ProjectFactory) cli.Command {
  37. return cli.Command{
  38. Name: "build",
  39. Usage: "Build or rebuild services",
  40. Before: verifyOneOrMoreServices,
  41. Action: composeApp.WithProject(factory, app.ProjectBuild),
  42. Flags: []cli.Flag{
  43. cli.BoolFlag{
  44. Name: "no-cache",
  45. Usage: "Do not use cache when building the image",
  46. },
  47. cli.BoolFlag{
  48. Name: "force-rm",
  49. Usage: "Always remove intermediate containers",
  50. },
  51. cli.BoolFlag{
  52. Name: "pull",
  53. Usage: "Always attempt to pull a newer version of the image",
  54. },
  55. },
  56. }
  57. }
  58. func PsCommand(factory composeApp.ProjectFactory) cli.Command {
  59. return cli.Command{
  60. Name: "ps",
  61. Usage: "List containers",
  62. Action: composeApp.WithProject(factory, app.ProjectPs),
  63. Flags: []cli.Flag{
  64. cli.BoolFlag{
  65. Name: "q",
  66. Usage: "Only display IDs",
  67. },
  68. },
  69. }
  70. }
  71. func UpCommand(factory composeApp.ProjectFactory) cli.Command {
  72. return cli.Command{
  73. Name: "up",
  74. Usage: "Create and start containers",
  75. Before: verifyOneOrMoreServices,
  76. Action: composeApp.WithProject(factory, app.ProjectUp),
  77. Flags: []cli.Flag{
  78. cli.BoolFlag{
  79. Name: "foreground",
  80. Usage: "Run in foreground and log",
  81. },
  82. cli.BoolFlag{
  83. Name: "no-build",
  84. Usage: "Don't build an image, even if it's missing.",
  85. },
  86. cli.BoolFlag{
  87. Name: "no-recreate",
  88. Usage: "If containers already exist, don't recreate them. Incompatible with --force-recreate.",
  89. },
  90. cli.BoolFlag{
  91. Name: "force-recreate",
  92. Usage: "Recreate containers even if their configuration and image haven't changed. Incompatible with --no-recreate.",
  93. },
  94. },
  95. }
  96. }
  97. func StartCommand(factory composeApp.ProjectFactory) cli.Command {
  98. return cli.Command{
  99. Name: "start",
  100. Usage: "Start services",
  101. Before: verifyOneOrMoreServices,
  102. Action: composeApp.WithProject(factory, app.ProjectStart),
  103. Flags: []cli.Flag{
  104. cli.BoolTFlag{
  105. Name: "foreground",
  106. Usage: "Run in foreground and log",
  107. },
  108. },
  109. }
  110. }
  111. func PullCommand(factory composeApp.ProjectFactory) cli.Command {
  112. return cli.Command{
  113. Name: "pull",
  114. Usage: "Pulls service images",
  115. Before: verifyOneOrMoreServices,
  116. Action: composeApp.WithProject(factory, app.ProjectPull),
  117. Flags: []cli.Flag{
  118. cli.BoolFlag{
  119. Name: "ignore-pull-failures",
  120. Usage: "Pull what it can and ignores images with pull failures.",
  121. },
  122. },
  123. }
  124. }
  125. func LogsCommand(factory composeApp.ProjectFactory) cli.Command {
  126. return cli.Command{
  127. Name: "logs",
  128. Usage: "View output from containers",
  129. Before: verifyOneOrMoreServices,
  130. Action: composeApp.WithProject(factory, app.ProjectLog),
  131. Flags: []cli.Flag{
  132. cli.IntFlag{
  133. Name: "lines",
  134. Usage: "number of lines to tail",
  135. Value: 100,
  136. },
  137. cli.BoolFlag{
  138. Name: "follow, f",
  139. Usage: "Follow log output.",
  140. },
  141. },
  142. }
  143. }
  144. func RestartCommand(factory composeApp.ProjectFactory) cli.Command {
  145. return cli.Command{
  146. Name: "restart",
  147. Usage: "Restart services",
  148. Before: verifyOneOrMoreServices,
  149. Action: composeApp.WithProject(factory, app.ProjectRestart),
  150. Flags: []cli.Flag{
  151. cli.IntFlag{
  152. Name: "timeout,t",
  153. Usage: "Specify a shutdown timeout in seconds.",
  154. Value: 10,
  155. },
  156. },
  157. }
  158. }
  159. func StopCommand(factory composeApp.ProjectFactory) cli.Command {
  160. return cli.Command{
  161. Name: "stop",
  162. Usage: "Stop services",
  163. Before: verifyOneOrMoreServices,
  164. Action: composeApp.WithProject(factory, app.ProjectStop),
  165. Flags: []cli.Flag{
  166. cli.IntFlag{
  167. Name: "timeout,t",
  168. Usage: "Specify a shutdown timeout in seconds.",
  169. Value: 10,
  170. },
  171. },
  172. }
  173. }
  174. func DownCommand(factory composeApp.ProjectFactory) cli.Command {
  175. return cli.Command{
  176. Name: "down",
  177. Usage: "Stop and remove containers, networks, images, and volumes",
  178. Before: verifyOneOrMoreServices,
  179. Action: composeApp.WithProject(factory, app.ProjectDown),
  180. Flags: []cli.Flag{
  181. cli.BoolFlag{
  182. Name: "volumes,v",
  183. Usage: "Remove data volumes",
  184. },
  185. cli.StringFlag{
  186. Name: "rmi",
  187. Usage: "Remove images, type may be one of: 'all' to remove all images, or 'local' to remove only images that don't have an custom name set by the `image` field",
  188. },
  189. cli.BoolFlag{
  190. Name: "remove-orphans",
  191. Usage: "Remove containers for services not defined in the Compose file",
  192. },
  193. },
  194. }
  195. }
  196. func RmCommand(factory composeApp.ProjectFactory) cli.Command {
  197. return cli.Command{
  198. Name: "rm",
  199. Usage: "Delete services",
  200. Before: verifyOneOrMoreServices,
  201. Action: composeApp.WithProject(factory, app.ProjectDelete),
  202. Flags: []cli.Flag{
  203. cli.BoolFlag{
  204. Name: "force,f",
  205. Usage: "Allow deletion of all services",
  206. },
  207. cli.BoolFlag{
  208. Name: "v",
  209. Usage: "Remove volumes associated with containers",
  210. },
  211. },
  212. }
  213. }
  214. func KillCommand(factory composeApp.ProjectFactory) cli.Command {
  215. return cli.Command{
  216. Name: "kill",
  217. Usage: "Kill containers",
  218. Before: verifyOneOrMoreServices,
  219. Action: composeApp.WithProject(factory, app.ProjectKill),
  220. Flags: []cli.Flag{
  221. cli.StringFlag{
  222. Name: "signal,s",
  223. Usage: "SIGNAL to send to the container",
  224. Value: "SIGKILL",
  225. },
  226. },
  227. }
  228. }