Repository: compose-spec/compose-go
Pull request #236 (2022-03-10 09:48:09)

add secrets property to build section
This implements https://github.com/compose-spec/compose-spec/pull/238


Patch:
diff --git a/loader/full-example.yml b/loader/full-example.yml
index 4f17450..0a77f3a 100644
--- a/loader/full-example.yml
+++ b/loader/full-example.yml
@@ -15,6 +15,13 @@ services:
         - foo
         - bar
       labels: [FOO=BAR]
+      secrets:
+        - secret1
+        - source: secret2
+          target: my_secret
+          uid: '103'
+          gid: '103'
+          mode: 0440
 
 
     cap_add:
diff --git a/schema/compose-spec.json b/schema/compose-spec.json
index 5bf4ddd..697034e 100644
--- a/schema/compose-spec.json
+++ b/schema/compose-spec.json
@@ -99,7 +99,8 @@
                 "target": {"type": "string"},
                 "shm_size": {"type": ["integer", "string"]},
                 "extra_hosts": {"$ref": "#/definitions/list_or_dict"},
-                "isolation": {"type": "string"}
+                "isolation": {"type": "string"},
+                "secrets": {"$ref": "#/definitions/service_config_or_secret"}
               },
               "additionalProperties": false,
               "patternProperties": {"^x-": {}}
@@ -142,26 +143,7 @@
             {"type": "array", "items": {"type": "string"}}
           ]
         },
-        "configs": {
-          "type": "array",
-          "items": {
-            "oneOf": [
-              {"type": "string"},
-              {
-                "type": "object",
-                "properties": {
-                  "source": {"type": "string"},
-                  "target": {"type": "string"},
-                  "uid": {"type": "string"},
-                  "gid": {"type": "string"},
-                  "mode": {"type": "number"}
-                },
-                "additionalProperties": false,
-                "patternProperties": {"^x-": {}}
-              }
-            ]
-          }
-        },
+        "configs": {"$ref": "#/definitions/service_config_or_secret"},
         "container_name": {"type": "string"},
         "cpu_count": {"type": "integer", "minimum": 0},
         "cpu_percent": {"type": "integer", "minimum": 0, "maximum": 100},
@@ -350,26 +332,7 @@
         },
         "security_opt": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
         "shm_size": {"type": ["number", "string"]},
-        "secrets": {
-          "type": "array",
-          "items": {
-            "oneOf": [
-              {"type": "string"},
-              {
-                "type": "object",
-                "properties": {
-                  "source": {"type": "string"},
-                  "target": {"type": "string"},
-                  "uid": {"type": "string"},
-                  "gid": {"type": "string"},
-                  "mode": {"type": "number"}
-                },
-                "additionalProperties": false,
-                "patternProperties": {"^x-": {}}
-              }
-            ]
-          }
-        },
+        "secrets": {"$ref": "#/definitions/service_config_or_secret"},
         "sysctls": {"$ref": "#/definitions/list_or_dict"},
         "stdin_open": {"type": "boolean"},
         "stop_grace_period": {"type": "string", "format": "duration"},
@@ -807,6 +770,27 @@
       "additionalProperties": false
     },
 
+    "service_config_or_secret": {
+      "type": "array",
+      "items": {
+        "oneOf": [
+          {"type": "string"},
+          {
+            "type": "object",
+            "properties": {
+              "source": {"type": "string"},
+              "target": {"type": "string"},
+              "uid": {"type": "string"},
+              "gid": {"type": "string"},
+              "mode": {"type": "number"}
+            },
+            "additionalProperties": false,
+            "patternProperties": {"^x-": {}}
+          }
+        ]
+      }
+    },
+
     "constraints": {
       "service": {
         "id": "#/definitions/constraints/service",
diff --git a/types/types.go b/types/types.go
index e25150e..9538ca3 100644
--- a/types/types.go
+++ b/types/types.go
@@ -302,6 +302,7 @@ type BuildConfig struct {
 	Isolation  string            `yaml:",omitempty" json:"isolation,omitempty"`
 	Network    string            `yaml:",omitempty" json:"network,omitempty"`
 	Target     string            `yaml:",omitempty" json:"target,omitempty"`
+	Secrets    []ServiceSecretConfig `yaml:",omitempty" json:"secrets,omitempty"`
 
 	Extensions map[string]interface{} `yaml:",inline" json:"-"`
 }


Test patch:
diff --git a/loader/full-struct_test.go b/loader/full-struct_test.go
index ee19fd2..36f9d6f 100644
--- a/loader/full-struct_test.go
+++ b/loader/full-struct_test.go
@@ -58,6 +58,18 @@ func services(workingDir, homeDir string) []types.ServiceConfig {
 				Network:    "foo",
 				CacheFrom:  []string{"foo", "bar"},
 				Labels:     map[string]string{"FOO": "BAR"},
+				Secrets: []types.ServiceSecretConfig{
+					{
+						Source: "secret1",
+					},
+					{
+						Source: "secret2",
+						Target: "my_secret",
+						UID:    "103",
+						GID:    "103",
+						Mode:   uint32Ptr(0440),
+					},
+				},
 			},
 			CapAdd:       []string{"ALL"},
 			CapDrop:      []string{"NET_ADMIN", "SYS_ADMIN"},
@@ -579,6 +591,13 @@ services:
       - bar
       network: foo
       target: foo
+      secrets:
+      - source: secret1
+      - source: secret2
+        target: my_secret
+        uid: "103"
+        gid: "103"
+        mode: 288
     cap_add:
     - ALL
     cap_drop:
@@ -1096,7 +1115,19 @@ func fullExampleJSON(workingDir, homeDir string) string {
           "bar"
         ],
         "network": "foo",
-        "target": "foo"
+        "target": "foo",
+        "secrets": [
+          {
+            "source": "secret1"
+          },
+          {
+            "source": "secret2",
+            "target": "my_secret",
+            "uid": "103",
+            "gid": "103",
+            "mode": 288
+          }
+        ]
       },
       "cap_add": [
         "ALL"