@balena/compose-parser 0.0.2-build-setup-compose-go-1206dd03ac7e912df0da255a5bbf3d40cb932da1-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/errors.ts ADDED
@@ -0,0 +1,41 @@
1
+ import { TypedError } from 'typed-error';
2
+
3
+ export enum ErrorLevel {
4
+ ERROR = 'error',
5
+ FATAL = 'fatal',
6
+ WARN = 'warn',
7
+ INFO = 'info',
8
+ DEBUG = 'debug',
9
+ }
10
+
11
+ export class ComposeError extends TypedError {
12
+ constructor(
13
+ public message: string,
14
+ // The error level, e.g. "error", "fatal", "panic"
15
+ public level = ErrorLevel.ERROR,
16
+ public name = 'ComposeError',
17
+ ) {
18
+ super(message);
19
+ }
20
+ }
21
+
22
+ export class ValidationError extends ComposeError {
23
+ constructor(public message: string) {
24
+ super(message, ErrorLevel.ERROR, 'ValidationError');
25
+ }
26
+ }
27
+
28
+ export class ServiceError extends ComposeError {
29
+ constructor(
30
+ public message: string,
31
+ public serviceName: string,
32
+ ) {
33
+ super(message, ErrorLevel.ERROR, 'ServiceError');
34
+ }
35
+ }
36
+
37
+ export class ArgumentError extends ComposeError {
38
+ constructor(public message: string) {
39
+ super(message, ErrorLevel.ERROR, 'ArgumentError');
40
+ }
41
+ }
package/lib/go.mod ADDED
@@ -0,0 +1,23 @@
1
+ module balena-compose-go
2
+
3
+ go 1.24.4
4
+
5
+ require (
6
+ github.com/compose-spec/compose-go/v2 v2.8.1
7
+ github.com/sirupsen/logrus v1.9.0
8
+ )
9
+
10
+ require (
11
+ github.com/distribution/reference v0.5.0 // indirect
12
+ github.com/docker/go-connections v0.4.0 // indirect
13
+ github.com/docker/go-units v0.5.0 // indirect
14
+ github.com/go-viper/mapstructure/v2 v2.3.0 // indirect
15
+ github.com/mattn/go-shellwords v1.0.12 // indirect
16
+ github.com/opencontainers/go-digest v1.0.0 // indirect
17
+ github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 // indirect
18
+ github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
19
+ go.yaml.in/yaml/v3 v3.0.4 // indirect
20
+ golang.org/x/sync v0.3.0 // indirect
21
+ golang.org/x/sys v0.5.0 // indirect
22
+ golang.org/x/text v0.14.0 // indirect
23
+ )
package/lib/go.sum ADDED
@@ -0,0 +1,49 @@
1
+ github.com/compose-spec/compose-go/v2 v2.8.1 h1:27O4dzyhiS/UEUKp1zHOHCBWD1WbxGsYGMNNaSejTk4=
2
+ github.com/compose-spec/compose-go/v2 v2.8.1/go.mod h1:veko/VB7URrg/tKz3vmIAQDaz+CGiXH8vZsW79NmAww=
3
+ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4
+ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
5
+ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6
+ github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
7
+ github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
8
+ github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=
9
+ github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
10
+ github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
11
+ github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
12
+ github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
13
+ github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
14
+ github.com/go-viper/mapstructure/v2 v2.3.0 h1:27XbWsHIqhbdR5TIC911OfYvgSaW93HM+dX7970Q7jk=
15
+ github.com/go-viper/mapstructure/v2 v2.3.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
16
+ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
17
+ github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
18
+ github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=
19
+ github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
20
+ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
21
+ github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
22
+ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
23
+ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
24
+ github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 h1:PKK9DyHxif4LZo+uQSgXNqs0jj5+xZwwfKHgph2lxBw=
25
+ github.com/santhosh-tekuri/jsonschema/v6 v6.0.1/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU=
26
+ github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
27
+ github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
28
+ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
29
+ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
30
+ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
31
+ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
32
+ github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc=
33
+ github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU=
34
+ go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
35
+ go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
36
+ golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
37
+ golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
38
+ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
39
+ golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
40
+ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
41
+ golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
42
+ golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
43
+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
44
+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
45
+ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
46
+ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
47
+ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
48
+ gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o=
49
+ gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g=
package/lib/index.ts ADDED
@@ -0,0 +1,30 @@
1
+ import { parse, toImageDescriptors } from './compose';
2
+ import {
3
+ ServiceError,
4
+ ValidationError,
5
+ ArgumentError,
6
+ ComposeError,
7
+ } from './errors';
8
+ import {
9
+ Composition,
10
+ Service,
11
+ Network,
12
+ Volume,
13
+ BuildConfig,
14
+ ImageDescriptor,
15
+ } from './types';
16
+
17
+ export {
18
+ parse,
19
+ toImageDescriptors,
20
+ Composition,
21
+ Service,
22
+ Network,
23
+ Volume,
24
+ BuildConfig,
25
+ ImageDescriptor,
26
+ ComposeError,
27
+ ServiceError,
28
+ ValidationError,
29
+ ArgumentError,
30
+ };
package/lib/main.go ADDED
@@ -0,0 +1,147 @@
1
+ package main
2
+
3
+ import (
4
+ "context"
5
+ "encoding/json"
6
+ "fmt"
7
+ "os"
8
+ "time"
9
+
10
+ "github.com/compose-spec/compose-go/v2/cli"
11
+ "github.com/compose-spec/compose-go/v2/types"
12
+ "github.com/sirupsen/logrus"
13
+ )
14
+
15
+ // ErrorResponse represents error output from the parser
16
+ type ErrorResponse struct {
17
+ Error bool `json:"error"`
18
+ Name string `json:"name"`
19
+ Message string `json:"message"`
20
+ }
21
+
22
+ // Usage message
23
+ const usage = `
24
+ Usage: balena-compose-go -f <compose-file> [-f <compose-file>...] <project-name>
25
+
26
+ Parses one or more docker-compose files and outputs a structured response.
27
+
28
+ Arguments:
29
+ -f <compose-file> Path to a docker-compose file to parse (can be specified multiple times with later files overriding earlier ones)
30
+ <project-name> Name of the project to use for the parsed output. It is recommended to use a UUID, as any fields which include
31
+ the project name need to be removed for normalization into a compose acceptable by balena.
32
+
33
+ Example:
34
+ balena-compose-go -f docker-compose.yml -f docker-compose.override.yml my-project-name
35
+ `
36
+
37
+ func main() {
38
+ if len(os.Args) < 4 {
39
+ outputError("ArgumentError", usage)
40
+ os.Exit(1)
41
+ }
42
+
43
+ // Format logs outputted from compose-go to JSON
44
+ logrus.SetFormatter(&logrus.JSONFormatter{
45
+ FieldMap: logrus.FieldMap{
46
+ logrus.FieldKeyTime: "time",
47
+ logrus.FieldKeyLevel: "level",
48
+ logrus.FieldKeyMsg: "message",
49
+ },
50
+ })
51
+
52
+ var composeFiles []string
53
+ var projectName string
54
+
55
+ // Parse command line arguments
56
+ i := 1
57
+ for i < len(os.Args) {
58
+ if os.Args[i] == "-f" {
59
+ if i+1 >= len(os.Args) {
60
+ outputError("ArgumentError", "Missing file path after -f flag\n"+usage)
61
+ os.Exit(1)
62
+ }
63
+ composeFiles = append(composeFiles, os.Args[i+1])
64
+ i += 2
65
+ } else {
66
+ // The last non-flag argument should be the project name
67
+ projectName = os.Args[i]
68
+ i++
69
+ break
70
+ }
71
+ }
72
+
73
+ // Validate we have at least one compose file and a project name
74
+ if len(composeFiles) == 0 {
75
+ outputError("ArgumentError", "At least one compose file must be specified with -f\n"+usage)
76
+ os.Exit(1)
77
+ }
78
+
79
+ if projectName == "" {
80
+ outputError("ArgumentError", "Project name is required\n"+usage)
81
+ os.Exit(1)
82
+ }
83
+
84
+ // Create a timeout context - 10 seconds timeout for parsing
85
+ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
86
+ defer cancel()
87
+
88
+ options, err := cli.NewProjectOptions(
89
+ composeFiles,
90
+ cli.WithOsEnv,
91
+ cli.WithDotEnv,
92
+ cli.WithName(projectName),
93
+ )
94
+ if err != nil {
95
+ outputError("ConfigError", fmt.Sprintf("Failed to create compose project options: %v", err))
96
+ os.Exit(1)
97
+ }
98
+
99
+ // Channel to receive the result from the goroutine
100
+ type loadResult struct {
101
+ project *types.Project
102
+ err error
103
+ }
104
+ resultChan := make(chan loadResult, 1)
105
+
106
+ // Run LoadProject in a goroutine
107
+ go func() {
108
+ project, err := options.LoadProject(ctx)
109
+ resultChan <- loadResult{project: project, err: err}
110
+ }()
111
+
112
+ // Wait for either the result or timeout
113
+ var project *types.Project
114
+ select {
115
+ case result := <-resultChan:
116
+ if result.err != nil {
117
+ outputError("ParseError", fmt.Sprintf("Failed to parse compose file: %v", result.err))
118
+ os.Exit(1)
119
+ }
120
+ project = result.project
121
+ case <-ctx.Done():
122
+ outputError("TimeoutError", "Compose file parsing timed out after 10 seconds")
123
+ os.Exit(1)
124
+ }
125
+
126
+ // Get JSON representation using project's MarshalJSON method
127
+ projectJSON, err := project.MarshalJSON()
128
+ if err != nil {
129
+ outputError("ParseError", fmt.Sprintf("Failed to marshal compose project to JSON: %v", err))
130
+ os.Exit(1)
131
+ }
132
+
133
+ // Output the parsed project directly to stdout
134
+ os.Stdout.Write(projectJSON)
135
+ }
136
+
137
+ // Write a structured error response to stderr
138
+ func outputError(errorName, message string) {
139
+ response := ErrorResponse{
140
+ Error: true,
141
+ Name: errorName,
142
+ Message: message,
143
+ }
144
+
145
+ // Output to stderr for error handling in TypeScript
146
+ json.NewEncoder(os.Stderr).Encode(response)
147
+ }
package/lib/types.ts ADDED
@@ -0,0 +1,318 @@
1
+ // Types from https://docs.docker.com/reference/compose-file/ are the output
2
+ // from the compose-go parser, meaning that some inputs have been normalized.
3
+
4
+ export type Dict<T> = Record<string, T>;
5
+
6
+ // Helper types for primitive values, lists and dicts.
7
+ export type Value = string | number | null;
8
+ export type ByteValue = string;
9
+ export type DurationValue = string;
10
+ export type ListOrDict<T> = T[] | Dict<T>;
11
+ export type StringOrList = string | string[];
12
+ export type NonEmpty<T> = keyof T extends never ? never : T;
13
+
14
+ interface BlkioLimit {
15
+ path?: string;
16
+ rate?: number | ByteValue;
17
+ }
18
+
19
+ interface BlkioWeight {
20
+ path?: string;
21
+ weight?: number;
22
+ }
23
+
24
+ interface ConfigMount {
25
+ source: string;
26
+ target?: string;
27
+ uid?: string;
28
+ gid?: string;
29
+ mode?: number;
30
+ }
31
+ type Config = ConfigMount;
32
+ type Secret = ConfigMount;
33
+
34
+ interface DependsOnConfig {
35
+ condition: string;
36
+ restart?: boolean;
37
+ required?: boolean;
38
+ }
39
+
40
+ export interface DevicesConfig {
41
+ source: string;
42
+ target: string;
43
+ permissions: string;
44
+ }
45
+
46
+ interface EnvFileConfig {
47
+ path: string;
48
+ required?: boolean;
49
+ format?: string;
50
+ }
51
+
52
+ interface GPUConfig {
53
+ driver?: string;
54
+ count?: number;
55
+ device_ids?: string[];
56
+ options?: Dict<string>;
57
+ }
58
+
59
+ interface LifecycleHook {
60
+ command: string[]; // Normalized from StringOrList
61
+ user?: string;
62
+ privileged?: boolean;
63
+ working_dir?: string;
64
+ environment?: Dict<string>; // Normalized from ListOrDict<string>
65
+ }
66
+
67
+ interface PortConfig {
68
+ name?: string;
69
+ target?: number;
70
+ host_ip?: string;
71
+ published?: string;
72
+ protocol?: string;
73
+ app_protocol?: string;
74
+ mode?: string;
75
+ }
76
+
77
+ interface Ulimit {
78
+ soft: number;
79
+ hard: number;
80
+ }
81
+
82
+ interface ServiceVolumeBase {
83
+ type: string;
84
+ source?: string;
85
+ target?: string;
86
+ read_only?: boolean;
87
+ consistency?: string;
88
+ }
89
+
90
+ interface ServiceBindMount extends ServiceVolumeBase {
91
+ type: 'bind';
92
+ bind: {
93
+ propagation?: string;
94
+ create_host_path?: boolean;
95
+ selinux?: string;
96
+ };
97
+ }
98
+
99
+ interface ServiceVolumeMount extends ServiceVolumeBase {
100
+ type: 'volume';
101
+ volume: {
102
+ nocopy?: boolean;
103
+ subpath?: boolean;
104
+ };
105
+ }
106
+
107
+ interface ServiceTmpfsMount extends ServiceVolumeBase {
108
+ type: 'tmpfs';
109
+ tmpfs: {
110
+ size?: number | ByteValue;
111
+ mode?: number;
112
+ };
113
+ }
114
+
115
+ interface ServiceImageMount extends ServiceVolumeBase {
116
+ type: 'image';
117
+ image: {
118
+ subpath?: string;
119
+ };
120
+ }
121
+
122
+ export type ServiceVolumeConfig =
123
+ | ServiceBindMount
124
+ | ServiceVolumeMount
125
+ | ServiceTmpfsMount
126
+ | ServiceImageMount;
127
+
128
+ export interface BuildConfig {
129
+ additional_contexts?: Dict<string>; // Normalized from ListOrDict<string>
130
+ args?: Dict<string>; // Normalized from ListOrDict<string>
131
+ context?: string;
132
+ cache_from?: string[];
133
+ cache_to?: string[];
134
+ dockerfile?: string;
135
+ dockerfile_inline?: string;
136
+ entitlements?: string[];
137
+ extra_hosts?: string[]; // Normalized from ListOrDict<string>
138
+ isolation?: string;
139
+ labels?: Dict<string>; // Normalized from ListOrDict<string>
140
+ network?: string;
141
+ no_cache?: boolean;
142
+ platforms?: string[];
143
+ privileged?: boolean;
144
+ pull?: boolean;
145
+ secrets?: Secret[]; // Normalized from Array<string | Secret>
146
+ ssh?: string[];
147
+ shm_size?: number | string;
148
+ tags?: string[];
149
+ target?: string;
150
+ ulimits?: Dict<number | Ulimit>;
151
+ }
152
+
153
+ export interface Service {
154
+ annotations?: Dict<string>; // Normalized from ListOrDict<string>
155
+ attach?: boolean;
156
+ build?: BuildConfig;
157
+ blkio_config?: {
158
+ weight?: number;
159
+ weight_device?: BlkioWeight[];
160
+ device_read_bps?: BlkioLimit[];
161
+ device_write_bps?: BlkioLimit[];
162
+ device_read_iops?: BlkioLimit[];
163
+ device_write_iops?: BlkioLimit[];
164
+ };
165
+ cpu_count?: number;
166
+ cpu_percent?: number;
167
+ cpu_shares?: number | string;
168
+ cpu_period?: number | string;
169
+ cpu_quota?: number | string;
170
+ cpu_rt_runtime?: number | string;
171
+ cpu_rt_period?: number | string;
172
+ cap_add?: string[];
173
+ cap_drop?: string[];
174
+ cpus?: string;
175
+ cpuset?: string;
176
+ cgroup?: string;
177
+ cgroup_parent?: string;
178
+ command?: string[]; // Normalized from StringOrList
179
+ configs?: Config[]; // Normalized from Array<string | Config>
180
+ container_name?: string;
181
+ credential_spec?: Dict<string>;
182
+ depends_on?: string[] | Dict<DependsOnConfig>;
183
+ deploy?: Dict<any>; // Unsupported with no intention to support, therefore `any` is permissible
184
+ develop?: Array<{ watch: any }>; // Unsupported with no current intention to support (as we have livepush) therefore `any` is permissible
185
+ device_cgroup_rules?: string[];
186
+ devices?: string[] | DevicesConfig[];
187
+ dns?: string[]; // Normalized from StringOrList
188
+ dns_opt?: string[];
189
+ dns_search?: string[]; // Normalized from StringOrList
190
+ domainname?: string;
191
+ entrypoint?: string[]; // Normalized from StringOrList
192
+ env_file?: Array<string | EnvFileConfig>; // Normalized from StringOrList | EnvFileConfig[]; Files pointed by this are loaded and vars are folded into `environment`, with `environment` taking precedence
193
+ environment?: Dict<string>; // Normalized from ListOrDict<string>
194
+ expose?: string[];
195
+ // extends?: { file?: string; service: string }; While a field in the raw yaml file, this isn't included in the parsed composition
196
+ external_links?: string[];
197
+ extra_hosts?: string[]; // Normalized from ListOrDict<string>
198
+ gpus?: Array<NonEmpty<GPUConfig>>; // Normalized from 'all' | Array<GPUConfig>
199
+ group_add?: string[]; // Normalized from Array<string | number>
200
+ healthcheck?: NonEmpty<{
201
+ test?: string[]; // Normalized from StringOrList
202
+ disable?: boolean;
203
+ retries?: number;
204
+ interval?: DurationValue;
205
+ start_period?: DurationValue;
206
+ start_interval?: DurationValue;
207
+ timeout?: DurationValue;
208
+ }>;
209
+ hostname?: string;
210
+ image?: string;
211
+ init?: boolean;
212
+ ipc?: string;
213
+ isolation?: string;
214
+ labels?: Dict<string>; // Normalized from ListOrDict<string>
215
+ label_file?: string[]; // Normalized from string | string[]; Files pointed by this are loaded and labels are folded into `labels`, with `labels` taking precedence
216
+ links?: string[];
217
+ logging?: {
218
+ driver?: string;
219
+ options?: Dict<string>; // Normalized from Dict<string | number>
220
+ };
221
+ mac_address?: string;
222
+ mem_limit?: number | ByteValue;
223
+ mem_reservation?: number | ByteValue;
224
+ mem_swappiness?: number;
225
+ memswap_limit?: number | ByteValue;
226
+ network_mode?: string;
227
+ networks?: Dict<null | {
228
+ aliases?: string[];
229
+ driver_opts?: Dict<string>; // Normalized from Dict<string | number>
230
+ interface_name?: string;
231
+ ipv4_address?: string;
232
+ ipv6_address?: string;
233
+ link_local_ips?: string[];
234
+ mac_address?: string;
235
+ gw_priority?: number;
236
+ priority?: number;
237
+ }>; // Normalized from string[] | Dict<{..(same object as above)..}>;
238
+ oom_kill_disable?: boolean;
239
+ oom_score_adj?: number;
240
+ pid?: string;
241
+ pids_limit?: number;
242
+ platform?: string;
243
+ ports?: Array<string | PortConfig>;
244
+ post_start?: LifecycleHook[];
245
+ pre_stop?: LifecycleHook[];
246
+ privileged?: boolean;
247
+ // profiles?: string[]; While a field in the raw yaml file, this isn't included in the parsed composition
248
+ pull_policy?: string;
249
+ read_only?: boolean;
250
+ restart?: string;
251
+ runtime?: string;
252
+ scale?: number;
253
+ secrets?: Secret[]; // Normalized from Array<string | Secret>
254
+ security_opt?: string[];
255
+ shm_size?: number | ByteValue;
256
+ stdin_open?: boolean;
257
+ stop_grace_period?: DurationValue;
258
+ stop_signal?: string;
259
+ storage_opt?: Dict<string>; // Normalized from Dict<any>
260
+ sysctls?: Dict<string>; // Normalized from string[] | Dict<string | number>;
261
+ tmpfs?: string[]; // Normalized from StringOrList
262
+ tty?: boolean;
263
+ ulimits?: Dict<number | Ulimit>;
264
+ user?: string;
265
+ userns_mode?: string;
266
+ uts?: string;
267
+ volumes?: string[] | ServiceVolumeConfig[];
268
+ volumes_from?: string[];
269
+ working_dir?: string;
270
+ }
271
+
272
+ export interface Network {
273
+ driver?: string;
274
+ driver_opts?: Dict<string>; // Normalized from Dict<string | number>
275
+ attachable?: boolean;
276
+ enable_ipv4?: boolean;
277
+ enable_ipv6?: boolean;
278
+ external?: boolean;
279
+ ipam?: {
280
+ driver?: string;
281
+ config?: Array<{
282
+ subnet?: string;
283
+ ip_range?: string;
284
+ gateway?: string;
285
+ aux_addresses?: Dict<string>;
286
+ }>;
287
+ options?: Dict<string>;
288
+ };
289
+ internal?: boolean;
290
+ labels?: Dict<string>; // Normalized from ListOrDict<string>
291
+ name?: string;
292
+ }
293
+
294
+ export interface Volume {
295
+ driver?: string;
296
+ driver_opts?: Dict<string>; // Normalized from Dict<string | number>
297
+ external?: boolean;
298
+ labels?: Dict<string>; // Normalized from ListOrDict<string>
299
+ name?: string;
300
+ }
301
+
302
+ export interface Composition {
303
+ name?: string;
304
+ version?: string;
305
+ services: Dict<Service>;
306
+ networks?: Dict<Network>;
307
+ volumes?: Dict<Volume>;
308
+ }
309
+
310
+ export type ContractObject = {
311
+ type: string;
312
+ } & { [key: string]: any };
313
+
314
+ export interface ImageDescriptor {
315
+ serviceName: string;
316
+ image: string | BuildConfig;
317
+ contract?: ContractObject;
318
+ }
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@balena/compose-parser",
3
+ "version": "0.0.2-build-setup-compose-go-1206dd03ac7e912df0da255a5bbf3d40cb932da1-1",
4
+ "description": "Wraps compose-go to parse balena-compatible docker-compose.yml files",
5
+ "scripts": {
6
+ "clean": "rimraf dist",
7
+ "lint": "balena-lint lib/ test/ && tsc --noEmit",
8
+ "lint-fix": "balena-lint --fix lib/ test/",
9
+ "build": "npm run clean && npm run build:test",
10
+ "build:test": "tsc",
11
+ "build:release": "npm run clean && tsc --project tsconfig.release.json",
12
+ "build:go": "CGO_ENABLED=0 go build -C lib -ldflags='-s -w' -o '../dist/bin/balena-compose-go'",
13
+ "test": "npm run lint && npm run test:unit",
14
+ "test:unit": "npm run build:test && mocha 'dist/test/**/*unit.spec.js'",
15
+ "test:integration": "npm run build:test && mocha 'dist/test/**/*.spec.js'",
16
+ "test:compose": "(docker compose -f docker-compose.test.yml run --build --rm sut || docker compose logs); npm run compose:down",
17
+ "compose:down": "docker compose -f docker-compose.test.yml down --volumes",
18
+ "prepack": "npm run build:release",
19
+ "install": "node install.js"
20
+ },
21
+ "files": [
22
+ "dist/",
23
+ "lib/",
24
+ "install.js"
25
+ ],
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/balena-io-experimental/balena-compose-go.git"
29
+ },
30
+ "license": "Apache-2.0",
31
+ "bugs": {
32
+ "url": "https://github.com/balena-io-experimental/balena-compose-go/issues"
33
+ },
34
+ "homepage": "https://github.com/balena-io-experimental/balena-compose-go#readme",
35
+ "engines": {
36
+ "node": ">=20"
37
+ },
38
+ "main": "dist/lib/index.js",
39
+ "types": "dist/lib/index.d.ts",
40
+ "binary": {
41
+ "module_name": "balena-compose-go",
42
+ "module_path": "./dist/bin/",
43
+ "remote_path": "{version}",
44
+ "package_name": "balena-compose-go-{platform}-{arch}",
45
+ "host": "https://github.com/balena-io-experimental/balena-compose-go/releases/download/"
46
+ },
47
+ "devDependencies": {
48
+ "@balena/lint": "^9.3.3",
49
+ "@types/chai": "^5.2.2",
50
+ "@types/js-yaml": "^4.0.9",
51
+ "@types/mocha": "^10.0.10",
52
+ "@types/node": "^24.3.1",
53
+ "@types/semver": "^7.7.1",
54
+ "@types/sinon": "^17.0.4",
55
+ "chai": "^6.0.1",
56
+ "js-yaml": "^4.1.0",
57
+ "mocha": "^11.7.2",
58
+ "rimraf": "^6.0.1",
59
+ "sinon": "^21.0.0",
60
+ "typescript": "^5.9.2"
61
+ },
62
+ "dependencies": {
63
+ "@mapbox/node-pre-gyp": "^2.0.0",
64
+ "semver": "^7.7.2",
65
+ "typed-error": "^3.2.2"
66
+ },
67
+ "versionist": {
68
+ "publishedAt": "2025-09-10T07:03:28.900Z"
69
+ }
70
+ }