docker-bake.hcl 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. // ==== Baking Variables ====
  2. // Set which cargo profile to use, dev or release for example
  3. // Use the value provided in the Dockerfile as default
  4. variable "CARGO_PROFILE" {
  5. default = null
  6. }
  7. // Set which DB's (features) to enable
  8. // Use the value provided in the Dockerfile as default
  9. variable "DB" {
  10. default = null
  11. }
  12. // The repository this build was triggered from
  13. variable "SOURCE_REPOSITORY_URL" {
  14. default = null
  15. }
  16. // The commit hash of the current commit this build was triggered on
  17. variable "SOURCE_COMMIT" {
  18. default = null
  19. }
  20. // The version of this build
  21. // Typically the current exact tag of this commit,
  22. // else the last tag and the first 8 characters of the source commit
  23. variable "SOURCE_VERSION" {
  24. default = null
  25. }
  26. // This can be used to overwrite SOURCE_VERSION
  27. // It will be used during the build.rs building stage
  28. variable "VW_VERSION" {
  29. default = null
  30. }
  31. // The base tag(s) to use
  32. // This can be a comma separated value like "testing,1.29.2"
  33. variable "BASE_TAGS" {
  34. default = "testing"
  35. }
  36. // Which container registries should be used for the tagging
  37. // This can be a comma separated value
  38. // Use a full URI like `ghcr.io/dani-garcia/vaultwarden,docker.io/vaultwarden/server`
  39. variable "CONTAINER_REGISTRIES" {
  40. default = "vaultwarden/server"
  41. }
  42. // ==== Baking Groups ====
  43. group "default" {
  44. targets = ["debian"]
  45. }
  46. // ==== Shared Baking ====
  47. function "labels" {
  48. params = []
  49. result = {
  50. "org.opencontainers.image.description" = "Unofficial Bitwarden compatible server written in Rust - ${SOURCE_VERSION}"
  51. "org.opencontainers.image.licenses" = "AGPL-3.0-only"
  52. "org.opencontainers.image.documentation" = "https://github.com/dani-garcia/vaultwarden/wiki"
  53. "org.opencontainers.image.url" = "https://github.com/dani-garcia/vaultwarden"
  54. "org.opencontainers.image.created" = "${formatdate("YYYY-MM-DD'T'hh:mm:ssZZZZZ", timestamp())}"
  55. "org.opencontainers.image.source" = "${SOURCE_REPOSITORY_URL}"
  56. "org.opencontainers.image.revision" = "${SOURCE_COMMIT}"
  57. "org.opencontainers.image.version" = "${SOURCE_VERSION}"
  58. }
  59. }
  60. target "_default_attributes" {
  61. labels = labels()
  62. args = {
  63. DB = "${DB}"
  64. CARGO_PROFILE = "${CARGO_PROFILE}"
  65. VW_VERSION = "${VW_VERSION}"
  66. }
  67. }
  68. // ==== Debian Baking ====
  69. // Default Debian target, will build a container using the hosts platform architecture
  70. target "debian" {
  71. inherits = ["_default_attributes"]
  72. dockerfile = "docker/Dockerfile.debian"
  73. tags = generate_tags("", platform_tag())
  74. output = ["type=docker"]
  75. }
  76. // Multi Platform target, will build one tagged manifest with all supported architectures
  77. // This is mainly used by GitHub Actions to build and push new containers
  78. target "debian-multi" {
  79. inherits = ["debian"]
  80. platforms = ["linux/amd64", "linux/arm64", "linux/arm/v7", "linux/arm/v6"]
  81. tags = generate_tags("", "")
  82. output = [join(",", flatten([["type=registry"], image_index_annotations()]))]
  83. }
  84. // Per platform targets, to individually test building per platform locally
  85. target "debian-amd64" {
  86. inherits = ["debian"]
  87. platforms = ["linux/amd64"]
  88. tags = generate_tags("", "-amd64")
  89. }
  90. target "debian-arm64" {
  91. inherits = ["debian"]
  92. platforms = ["linux/arm64"]
  93. tags = generate_tags("", "-arm64")
  94. }
  95. target "debian-armv7" {
  96. inherits = ["debian"]
  97. platforms = ["linux/arm/v7"]
  98. tags = generate_tags("", "-armv7")
  99. }
  100. target "debian-armv6" {
  101. inherits = ["debian"]
  102. platforms = ["linux/arm/v6"]
  103. tags = generate_tags("", "-armv6")
  104. }
  105. // ==== Start of unsupported Debian architecture targets ===
  106. // These are provided just to help users build for these rare platforms
  107. // They will not be built by default
  108. target "debian-386" {
  109. inherits = ["debian"]
  110. platforms = ["linux/386"]
  111. tags = generate_tags("", "-386")
  112. args = {
  113. ARCH_OPENSSL_LIB_DIR = "/usr/lib/i386-linux-gnu"
  114. ARCH_OPENSSL_INCLUDE_DIR = "/usr/include/i386-linux-gnu"
  115. }
  116. }
  117. target "debian-ppc64le" {
  118. inherits = ["debian"]
  119. platforms = ["linux/ppc64le"]
  120. tags = generate_tags("", "-ppc64le")
  121. args = {
  122. ARCH_OPENSSL_LIB_DIR = "/usr/lib/powerpc64le-linux-gnu"
  123. ARCH_OPENSSL_INCLUDE_DIR = "/usr/include/powerpc64le-linux-gnu"
  124. }
  125. }
  126. target "debian-s390x" {
  127. inherits = ["debian"]
  128. platforms = ["linux/s390x"]
  129. tags = generate_tags("", "-s390x")
  130. args = {
  131. ARCH_OPENSSL_LIB_DIR = "/usr/lib/s390x-linux-gnu"
  132. ARCH_OPENSSL_INCLUDE_DIR = "/usr/include/s390x-linux-gnu"
  133. }
  134. }
  135. // ==== End of unsupported Debian architecture targets ===
  136. // A Group to build all platforms individually for local testing
  137. group "debian-all" {
  138. targets = ["debian-amd64", "debian-arm64", "debian-armv7", "debian-armv6"]
  139. }
  140. // ==== Alpine Baking ====
  141. // Default Alpine target, will build a container using the hosts platform architecture
  142. target "alpine" {
  143. inherits = ["_default_attributes"]
  144. dockerfile = "docker/Dockerfile.alpine"
  145. tags = generate_tags("-alpine", platform_tag())
  146. output = ["type=docker"]
  147. }
  148. // Multi Platform target, will build one tagged manifest with all supported architectures
  149. // This is mainly used by GitHub Actions to build and push new containers
  150. target "alpine-multi" {
  151. inherits = ["alpine"]
  152. platforms = ["linux/amd64", "linux/arm64", "linux/arm/v7", "linux/arm/v6"]
  153. tags = generate_tags("-alpine", "")
  154. output = [join(",", flatten([["type=registry"], image_index_annotations()]))]
  155. }
  156. // Per platform targets, to individually test building per platform locally
  157. target "alpine-amd64" {
  158. inherits = ["alpine"]
  159. platforms = ["linux/amd64"]
  160. tags = generate_tags("-alpine", "-amd64")
  161. }
  162. target "alpine-arm64" {
  163. inherits = ["alpine"]
  164. platforms = ["linux/arm64"]
  165. tags = generate_tags("-alpine", "-arm64")
  166. }
  167. target "alpine-armv7" {
  168. inherits = ["alpine"]
  169. platforms = ["linux/arm/v7"]
  170. tags = generate_tags("-alpine", "-armv7")
  171. }
  172. target "alpine-armv6" {
  173. inherits = ["alpine"]
  174. platforms = ["linux/arm/v6"]
  175. tags = generate_tags("-alpine", "-armv6")
  176. }
  177. // A Group to build all platforms individually for local testing
  178. group "alpine-all" {
  179. targets = ["alpine-amd64", "alpine-arm64", "alpine-armv7", "alpine-armv6"]
  180. }
  181. // ==== Bake everything locally ====
  182. group "all" {
  183. targets = ["debian-all", "alpine-all"]
  184. }
  185. // ==== Baking functions ====
  186. // This will return the local platform as amd64, arm64 or armv7 for example
  187. // It can be used for creating a local image tag
  188. function "platform_tag" {
  189. params = []
  190. result = "-${replace(replace(BAKE_LOCAL_PLATFORM, "linux/", ""), "/", "")}"
  191. }
  192. function "get_container_registries" {
  193. params = []
  194. result = flatten(split(",", CONTAINER_REGISTRIES))
  195. }
  196. function "get_base_tags" {
  197. params = []
  198. result = flatten(split(",", BASE_TAGS))
  199. }
  200. function "generate_tags" {
  201. params = [
  202. suffix, // What to append to the BASE_TAG when needed, like `-alpine` for example
  203. platform // the platform we are building for if needed
  204. ]
  205. result = flatten([
  206. for registry in get_container_registries() :
  207. [for base_tag in get_base_tags() :
  208. concat(
  209. # If the base_tag contains latest, and the suffix contains `-alpine` add a `:alpine` tag too
  210. base_tag == "latest" ? suffix == "-alpine" ? ["${registry}:alpine${platform}"] : [] : [],
  211. # The default tagging strategy
  212. ["${registry}:${base_tag}${suffix}${platform}"]
  213. )
  214. ]
  215. ])
  216. }
  217. function "image_index_annotations" {
  218. params = []
  219. result = flatten([
  220. for key, value in labels() :
  221. value != null ? formatlist("annotation-index.%s=%s", "${key}", "${value}") : []
  222. ])
  223. }