You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.1 KiB

7 years ago
Unify `copies` and `artifacts` configuration Refactored `copies` configuration to allow for greater control over when and which both local build context files and variant artifacts are copied into the target image. The new configuration introduces a "local" keyword to signify when a `copies` entry should apply to the files from the local build context as opposed to files from another variant's image during a multi-stage build. variants: build: copies: - from: local source: ./src destination: . Note that with this change, the user must now explicitly define whether _any_ files should be copied in from the local build context. None will be copied in by default. To help keep configurations succinct, especially considering this new requirement, and to approximate the old `copies: variant`, a shorthand format and sane defaults for `source` and `destination` (depending whether `from` is "local" or a variant name) were implemented. variants: build: copies: [local] development: copies: - from: build - from: local source: ./config.dev.yaml destination: ./config.yaml The shorthand: copies: [ref, ...] # is equivalent to copies: [{ from: ref }, ...] And the following defaults are used when no `source` and `destination` are specified. copies: - from: local # defaults to - from: local source: . destination: . copies: - from: variant # defaults to two entries - from: variant source: /srv/app # the lives.in dir destination: /srv/app - from: variant source: /opt/local # the shared lib dir destination: /opt/local Bug: T211625 Change-Id: I4c4217905afc0762b6bd66ed594d43cc0486e3e2
5 years ago
Unify `copies` and `artifacts` configuration Refactored `copies` configuration to allow for greater control over when and which both local build context files and variant artifacts are copied into the target image. The new configuration introduces a "local" keyword to signify when a `copies` entry should apply to the files from the local build context as opposed to files from another variant's image during a multi-stage build. variants: build: copies: - from: local source: ./src destination: . Note that with this change, the user must now explicitly define whether _any_ files should be copied in from the local build context. None will be copied in by default. To help keep configurations succinct, especially considering this new requirement, and to approximate the old `copies: variant`, a shorthand format and sane defaults for `source` and `destination` (depending whether `from` is "local" or a variant name) were implemented. variants: build: copies: [local] development: copies: - from: build - from: local source: ./config.dev.yaml destination: ./config.yaml The shorthand: copies: [ref, ...] # is equivalent to copies: [{ from: ref }, ...] And the following defaults are used when no `source` and `destination` are specified. copies: - from: local # defaults to - from: local source: . destination: . copies: - from: variant # defaults to two entries - from: variant source: /srv/app # the lives.in dir destination: /srv/app - from: variant source: /opt/local # the shared lib dir destination: /opt/local Bug: T211625 Change-Id: I4c4217905afc0762b6bd66ed594d43cc0486e3e2
5 years ago
7 years ago
7 years ago
Unify `copies` and `artifacts` configuration Refactored `copies` configuration to allow for greater control over when and which both local build context files and variant artifacts are copied into the target image. The new configuration introduces a "local" keyword to signify when a `copies` entry should apply to the files from the local build context as opposed to files from another variant's image during a multi-stage build. variants: build: copies: - from: local source: ./src destination: . Note that with this change, the user must now explicitly define whether _any_ files should be copied in from the local build context. None will be copied in by default. To help keep configurations succinct, especially considering this new requirement, and to approximate the old `copies: variant`, a shorthand format and sane defaults for `source` and `destination` (depending whether `from` is "local" or a variant name) were implemented. variants: build: copies: [local] development: copies: - from: build - from: local source: ./config.dev.yaml destination: ./config.yaml The shorthand: copies: [ref, ...] # is equivalent to copies: [{ from: ref }, ...] And the following defaults are used when no `source` and `destination` are specified. copies: - from: local # defaults to - from: local source: . destination: . copies: - from: variant # defaults to two entries - from: variant source: /srv/app # the lives.in dir destination: /srv/app - from: variant source: /opt/local # the shared lib dir destination: /opt/local Bug: T211625 Change-Id: I4c4217905afc0762b6bd66ed594d43cc0486e3e2
5 years ago
7 years ago
Unify `copies` and `artifacts` configuration Refactored `copies` configuration to allow for greater control over when and which both local build context files and variant artifacts are copied into the target image. The new configuration introduces a "local" keyword to signify when a `copies` entry should apply to the files from the local build context as opposed to files from another variant's image during a multi-stage build. variants: build: copies: - from: local source: ./src destination: . Note that with this change, the user must now explicitly define whether _any_ files should be copied in from the local build context. None will be copied in by default. To help keep configurations succinct, especially considering this new requirement, and to approximate the old `copies: variant`, a shorthand format and sane defaults for `source` and `destination` (depending whether `from` is "local" or a variant name) were implemented. variants: build: copies: [local] development: copies: - from: build - from: local source: ./config.dev.yaml destination: ./config.yaml The shorthand: copies: [ref, ...] # is equivalent to copies: [{ from: ref }, ...] And the following defaults are used when no `source` and `destination` are specified. copies: - from: local # defaults to - from: local source: . destination: . copies: - from: variant # defaults to two entries - from: variant source: /srv/app # the lives.in dir destination: /srv/app - from: variant source: /opt/local # the shared lib dir destination: /opt/local Bug: T211625 Change-Id: I4c4217905afc0762b6bd66ed594d43cc0486e3e2
5 years ago
7 years ago
7 years ago
7 years ago
  1. ![Blubber](docs/logo-400.png)
  2. **Very experimental proof of concept.**
  3. Blubber is a highly opinionated abstraction for container build configurations
  4. and a command-line compiler which currently supports outputting multi-stage
  5. Dockerfiles. It aims to provide a handful of declarative constructs that
  6. accomplish build configuration in a more secure and determinate way than
  7. running ad-hoc commands.
  8. ## Example configuration
  9. ```yaml
  10. version: v4
  11. base: debian:jessie
  12. apt:
  13. packages: [libjpeg, libyaml]
  14. lives:
  15. in: /srv/service
  16. runs:
  17. environment:
  18. FOO: bar
  19. BAR: baz
  20. variants:
  21. build:
  22. apt:
  23. packages: [libjpeg-dev, libyaml-dev]
  24. node:
  25. requirements: [package.json, package-lock.json]
  26. copies: [local]
  27. development:
  28. includes: [build]
  29. test:
  30. includes: [build]
  31. apt:
  32. packages: [chromium]
  33. entrypoint: [npm, test]
  34. prep:
  35. includes: [build]
  36. node:
  37. env: production
  38. production:
  39. base: debian:jessie-slim
  40. node:
  41. env: production
  42. copies: [prep]
  43. entrypoint: [node, server.js]
  44. ```
  45. ## Variants
  46. Blubber supports a concept of composeable configuration variants for defining
  47. slightly different container images while still maintaining a sufficient
  48. degree of parity between them. For example, images for development and testing
  49. may require some development and debugging packages which you wouldn't want in
  50. production lest they contain vulnerabilities and somehow end up linked or
  51. included in the application runtime.
  52. Properties declared at the top level are shared among all variants unless
  53. redefined, and one variant can include the properties of others. Some
  54. properties, like `apt:packages` are combined when inherited or included.
  55. In the example configuration, the `test` variant when expanded effectively
  56. becomes:
  57. ```yaml
  58. version: v4
  59. base: debian:jessie
  60. apt:
  61. packages: [libjpeg, libyaml, libjpeg-dev, libyaml-dev, chromium]
  62. node:
  63. dependencies: true
  64. runs:
  65. in: /srv/service
  66. as: runuser
  67. uid: 666
  68. gid: 666
  69. entrypoint: [npm, test]
  70. ```
  71. ## Artifacts
  72. When trying to ensure optimally sized Docker images for production, there's a
  73. common pattern that has emerged which is essentially to use one image for
  74. building an application and copying the resulting build artifacts to another
  75. much more optimized image, using the latter for production.
  76. The Docker community has responded to this need by implementing
  77. [multi-stage builds](https://github.com/moby/moby/pull/32063) and Blubber
  78. makes use of this with its `copies` configuration property.
  79. In the example configuration, the `production` variant declares artifacts to
  80. be copied over from the result of building the `prep` image.
  81. ## Usage
  82. Running the `blubber` command will be produce `Dockerfile` output for the
  83. given variant.
  84. blubber config.yaml variant
  85. You can see the result of the example configuration by cloning this repo and
  86. running (assuming you have go):
  87. make
  88. ./bin/blubber blubber blubber.example.yaml development
  89. ./bin/blubber blubber blubber.example.yaml test
  90. ./bin/blubber blubber blubber.example.yaml production
  91. ## Contribution
  92. If you'd like to make code contributions to Blubber, see
  93. [CONTRIBUTING.md](CONTRIBUTING.md).