compose-validatr 0.1.3

Library for parsing and validating Docker compose manifests
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
//! Service fields and validation

mod blkio_config;
mod build;
mod deploy;
mod healthcheck;
mod logging;
mod networks;
mod ports;
mod secrets;
mod volumes;

use crate::{compose::Compose, errors::ValidationError};
use regex::Regex;
use std::collections::HashMap;

use serde::{Deserialize, Serialize};

use crate::{compose::Validate, errors::ValidationErrors};

/// Represents the top level [Service](https://docs.docker.com/compose/compose-file/05-services/) element
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Service {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub attach: Option<bool>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub build: Option<build::Build>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub blkio_config: Option<blkio_config::BlkioConfig>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub cpu_count: Option<u8>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub cpu_percent: Option<f32>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub cpu_shares: Option<u32>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub cpu_period: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub cpu_quota: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub cpu_rt_runtime: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub cpu_rt_period: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub cpus: Option<f32>, // deprecated

    #[serde(skip_serializing_if = "Option::is_none")]
    pub cpuset: Option<u8>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub cap_add: Option<Vec<Capabilities>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub cap_drop: Option<Vec<Capabilities>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub cgroup: Option<Cgroup>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub cgroup_parent: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub command: Option<Command>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub configs: Option<Vec<Config>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub container_name: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub credential_spec: Option<CredentialSpec>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub depends_on: Option<DependsOn>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub deploy: Option<deploy::Deploy>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub device_cgroup_rules: Option<Vec<String>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub devices: Option<Vec<String>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub dns: Option<Labels>, // TODO: maybe validate as ipv4

    #[serde(skip_serializing_if = "Option::is_none")]
    pub dns_opt: Option<Vec<String>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub dns_search: Option<Labels>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub domainname: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub entrypoint: Option<Labels>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub env_file: Option<Labels>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub environment: Option<Labels>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub expose: Option<Vec<String>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub extends: Option<Extends>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub annotations: Option<Labels>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub external_links: Option<Vec<String>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub extra_hosts: Option<Labels>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub group_add: Option<Vec<String>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub healthcheck: Option<healthcheck::HealthCheck>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub hostname: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub image: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub init: Option<bool>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub ipc: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub uts: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub isolation: Option<String>, // TODO: Verify this

    #[serde(skip_serializing_if = "Option::is_none")]
    pub labels: Option<Labels>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub links: Option<Vec<String>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub logging: Option<logging::Logging>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub network_mode: Option<String>, // TODO: Maybe make enum for this?

    #[serde(skip_serializing_if = "Option::is_none")]
    pub networks: Option<networks::Networks>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub mac_address: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub mem_limit: Option<String>, // deprecated

    #[serde(skip_serializing_if = "Option::is_none")]
    pub mem_reservation: Option<String>, // deprecated

    #[serde(skip_serializing_if = "Option::is_none")]
    pub mem_swappiness: Option<u8>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub memswap_limit: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub oom_kill_disable: Option<bool>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub oom_score_adj: Option<i16>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub pid: Option<u32>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub pids_limit: Option<u32>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub platform: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub ports: Option<ports::Ports>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub privileged: Option<bool>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub profiles: Option<Vec<String>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub pull_policy: Option<PullPolicy>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub read_only: Option<bool>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub restart: Option<Restart>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub runtime: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub scale: Option<u32>, // deprecated

    #[serde(skip_serializing_if = "Option::is_none")]
    pub secrets: Option<Vec<secrets::Secret>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub secruity_opt: Option<Vec<String>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub shm_size: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub stdin_open: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub stop_grace_period: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub stop_signal: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub storage_opt: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub sysctls: Option<Labels>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub tmpfs: Option<Tmpfs>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub tty: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub ulimits: Option<Ulimits>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub user: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub userns_mode: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub volumes: Option<Vec<volumes::Volumes>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub volumes_from: Option<Vec<String>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub working_dir: Option<String>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum Labels {
    List(Vec<String>),
    Map(HashMap<String, String>),
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum Tmpfs {
    String(String),
    List(Vec<String>),
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum Config {
    Short(String),
    Long(ConfigDetails),
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ConfigDetails {
    pub source: String,
    pub target: String,
    pub uid: String,
    pub gid: String,
    pub mode: String,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum Cgroup {
    Host,
    Private,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum Command {
    String(String),
    List(Vec<String>),
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct CredentialSpec {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub file: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub registry: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub config: Option<String>, // must be valid config
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum DependsOn {
    List(Vec<String>), // must be valid services
    Map(HashMap<String, DependsOnDetail>),
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct DependsOnDetail {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub restart: Option<bool>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub condition: Option<DependsOnCondition>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub required: Option<bool>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum DependsOnCondition {
    ServiceStarted,
    ServiceHealthy,
    ServiceCompletedSuccessfully,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Extends {
    // https://docs.docker.com/compose/compose-file/05-services/#extends
    pub file: String,
    pub service: String,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum PullPolicy {
    Always,
    Never,
    Missing,
    Build,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum Restart {
    No,
    Always,
    OnFailure,
    UnlessStopped,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Ulimits {
    pub nproc: u16,
    pub nofile: Nofile,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Nofile {
    pub soft: u16,
    pub hard: u16,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum Capabilities {
    All,
    AuditControl,
    AuditRead,
    AuditWrite,
    BlockSuspend,
    Bpf,
    CheckpointRestore,
    Chown,
    DacOverride,
    DacReadSearch,
    Fowner,
    Fsetid,
    IpcLock,
    IpcOwner,
    Kill,
    Lease,
    LinuxImmutable,
    MacAdmin,
    MacOverride,
    Mknod,
    NetAdmin,
    NetBindService,
    NetBroadcast,
    NetRaw,
    Perfmon,
    Setgid,
    Setfcap,
    Setpcap,
    Setuid,
    SysAdmin,
    SysBoot,
    SysChroot,
    SysModule,
    SysNice,
    SysPacct,
    SysPtrace,
    SysRawio,
    SysResource,
    SysTime,
    SysTtyConfig,
    Syslog,
    WakeAlarm,
}

impl Service {
    fn validate_blkio_config(&self, ctx: &Compose, errors: &mut ValidationErrors) {
        self.blkio_config.as_ref().map(|b| b.validate(ctx, errors));
    }

    fn validate_build(&self, ctx: &Compose, errors: &mut ValidationErrors) {
        self.build.as_ref().map(|b| b.validate(ctx, errors));
    }

    fn validate_deploy(&self, ctx: &Compose, errors: &mut ValidationErrors) {
        self.deploy.as_ref().map(|d| d.validate(ctx, errors));
    }

    fn validate_healthcheck(&self, ctx: &Compose, errors: &mut ValidationErrors) {
        self.healthcheck.as_ref().map(|h| h.validate(ctx, errors));
    }

    fn validate_logging(&self, ctx: &Compose, errors: &mut ValidationErrors) {
        self.logging.as_ref().map(|l| l.validate(ctx, errors));
    }

    fn validate_networks(&self, ctx: &Compose, errors: &mut ValidationErrors) {
        self.networks.as_ref().map(|n| n.validate(ctx, errors));
    }

    fn validate_ports(&self, ctx: &Compose, errors: &mut ValidationErrors) {
        self.ports.as_ref().map(|p| p.validate(ctx, errors));
    }

    fn validate_secrets(&self, ctx: &Compose, errors: &mut ValidationErrors) {
        self.secrets
            .as_ref()
            .map(|s| s.iter().for_each(|s| s.validate(ctx, errors)));
    }

    fn validate_volumes(&self, ctx: &Compose, errors: &mut ValidationErrors) {
        self.volumes
            .as_ref()
            .map(|v| v.iter().for_each(|volume| volume.validate(ctx, errors)));
    }

    fn validate_configs(&self, ctx: &Compose, errors: &mut ValidationErrors) {
        // configs must exist in top level configs

        self.configs.as_ref().map(|c| {
            c.iter().for_each(|config| match config {
                Config::Short(c) => {
                    ctx.configs.as_ref().map(|configs| {
                        if !configs.contains_key(c) {
                            errors.add_error(ValidationError::InvalidValue(format!(
                                "Config is not defined: {}",
                                c
                            )))
                        }
                    });
                }
                Config::Long(c) => {
                    ctx.configs.as_ref().map(|configs| {
                        if !configs.contains_key(&c.source) {
                            errors.add_error(ValidationError::InvalidValue(format!(
                                "Config is not defined: {}",
                                &c.source
                            )))
                        }
                    });
                }
            })
        });
    }

    fn validate_credential_spec(&self, ctx: &Compose, errors: &mut ValidationErrors) {
        self.credential_spec.as_ref().map(|c| {
            let result = c.config.as_ref().map(|cred| {
                ctx.configs
                    .as_ref()
                    .map(|configs| configs.contains_key(cred))
                    .is_some()
            });
            result.map(|r| {
                if !r {
                    errors.add_error(ValidationError::InvalidValue(
                        "Credential Spec references unknown config".to_string(),
                    ))
                }
            });
        });
    }

    fn validate_container_name(&self, _: &Compose, errors: &mut ValidationErrors) {
        let re = Regex::new(r"^[a-zA-Z0-9][a-zA-Z0-9_.-]+$").unwrap();
        self.container_name.as_ref().map(|c| {
            if !re.is_match(c) {
                errors.add_error(ValidationError::InvalidValue(
                    "Invalid container name".to_string(),
                ));
            }
        });
    }

    fn validate_depends_on(&self, ctx: &Compose, errors: &mut ValidationErrors) {
        self.depends_on.as_ref().map(|d| match d {
            DependsOn::List(service) => {
                let result = service.iter().any(|s| ctx.services.contains_key(s));
                if !result {
                    errors.add_error(ValidationError::InvalidValue(
                        "Invalid service for depends_on".to_string(),
                    ));
                }
            }
            DependsOn::Map(service) => {
                let result = service.iter().any(|s| ctx.services.contains_key(s.0));
                if !result {
                    errors.add_error(ValidationError::InvalidValue(
                        "Invalid service for depends_on".to_string(),
                    ));
                }
            }
        });
    }

    fn validate_expose(&self, _: &Compose, errors: &mut ValidationErrors) {
        self.expose.as_ref().map(|e| {
            e.iter().all(|port| match port.parse::<u16>() {
                Err(_) => {
                    errors.add_error(ValidationError::InvalidValue("Invalid port".to_string()));
                    false
                }
                _ => true,
            })
        });
    }

    fn validate_extends(&self, ctx: &Compose, errors: &mut ValidationErrors) {
        self.extends.as_ref().map(|e| {
            let result = ctx.services.contains_key(&e.service);
            if result {
                // Services that have dependencies on other services cannot be used as a base.
                // Therefore, any key that introduces a dependency on another service is incompatible
                // with extends. The non-exhaustive list of such keys is: links, volumes_from, container
                // mode (in ipc, pid, network_mode and net), service mode (in ipc, pid and network_mode), depends_on.
                let service = ctx.services.get(&e.service).unwrap();
                service.depends_on.as_ref().map(|_| {
                    errors.add_error(ValidationError::InvalidValue(
                        "Extends cannot extend another service that has a depends_on".to_string(),
                    ))
                });
                service.links.as_ref().map(|l| {
                    if l.len() > 0 {
                        errors.add_error(ValidationError::InvalidValue(
                            "Extends cannot have any links".to_string(),
                        ))
                    }
                });
                service.volumes_from.as_ref().map(|v| {
                    if v.len() > 0 {
                        errors.add_error(ValidationError::InvalidValue(
                            "Extends cannot have any volumes_from".to_string(),
                        ))
                    }
                });
                service.ipc.as_ref().map(|_| {
                    errors.add_error(ValidationError::InvalidValue(
                        "Extends cannot have an IPC mode".to_string(),
                    ))
                });
                service.network_mode.as_ref().map(|n| {
                    if n.starts_with("service:") {
                        errors.add_error(ValidationError::InvalidValue(
                            "Extends cannot extend a service that has a network dependency"
                                .to_string(),
                        ))
                    }
                });
            } else {
                errors.add_error(ValidationError::InvalidValue(
                    "Extends references invalid service".to_string(),
                ));
            }
        });
    }
}

impl Validate for Service {
    fn validate(&self, ctx: &Compose, errors: &mut ValidationErrors) {
        self.validate_blkio_config(ctx, errors);
        self.validate_build(ctx, errors);
        self.validate_deploy(ctx, errors);
        self.validate_healthcheck(ctx, errors);
        self.validate_logging(ctx, errors);
        self.validate_networks(ctx, errors);
        self.validate_ports(ctx, errors);
        self.validate_secrets(ctx, errors);
        self.validate_volumes(ctx, errors);
        self.validate_configs(ctx, errors);
        self.validate_container_name(ctx, errors);
        self.validate_credential_spec(ctx, errors);
        self.validate_depends_on(ctx, errors);
        self.validate_expose(ctx, errors);
        self.validate_extends(ctx, errors);
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn depends_on_missing_service() {
        let yaml = r#"
        services:
          gitlab:
            image: gitlab/gitlab-ce:latest
            container_name: gitlab
            hostname: gitlab
            restart: always
            depends_on:
              - hello_world
        "#;

        let compose = Compose::new(yaml);
        assert!(compose.is_err());
        assert!(compose.is_err_and(|e| e.all_errors().len() == 1));
    }

    #[test]
    fn depends_on_valid_service() {
        let yaml = r#"
        services:
          gitlab:
            image: gitlab/gitlab-ce:latest
            container_name: gitlab
            hostname: gitlab
            restart: always
            depends_on:
              - hello_world
          hello_world:
            image: gitlab/gitlab-ce:latest
            container_name: gitlab
            hostname: gitlab
            restart: always
        "#;

        let compose = Compose::new(yaml);
        assert!(compose.is_ok());
    }

    #[test]
    fn valid_config() {
        let yaml = r#"
        services:
          gitlab:
            image: gitlab/gitlab-ce:latest
            container_name: gitlab
            hostname: gitlab
            restart: always
            configs:
              - my_config
              - my_other_config
        configs:
          my_config:
            file: ./my_config.txt  
          my_other_config:
            external: true
        "#;

        let compose = Compose::new(yaml);
        assert!(compose.is_ok());
    }

    #[test]
    fn invalid_config() {
        let yaml = r#"
        services:
          gitlab:
            image: gitlab/gitlab-ce:latest
            container_name: gitlab
            hostname: gitlab
            restart: always
            configs:
              - hello
              - world
        configs:
          my_config:
            file: ./my_config.txt  
          my_other_config:
            external: true
        "#;

        let compose = Compose::new(yaml);
        dbg!(&compose);
        assert!(compose.is_err());
    }
}