docker-compose-config 0.1.0

Rust representations for types belonging to docker compose's configuration. Supports (de)serialization, JSON schema and merging
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
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
use super::*;

#[cfg(feature = "presets")]
pub use presets::*;

#[doc(hidden)]
#[cfg(feature = "presets")]
mod presets {
	use super::*;

	/// Ways of representing a service in a Docker preset.
	#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
	#[cfg_attr(feature = "schemars", derive(JsonSchema))]
	#[serde(untagged)]
	pub enum ServicePresetRef {
		/// The id of a service preset.
		PresetId(String),

		/// The defitinion for a Docker service.
		Preset(Box<DockerServicePreset>),
	}

	impl ServicePresetRef {
		pub fn as_config(self) -> Option<Service> {
			match self {
				Self::PresetId(_) => None,
				Self::Preset(docker_service_preset) => Some(docker_service_preset.config),
			}
		}

		#[doc(hidden)]
		pub fn requires_processing(&self) -> bool {
			match self {
				Self::PresetId(_) => true,
				Self::Preset(data) => !data.extends_presets.is_empty(),
			}
		}
	}

	/// A preset for a Docker service
	#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Default, Merge)]
	#[cfg_attr(feature = "schemars", derive(JsonSchema))]
	#[serde(default)]
	pub struct DockerServicePreset {
		/// The list of extended presets.
		#[serde(skip_serializing)]
		#[merge(skip)]
		pub extends_presets: IndexSet<String>,

		#[serde(flatten)]
		pub config: Service,
	}
}

/// Defines a service for a Compose application.
///
/// See more: https://docs.docker.com/reference/compose-file/services/
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default, Merge)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(default)]
pub struct Service {
	/// `extends` lets you share common configurations among different files, or even different projects entirely.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#extends
	#[serde(skip_serializing_if = "Option::is_none")]
	pub extends: Option<Extends>,

	/// A string that specifies a custom container name, rather than a name generated by default. Compose does not scale a service beyond one container if the Compose file specifies a container_name. Attempting to do so results in an error.
	///
	/// container_name follows the regex format of [a-zA-Z0-9][a-zA-Z0-9_.-]+
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#container_name
	#[serde(skip_serializing_if = "Option::is_none")]
	pub container_name: Option<String>,

	/// A custom host name to use for the service container. It must be a valid RFC 1123 hostname.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub hostname: Option<String>,

	/// Specifies the image to start the container from. See more: https://docs.docker.com/reference/compose-file/services/#image
	#[serde(skip_serializing_if = "Option::is_none")]
	pub image: Option<String>,

	/// Specifies the build configuration for creating a container image from source, as defined in the [Compose Build Specification](https://docs.docker.com/reference/compose-file/build/).
	#[serde(skip_serializing_if = "Option::is_none", rename = "build")]
	#[merge(with = merge_options)]
	pub build_: Option<BuildStep>,

	/// With the depends_on attribute, you can control the order of service startup and shutdown. It is useful if services are closely coupled, and the startup sequence impacts the application's functionality.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#depends_on
	#[serde(skip_serializing_if = "Option::is_none")]
	#[merge(with = merge_options)]
	pub depends_on: Option<DependsOn>,

	/// Overrides the default command declared by the container image, for example by Dockerfile's CMD.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#command
	#[serde(skip_serializing_if = "Option::is_none")]
	pub command: Option<StringOrList>,

	/// Declares the default entrypoint for the service container. This overrides the ENTRYPOINT instruction from the service's Dockerfile.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#entrypoint
	#[serde(skip_serializing_if = "Option::is_none")]
	pub entrypoint: Option<StringOrList>,

	/// Declares a check that's run to determine whether or not the service containers are "healthy".
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#healthcheck
	#[serde(skip_serializing_if = "Option::is_none")]
	pub healthcheck: Option<Healthcheck>,

	/// Defines the (incoming) port or a range of ports that Compose exposes from the container. These ports must be accessible to linked services and should not be published to the host machine. Only the internal container ports can be specified.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#expose
	#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
	pub expose: BTreeSet<StringOrNum>,

	/// One or more files that contain environment variables to be passed to the containers.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#env_file
	#[serde(skip_serializing_if = "Option::is_none")]
	#[merge(with = merge_options)]
	pub env_file: Option<Envfile>,

	/// Defines environment variables set in the container. environment can use either an array or a map. Any boolean values; true, false, yes, no, should be enclosed in quotes to ensure they are not converted to True or False by the YAML parser.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#environment
	#[serde(default, skip_serializing_if = "ListOrMap::is_empty")]
	pub environment: ListOrMap,

	/// Defines annotations for the container. annotations can use either an array or a map.
	#[serde(default, skip_serializing_if = "ListOrMap::is_empty")]
	pub annotations: ListOrMap,

	/// Requires: Docker Compose 2.20.0 and later
	///
	/// When attach is defined and set to false Compose does not collect service logs, until you explicitly request it to.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub attach: Option<bool>,

	/// Defines a set of configuration options to set block I/O limits for a service.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#blkio_config
	#[serde(skip_serializing_if = "Option::is_none")]
	pub blkio_config: Option<BlkioSettings>,

	/// Specifies additional container [capabilities](https://man7.org/linux/man-pages/man7/capabilities.7.html) as strings.
	#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
	pub cap_add: BTreeSet<String>,

	/// Specifies container [capabilities](https://man7.org/linux/man-pages/man7/capabilities.7.html) to drop as strings.
	#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
	pub cap_drop: BTreeSet<String>,

	/// Requires: Docker Compose 2.15.0 and later
	///
	/// Specifies the cgroup namespace to join. When unset, it is the container runtime's decision to select which cgroup namespace to use, if supported.
	///
	/// host: Runs the container in the Container runtime cgroup namespace.
	/// private: Runs the container in its own private cgroup namespace.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub cgroup: Option<Cgroup>,

	/// Specifies an optional parent cgroup for the container.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub cgroup_parent: Option<String>,

	/// Lets services adapt their behaviour without the need to rebuild a Docker image.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#configs
	#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
	pub configs: BTreeSet<ServiceConfigOrSecret>,

	/// The number of usable CPUs for service container.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub cpu_count: Option<StringOrNum>,

	/// The usable percentage of the available CPUs.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub cpu_percent: Option<StringOrNum>,

	/// Configures CPU CFS (Completely Fair Scheduler) period when a platform is based on Linux kernel.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub cpu_period: Option<StringOrNum>,

	/// Configures CPU CFS (Completely Fair Scheduler) quota when a platform is based on Linux kernel.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub cpu_quota: Option<StringOrNum>,

	/// A service container's relative CPU weight versus other containers.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub cpu_shares: Option<StringOrNum>,

	/// Configures CPU allocation parameters for platforms with support for real-time scheduler. It can be either an integer value using microseconds as unit or a duration.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub cpu_rt_period: Option<StringOrNum>,

	/// Configures CPU allocation parameters for platforms with support for real-time scheduler. It can be either an integer value using microseconds as unit or a duration.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub cpu_rt_runtime: Option<StringOrNum>,

	/// The number of (potentially virtual) CPUs to allocate to service containers. This is a fractional number. 0.000 means no limit.
	///
	/// When set, cpus must be consistent with the cpus attribute in the Deploy Specification.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub cpus: Option<StringOrNum>,

	/// The explicit CPUs in which to permit execution. Can be a range 0-3 or a list 0,1
	#[serde(skip_serializing_if = "Option::is_none")]
	pub cpuset: Option<String>,

	/// Configures the credential spec for a managed service account.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#credential_spec
	#[serde(skip_serializing_if = "Option::is_none")]
	pub credential_spec: Option<CredentialSpec>,

	/// Specifies the configuration for the deployment and lifecycle of services, as defined in the [Compose Deploy Specification](https://docs.docker.com/reference/compose-file/deploy)
	#[serde(skip_serializing_if = "Option::is_none")]
	pub deploy: Option<Deploy>,

	/// Specifies the development configuration for maintaining a container in sync with source.
	///
	/// See more: https://docs.docker.com/reference/compose-file/develop
	#[serde(skip_serializing_if = "Option::is_none")]
	#[merge(with = merge_options)]
	pub develop: Option<DevelopmentSettings>,

	/// A list of device cgroup rules for this container. The format is the same format the Linux kernel specifies in the Control [Groups Device Whitelist Controller]().
	#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
	pub device_cgroup_rules: BTreeSet<String>,

	/// Defines a list of device mappings for created containers.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#devices
	#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
	pub devices: BTreeSet<DeviceMapping>,

	/// Custom DNS servers to set on the container network interface configuration. It can be a single value or a list.
	#[serde(default, skip_serializing_if = "StringOrSortedList::is_empty")]
	pub dns: StringOrSortedList,

	/// Custom DNS options to be passed to the container’s DNS resolver (/etc/resolv.conf file on Linux).
	#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
	pub dns_opt: BTreeSet<String>,

	/// Custom DNS search domains to set on container network interface configuration. It can be a single value or a list.
	#[serde(default, skip_serializing_if = "StringOrSortedList::is_empty")]
	pub dns_search: StringOrSortedList,

	/// A custom domain name to use for the service container. It must be a valid RFC 1123 hostname.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub domainname: Option<String>,

	/// Requires: Docker Compose 2.27.1 and later
	///
	/// Specifies a list of options as key-value pairs to pass to the driver. These options are driver-dependent.
	/// Consult the [network drivers documentation](https://docs.docker.com/engine/network/) for more information.
	#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
	pub driver_opts: BTreeMap<String, StringOrNum>,

	/// `external_links` link service containers to services managed outside of your Compose application. `external_links` define the name of an existing service to retrieve using the platform lookup mechanism.
	#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
	pub external_links: BTreeSet<String>,

	/// Adds hostname mappings to the container network interface configuration (/etc/hosts for Linux).
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#extra_hosts
	#[serde(skip_serializing_if = "Option::is_none")]
	#[merge(with = merge_options)]
	pub extra_hosts: Option<ExtraHosts>,

	/// Requires: Docker Compose 2.30.0 and later
	///
	/// Specifies GPU devices to be allocated for container usage.
	#[serde(skip_serializing_if = "Option::is_none")]
	#[merge(with = merge_options)]
	pub gpus: Option<Gpus>,

	/// Additional groups, by name or number, which the user inside the container must be a member of.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#group_add
	#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
	pub group_add: BTreeSet<StringOrNum>,

	/// Runs an init process (PID 1) inside the container that forwards signals and reaps processes. Set this option to true to enable this feature for the service.
	///
	/// The init binary that is used is platform specific.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub init: Option<bool>,

	/// ipc configures the IPC isolation mode set by the service container.
	///
	/// shareable: Gives the container its own private IPC namespace, with a possibility to share it with other containers.
	///
	/// service:{name}: Makes the container join another container's (shareable) IPC namespace.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#ipc
	#[serde(skip_serializing_if = "Option::is_none")]
	pub ipc: Option<String>,

	/// Container isolation technology to use. Supported values are platform-specific.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub isolation: Option<String>,

	/// Add metadata to containers. You can use either an array or a map.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#labels
	#[serde(default, skip_serializing_if = "ListOrMap::is_empty")]
	pub labels: ListOrMap,

	/// Requires: Docker Compose 2.32.2 and later
	///
	///The label_file attribute lets you load labels for a service from an external file or a list of files. This provides a convenient way to manage multiple labels without cluttering the Compose file.
	/// See more: https://docs.docker.com/reference/compose-file/services/#label_file
	#[serde(default, skip_serializing_if = "StringOrSortedList::is_empty")]
	pub label_file: StringOrSortedList,

	/// Defines a network link to containers in another service. Either specify both the service name and a link alias (SERVICE:ALIAS), or just the service name.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#links
	#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
	pub links: BTreeSet<String>,

	/// Defines the logging configuration for the service.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#logging
	#[serde(skip_serializing_if = "Option::is_none")]
	pub logging: Option<LoggingSettings>,

	/// Sets a Mac address for the service container.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#mac_address
	#[serde(skip_serializing_if = "Option::is_none")]
	pub mac_address: Option<String>,

	/// Memory limit for the container. A string value can use suffix like '2g' for 2 gigabytes.
	///
	/// When set, mem_limit must be consistent with the limits.memory attribute in the [Deploy Specification](https://docs.docker.com/reference/compose-file/deploy/#memory).
	#[serde(skip_serializing_if = "Option::is_none")]
	pub mem_limit: Option<StringOrNum>,

	/// Configures a reservation on the amount of memory a container can allocate, set as a string expressing a [byte value](https://docs.docker.com/reference/compose-file/extension/#specifying-byte-values).
	///
	/// When set, mem_reservation must be consistent with the reservations.memory attribute in the [Deploy Specification](https://docs.docker.com/reference/compose-file/deploy/#memory).
	#[serde(skip_serializing_if = "Option::is_none")]
	pub mem_reservation: Option<StringOrNum>,

	/// Defines as a percentage, a value between 0 and 100, for the host kernel to swap out anonymous memory pages used by a container.
	///
	///  0: Turns off anonymous page swapping.
	/// 100: Sets all anonymous pages as swappable.
	///
	/// The default value is platform specific.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub mem_swappiness: Option<u8>,

	/// Defines the amount of memory the container is allowed to swap to disk.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#memswap_limit
	#[serde(skip_serializing_if = "Option::is_none")]
	pub memswap_limit: Option<StringOrNum>,

	/// Requires: Docker Compose 2.38.0 and later
	///
	/// Defines which AI models the service should use at runtime. Each referenced model must be defined under the [`models` top-level element](https://docs.docker.com/reference/compose-file/models/).
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#models
	#[serde(skip_serializing_if = "Option::is_none")]
	#[merge(with = merge_options)]
	pub models: Option<ServiceModels>,

	/// Sets a service container's network mode.
	///
	/// none: Turns off all container networking.
	/// host: Gives the container raw access to the host's network interface.
	/// service:{name}: Gives the container access to the specified container by referring to its service name.
	/// container:{name}: Gives the container access to the specified container by referring to its container ID.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#network_mode
	#[serde(skip_serializing_if = "Option::is_none")]
	pub network_mode: Option<NetworkMode>,

	/// The networks attribute defines the networks that service containers are attached to, referencing entries under the networks top-level element.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#networks
	#[serde(skip_serializing_if = "Option::is_none")]
	#[merge(with = merge_options)]
	pub networks: Option<ServiceNetworks>,

	/// If `oom_kill_disable` is set, Compose configures the platform so it won't kill the container in case of memory starvation.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub oom_kill_disable: Option<bool>,

	/// Tunes the preference for containers to be killed by platform in case of memory starvation. Value must be within -1000,1000 range.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub oom_score_adj: Option<i32>,

	/// Sets the PID mode for container created by Compose. Supported values are platform specific.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub pid: Option<String>,

	/// Tune a container's PIDs limit. Set to -1 for unlimited PIDs.
	///
	/// When set, pids_limit must be consistent with the pids attribute in the [Deploy Specification](https://docs.docker.com/reference/compose-file/deploy/#pids).
	#[serde(skip_serializing_if = "Option::is_none")]
	pub pids_limit: Option<i64>,

	/// The target platform the containers for the service run on. It uses the os[/arch[/variant]] syntax.
	///
	/// The values of os, arch, and variant must conform to the convention used by the OCI Image Spec.
	///
	/// Compose uses this attribute to determine which version of the image is pulled and/or on which platform the service’s build is performed.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub platform: Option<String>,

	/// Used to define the port mappings between the host machine and the containers.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#ports
	#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
	pub ports: BTreeSet<Port>,

	/// Requires: Docker Compose 2.30.0 and later
	///
	///Defines a sequence of lifecycle hooks to run after a container has started. The exact timing of when the command is run is not guaranteed.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#post_start
	#[serde(default, skip_serializing_if = "Vec::is_empty")]
	pub post_start: Vec<ServiceHook>,

	/// Defines a sequence of lifecycle hooks to run before the container is stopped. These hooks won't run if the container stops by itself or is terminated suddenly.
	#[serde(default, skip_serializing_if = "Vec::is_empty")]
	pub pre_stop: Vec<ServiceHook>,

	/// Configures the service container to run with elevated privileges. Support and actual impacts are platform specific.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub privileged: Option<bool>,

	/// Defines a list of named profiles for the service to be enabled under. If unassigned, the service is always started but if assigned, it is only started if the profile is activated.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#profiles
	#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
	pub profiles: BTreeSet<String>,

	/// Defines a service that Compose won't manage directly. Compose delegated the service lifecycle to a dedicated or third-party component.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#provider
	#[serde(skip_serializing_if = "Option::is_none")]
	pub provider: Option<Provider>,

	/// Defines the decisions Compose makes when it starts to pull images.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#pull_policy
	#[serde(skip_serializing_if = "Option::is_none")]
	pub pull_policy: Option<PullPolicy>,

	/// Time after which to refresh the image. Used with pull_policy=refresh.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub pull_refresh_after: Option<String>,

	/// Configures the service container to be created with a read-only filesystem.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub read_only: Option<bool>,

	/// Defines the policy that the platform applies on container termination.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#restart
	#[serde(skip_serializing_if = "Option::is_none")]
	pub restart: Option<Restart>,

	/// Specifies which runtime to use for the service’s containers.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#runtime
	#[serde(skip_serializing_if = "Option::is_none")]
	pub runtime: Option<String>,

	/// Specifies the default number of containers to deploy for this service. When both are set, scale must be consistent with the replicas attribute in the [Deploy Specification](https://docs.docker.com/reference/compose-file/deploy/#replicas).
	#[serde(skip_serializing_if = "Option::is_none")]
	pub scale: Option<u64>,

	/// The secrets attribute grants access to sensitive data defined by the secrets top-level element on a per-service basis. Services can be granted access to multiple secrets.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#secrets
	#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
	pub secrets: BTreeSet<ServiceConfigOrSecret>,

	/// Overrides the default labeling scheme for each container.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#security_opt
	#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
	pub security_opt: BTreeSet<String>,

	/// Size of /dev/shm. A string value can use suffix like '2g' for 2 gigabytes.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub shm_size: Option<StringOrNum>,

	/// Configures a service's container to run with an allocated stdin. This is the same as running a container with the -i flag. For more information, see [Keep stdin open](https://docs.docker.com/reference/cli/docker/container/run/#interactive).
	#[serde(skip_serializing_if = "Option::is_none")]
	pub stdin_open: Option<bool>,

	/// Specifies how long Compose must wait when attempting to stop a container if it doesn't handle SIGTERM (or whichever stop signal has been specified with stop_signal), before sending SIGKILL. It's specified as a duration.
	///
	/// Default value is 10 seconds for the container to exit before sending SIGKILL.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub stop_grace_period: Option<String>,

	/// The signal that Compose uses to stop the service containers. If unset containers are stopped by Compose by sending SIGTERM.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub stop_signal: Option<String>,

	/// Defines storage driver options for a service.
	#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
	pub storage_opt: BTreeMap<String, Value>,

	/// Defines kernel parameters to set in the container. sysctls can use either an array or a map.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#sysctls
	#[serde(default, skip_serializing_if = "ListOrMap::is_empty")]
	pub sysctls: ListOrMap,

	/// Mounts a temporary file system inside the container. It can be a single value or a list.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#tmpfs
	#[serde(skip_serializing_if = "Option::is_none")]
	pub tmpfs: Option<StringOrList>,

	/// Configures a service's container to run with a TTY. This is the same as running a container with the -t or --tty flag. For more information, see [Allocate a pseudo-TTY](https://docs.docker.com/reference/cli/docker/container/run/#tty).
	#[serde(skip_serializing_if = "Option::is_none")]
	pub tty: Option<bool>,

	/// Overrides the default ulimits for a container. It's specified either as an integer for a single limit or as mapping for soft/hard limits.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#ulimits
	#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
	pub ulimits: BTreeMap<String, Ulimit>,

	/// When `use_api_socket` is set, the container is able to interact with the underlying container engine through the API socket. Your credentials are mounted inside the container so the container acts as a pure delegate for your commands relating to the container engine. Typically, commands ran by container can pull and push to your registry.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub use_api_socket: Option<bool>,

	/// Overrides the user used to run the container process. The default is set by the image, for example Dockerfile USER. If it's not set, then root.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub user: Option<String>,

	/// Sets the user namespace for the service. Supported values are platform specific and may depend on platform configuration.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub userns_mode: Option<String>,

	/// /// Configures the UTS namespace mode set for the service container. When unspecified it is the runtime's decision to assign a UTS namespace, if supported.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub uts: Option<Uts>,

	/// The volumes attribute define mount host paths or named volumes that are accessible by service containers.
	///
	/// See more: https://docs.docker.com/reference/compose-file/services/#volumes
	#[serde(default, skip_serializing_if = "Vec::is_empty")]
	pub volumes: Vec<ServiceVolume>,

	/// Mounts all of the volumes from another service or container. You can optionally specify read-only access ro or read-write rw. If no access level is specified, then read-write access is used.
	///
	/// You can also mount volumes from a container that is not managed by Compose by using the container: prefix.
	#[serde(default, skip_serializing_if = "Vec::is_empty")]
	pub volumes_from: Vec<String>,

	/// Overrides the container's working directory which is specified by the image, for example Dockerfile's WORKDIR.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub working_dir: Option<String>,
}

/// `extends` lets you share common configurations among different files, or even different projects entirely.
///
/// See more: https://docs.docker.com/reference/compose-file/services/#extends
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(untagged)]
pub enum Extends {
	/// The name of the service to extend.
	Simple(String),
	Detailed {
		/// The name of the service to extend.
		service: String,

		/// The file path where the service to extend is defined.
		#[serde(default)]
		file: Option<String>,
	},
}

/// Requires: Docker Compose 2.30.0 and later
///
/// Specifies GPU devices to be allocated for container usage.
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub enum Gpus {
	/// Use all available GPUs.
	#[serde(rename = "all")]
	All,
	/// List of specific GPU devices to use.
	#[serde(untagged)]
	List(BTreeSet<GpuSettings>),
}

impl Merge for Gpus {
	fn merge(&mut self, other: Self) {
		match self {
			Self::All => {}
			Self::List(left_gpus) => match other {
				Self::All => *self = Self::All,
				Self::List(right_gpus) => left_gpus.extend(right_gpus),
			},
		}
	}
}

/// Requires: Docker Compose 2.30.0 and later
///
/// Specifies GPU devices to be allocated for container usage.
#[derive(Clone, Debug, Serialize, Default, Deserialize, PartialEq, Eq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(default)]
#[serde(deny_unknown_fields)]
pub struct GpuSettings {
	/// List of capabilities the GPU needs to have (e.g., 'compute', 'utility').
	#[serde(skip_serializing_if = "Option::is_none")]
	pub capabilities: Option<BTreeSet<String>>,

	// Number of GPUs to use.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub count: Option<usize>,

	/// List of specific GPU device IDs to use.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub device_ids: Option<BTreeSet<String>>,

	/// GPU driver to use (e.g., 'nvidia').
	#[serde(skip_serializing_if = "Option::is_none")]
	pub driver: Option<String>,

	/// Driver-specific options for the GPU.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub options: Option<ListOrMap>,
}

impl PartialOrd for GpuSettings {
	fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
		Some(self.cmp(other))
	}
}

impl Ord for GpuSettings {
	fn cmp(&self, other: &Self) -> Ordering {
		self.driver
			.cmp(&other.driver)
			.then_with(|| self.count.cmp(&other.count))
	}
}

/// Requires: Docker Compose 2.38.0 and later
///
/// Defines which AI models the service should use at runtime. Each referenced model must be defined under the [`models` top-level element](https://docs.docker.com/reference/compose-file/models/).
///
/// See more: https://docs.docker.com/reference/compose-file/services/#models
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(untagged)]
pub enum ServiceModels {
	List(BTreeSet<String>),
	Map(BTreeMap<String, ServiceModelSettings>),
}

impl Merge for ServiceModels {
	fn merge(&mut self, other: Self) {
		if let Self::List(left_list) = self
			&& let Self::List(right_list) = other
		{
			left_list.extend(right_list);
		} else if let Self::Map(left_list) = self
			&& let Self::Map(right_list) = other
		{
			left_list.extend(right_list);
		} else {
			*self = other;
		}
	}
}

#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Default)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(default)]
#[serde(deny_unknown_fields)]
pub struct ServiceModelSettings {
	/// Environment variable set to AI model name.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub model_var: Option<String>,

	/// Environment variable set to AI model endpoint.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub endpoint_var: Option<String>,
}

impl PartialOrd for ServiceModelSettings {
	fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
		Some(self.cmp(other))
	}
}

impl Ord for ServiceModelSettings {
	fn cmp(&self, other: &Self) -> Ordering {
		self.model_var.cmp(&other.model_var)
	}
}

/// Sets a service container's network mode.
///
///
/// See more: https://docs.docker.com/reference/compose-file/services/#network_mode
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub enum NetworkMode {
	Bridge,
	/// Gives the container raw access to the host's network interface.
	Host,
	/// Turns off all container networking.
	None,
	#[serde(untagged)]
	Other(String),
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(untagged)]
pub enum ServiceNetworks {
	List(BTreeSet<String>),
	Map(BTreeMap<String, ServiceNetworkSettings>),
}

impl ServiceNetworks {
	pub fn contains(&self, key: &str) -> bool {
		match self {
			Self::List(list) => list.contains(key),
			Self::Map(map) => map.contains_key(key),
		}
	}
}

impl Merge for ServiceNetworks {
	fn merge(&mut self, other: Self) {
		if let Self::List(left_list) = self
			&& let Self::List(right_list) = other
		{
			left_list.extend(right_list);
		} else if let Self::Map(left_list) = self
			&& let Self::Map(right_list) = other
		{
			left_list.extend(right_list);
		} else {
			*self = other;
		}
	}
}

/// The networks attribute defines the networks that service containers are attached to, referencing entries under the networks top-level element.
///
/// See more: https://docs.docker.com/reference/compose-file/services/#networks
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Default)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(default)]
#[serde(deny_unknown_fields)]
pub struct ServiceNetworkSettings {
	/// Interface network name used to connect to network
	#[serde(skip_serializing_if = "Option::is_none")]
	pub interface_name: Option<String>,

	/// Alternative hostnames for this service on the network.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub aliases: Option<BTreeSet<String>>,

	/// Specify a static IPv4 address for this service on this network.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub ipv4_address: Option<String>,

	/// Specify a static IPv6 address for this service on this network.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub ipv6_address: Option<String>,

	/// Specify a MAC address for this service on this network.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub mac_address: Option<String>,

	/// Specify the priority for the network connection.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub priority: Option<i64>,

	/// Specify the gateway priority for the network connection.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub gw_priority: Option<i64>,

	/// List of link-local IPs.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub link_local_ips: Option<BTreeSet<String>>,

	/// Driver options for this network.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub driver_opts: Option<BTreeMap<String, SingleValue>>,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(untagged)]
pub enum ProviderOptions {
	Single(SingleValue),
	List(Vec<SingleValue>),
}

/// Defines a service that Compose won't manage directly. Compose delegated the service lifecycle to a dedicated or third-party component.
///
/// See more: https://docs.docker.com/reference/compose-file/services/#provider
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub struct Provider {
	/// External component used by Compose to manage setup and teardown lifecycle of the service.
	#[serde(rename = "type")]
	pub type_: String,

	/// Provider-specific options.
	#[serde(skip_serializing_if = "Option::is_none")]
	#[serde(default)]
	pub options: Option<BTreeMap<String, ProviderOptions>>,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(rename_all = "kebab-case")]
pub enum Restart {
	Always,
	No,
	OnFailure,
	UnlessStopped,
	#[serde(untagged)]
	Other(String),
}

#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(untagged)]
pub enum BuildStep {
	/// Path to the build context. Can be a relative path or a URL.
	Simple(String),
	/// Configuration options for building the service's image.
	Advanced(Box<AdvancedBuildStep>),
}

impl Merge for BuildStep {
	fn merge(&mut self, other: Self) {
		if let Self::Advanced(left_data) = self
			&& let Self::Advanced(right_data) = other
		{
			left_data.merge(right_data);
		} else {
			*self = other;
		}
	}
}

/// Specifies the build configuration for creating a container image from source, as defined in the [Compose Build Specification](https://docs.docker.com/reference/compose-file/build/).
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq, Default, Merge)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(deny_unknown_fields)]
#[serde(default)]
pub struct AdvancedBuildStep {
	/// Defines either a path to a directory containing a Dockerfile, or a URL to a Git repository.
	///
	/// When the value supplied is a relative path, it is interpreted as relative to the project directory. Compose warns you about the absolute path used to define the build context as those prevent the Compose file from being portable.
	///
	/// See more: https://docs.docker.com/reference/compose-file/build/#context
	#[serde(skip_serializing_if = "Option::is_none")]
	pub context: Option<String>,

	/// Requires: Docker Compose 2.17.0 and later
	///
	/// Defines a list of named contexts the image builder should use during image build. Can be a mapping or a list.
	/// See more: https://docs.docker.com/reference/compose-file/build/#additional_contexts
	#[serde(default, skip_serializing_if = "ListOrMap::is_empty")]
	pub additional_contexts: ListOrMap,

	/// Sets an alternate Dockerfile. A relative path is resolved from the build context. Compose warns you about the absolute path used to define the Dockerfile as it prevents Compose files from being portable.
	///
	/// When set, dockerfile_inline attribute is not allowed and Compose rejects any Compose file having both set.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub dockerfile: Option<String>,

	/// Requires: Docker Compose 2.17.0 and later
	///
	/// dockerfile_inline defines the Dockerfile content as an inlined string in a Compose file. When set, the dockerfile attribute is not allowed and Compose rejects any Compose file having both set.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub dockerfile_inline: Option<String>,

	/// Define build arguments, that is Dockerfile ARG values.
	///
	/// Cache location syntax follows the global format [NAME|type=TYPE[,KEY=VALUE]]. Simple NAME is actually a shortcut notation for type=registry,ref=NAME.
	///
	/// See more: https://docs.docker.com/reference/compose-file/build/#args
	#[serde(skip_serializing_if = "Option::is_none")]
	pub args: Option<ListOrMap>,

	/// Defines a list of sources the image builder should use for cache resolution.
	///
	/// See more: https://docs.docker.com/reference/compose-file/build/#cache_from
	#[serde(default, skip_serializing_if = "Vec::is_empty")]
	pub cache_from: Vec<String>,

	/// Defines a list of export locations to be used to share build cache with future builds.
	///
	/// Cache location syntax follows the global format [NAME|type=TYPE[,KEY=VALUE]]. Simple NAME is actually a shortcut notation for type=registry,ref=NAME.
	///
	/// See more: https://docs.docker.com/reference/compose-file/build/#cache_to
	#[serde(default, skip_serializing_if = "Vec::is_empty")]
	pub cache_to: Vec<String>,

	/// Requires: Docker Compose 2.27.1 and later
	///
	/// Defines extra privileged entitlements to be allowed during the build.
	#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
	pub entitlements: BTreeSet<String>,

	/// Adds hostname mappings at build-time. Use the same syntax as [extra_hosts](https://docs.docker.com/reference/compose-file/services/#extra_hosts).
	#[serde(skip_serializing_if = "Option::is_none")]
	#[merge(with = merge_options)]
	pub extra_hosts: Option<ExtraHosts>,

	/// Specifies a build’s container isolation technology. Supported values are platform specific.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub isolation: Option<String>,

	/// Add metadata to the resulting image. Can be set either as an array or a map.
	///
	/// It's recommended that you use reverse-DNS notation to prevent your labels from conflicting with other software.
	#[serde(default, skip_serializing_if = "ListOrMap::is_empty")]
	pub labels: ListOrMap,

	/// Network mode to use for the build. Options include 'default', 'none', 'host', or a network name.
	///
	/// See more: https://docs.docker.com/reference/compose-file/build/#network
	#[serde(skip_serializing_if = "Option::is_none")]
	pub network: Option<String>,

	/// Disables image builder cache and enforces a full rebuild from source for all image layers. This only applies to layers declared in the Dockerfile, referenced images can be retrieved from local image store whenever tag has been updated on registry (see [pull](https://docs.docker.com/reference/compose-file/build/#pull)).
	#[serde(skip_serializing_if = "Option::is_none")]
	pub no_cache: Option<bool>,

	/// Defines a list of target [platforms](https://docs.docker.com/reference/compose-file/services/#platform).
	///
	/// See more: https://docs.docker.com/reference/compose-file/build/#platforms
	#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
	pub platforms: BTreeSet<String>,

	/// Requires: Docker Compose 2.15.0 and later
	///
	/// Configures the service image to build with elevated privileges. Support and actual impacts are platform specific.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub privileged: Option<bool>,

	/// Requires: Docker Compose 2.39.0 and later
	///
	/// Configures the builder to add a provenance attestation to the published image.
	///
	/// The value can be either a boolean to enable/disable provenance attestation, or a key=value string to set provenance configuration. You can use this to select the level of detail to be included in the provenance attestation by setting the mode parameter.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub provenance: Option<bool>,

	/// Requires the image builder to pull referenced images (FROM Dockerfile directive), even if those are already available in the local image store.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub pull: Option<bool>,

	/// Requires: Docker Compose 2.39.0 and later
	///
	/// Configures the builder to add a provenance attestation to the published image.
	///
	/// See more: https://docs.docker.com/reference/compose-file/build/#sbom
	#[serde(skip_serializing_if = "Option::is_none")]
	pub sbom: Option<bool>,

	/// Grants access to sensitive data defined by secrets on a per-service build basis.
	///
	/// See more: https://docs.docker.com/reference/compose-file/build/#secrets
	#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
	pub secrets: BTreeSet<ServiceConfigOrSecret>,

	/// SSH agent socket or keys to expose to the build. Format is either a string or a list of 'default|<id>[=<socket>|<key>[,<key>]]'.
	///
	/// See more: https://docs.docker.com/reference/compose-file/build/#ssh
	#[serde(default, skip_serializing_if = "ListOrMap::is_empty")]
	pub ssh: ListOrMap,

	/// Size of /dev/shm for the build container. A string value can use suffix like '2g' for 2 gigabytes.
	///
	/// See more: https://docs.docker.com/reference/compose-file/build/#shm_size
	#[serde(skip_serializing_if = "Option::is_none")]
	pub shm_size: Option<StringOrNum>,

	/// Defines a list of tag mappings that must be associated to the build image. This list comes in addition to the image property defined in the service section.
	#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
	pub tags: BTreeSet<String>,

	/// Defines the stage to build as defined inside a multi-stage Dockerfile.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub target: Option<String>,

	/// Requires: Docker Compose 2.23.1 and later
	///
	/// ulimits overrides the default ulimits for a container. It's specified either as an integer for a single limit or as mapping for soft/hard limits.
	///
	/// See more: https://docs.docker.com/reference/compose-file/build/#ulimits
	#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
	pub ulimits: BTreeMap<String, Ulimit>,
}

/// Configures the UTS namespace mode set for the service container. When unspecified it is the runtime's decision to assign a UTS namespace, if supported.
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(rename = "kebab-case")]
pub enum Uts {
	/// Results in the container using the same UTS namespace as the host.
	Host,
}

/// With the depends_on attribute, you can control the order of service startup and shutdown.
///
/// It is useful if services are closely coupled, and the startup sequence impacts the application's functionality.
///
/// See more: https://docs.docker.com/reference/compose-file/services/#depends_on
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(untagged)]
pub enum DependsOn {
	Simple(Vec<String>),

	Conditional(IndexMap<String, DependsOnSettings>),
}

impl Merge for DependsOn {
	fn merge(&mut self, other: Self) {
		if let Self::Simple(left_list) = self
			&& let Self::Simple(right_list) = other
		{
			left_list.extend(right_list);
		} else if let Self::Conditional(left_list) = self
			&& let Self::Conditional(right_list) = other
		{
			left_list.extend(right_list);
		} else {
			*self = other;
		}
	}
}

impl Default for DependsOn {
	fn default() -> Self {
		Self::Simple(Default::default())
	}
}

impl DependsOn {
	pub fn is_empty(&self) -> bool {
		match self {
			Self::Simple(v) => v.is_empty(),
			Self::Conditional(m) => m.is_empty(),
		}
	}
}

#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(rename_all = "snake_case")]
pub enum DependsOnCondition {
	/// Waits until the service has completed successfully.
	ServiceCompletedSuccessfully,
	/// Waits until the service is healthy (as defined by its healthcheck).
	ServiceHealthy,
	/// Waits until the service has started.
	ServiceStarted,
}

/// With the depends_on attribute, you can control the order of service startup and shutdow```
///
/// It is useful if services are closely coupled, and the startup sequence impacts the application's functionality.
///
/// See more: https://docs.docker.com/reference/compose-file/services/#depends_on
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(deny_unknown_fields)]
pub struct DependsOnSettings {
	/// Condition to wait for.
	pub condition: DependsOnCondition,

	/// Whether to restart dependent services when this service is restarted.
	#[serde(skip_serializing_if = "Option::is_none")]
	#[serde(default)]
	pub restart: Option<bool>,

	/// Whether the dependency is required for the dependent service to start. (default: true)
	#[serde(skip_serializing_if = "Option::is_none")]
	#[serde(default)]
	pub required: Option<bool>,
}

/// Defines the logging configuration.
///
/// See more: https://docs.docker.com/engine/logging/configure/
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(default)]
#[serde(deny_unknown_fields)]
pub struct LoggingSettings {
	/// Logging driver to use, such as 'json-file', 'syslog', 'journald', etc.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub driver: Option<LoggingDriver>,

	/// Options for the logging driver.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub options: Option<BTreeMap<String, Option<StringOrNum>>>,
}

/// A logging driver for Docker.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(rename_all = "kebab-case")]
pub enum LoggingDriver {
	/// Logs are stored in a custom format designed for minimal overhead.
	Local,
	/// The logs are formatted as JSON. The default logging driver for Docker.
	JsonFile,
	/// Writes logging messages to the syslog facility. The syslog daemon must be running on the host machine.
	Syslog,
	/// Writes log messages to journald. The journald daemon must be running on the host machine.
	Journald,
	/// Writes log messages to a Graylog Extended Log Format (GELF) endpoint such as Graylog or Logstash.
	Gelf,
	/// Writes log messages to fluentd (forward input). The fluentd daemon must be running on the host machine.
	Fluentd,
	/// Writes log messages to Amazon CloudWatch Logs.
	Awslogs,
	/// Writes log messages to splunk using the HTTP Event Collector.
	Splunk,
	/// Writes log messages as Event Tracing for Windows (ETW) events. Only available on Windows platforms.
	Etwlogs,
	/// Writes log messages to Google Cloud Platform (GCP) Logging.
	Gcplogs,
}

/// Declares a check that's run to determine whether or not the service containers are "healthy".
///
/// See more: https://docs.docker.com/reference/compose-file/services/#healthcheck
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Default)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(deny_unknown_fields)]
#[serde(default)]
pub struct Healthcheck {
	/// Disable any container-specified healthcheck. Set to true to disable.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub disable: Option<bool>,

	/// The test to perform to check container health. Can be a string or a list. The first item is either NONE, CMD, or CMD-SHELL. If it's CMD, the rest of the command is exec'd. If it's CMD-SHELL, the rest is run in the shell.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub test: Option<StringOrList>,

	/// Time between running the check (e.g., '1s', '1m30s'). Default: 30s.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub interval: Option<String>,

	/// Start period for the container to initialize before starting health-retries countdown (e.g., '1s', '1m30s'). Default: 0s.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub start_period: Option<String>,

	/// Time between running the check during the start period (e.g., '1s', '1m30s'). Default: interval value.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub start_interval: Option<String>,

	/// Number of consecutive failures needed to consider the container as unhealthy. Default: 3.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub retries: Option<StringOrNum>,

	/// Maximum time to allow one check to run (e.g., '1s', '1m30s'). Default: 30s.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub timeout: Option<String>,
}

/// Defines an environment file(s) to use to define default values when interpolating variables in the Compose file being parsed.
///
/// It defaults to .env file in the project_directory for the Compose file being parsed.
///
/// See more: https://docs.docker.com/reference/compose-file/include/#env_file
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(untagged)]
pub enum Envfile {
	/// Path to a file containing environment variables.
	Simple(String),
	List(Vec<EnvfileFormat>),
}

impl Merge for Envfile {
	fn merge(&mut self, other: Self) {
		match self {
			Self::Simple(_) => {
				*self = other;
			}
			Self::List(list) => match other {
				Self::Simple(file) => list.push(EnvfileFormat::Simple(file)),
				Self::List(files) => list.extend(files),
			},
		}
	}
}

/// Defines an environment file(s) to use to define default values when interpolating variables in the Compose file being parsed.
///
/// It defaults to .env file in the project_directory for the Compose file being parsed.
///
/// See more: https://docs.docker.com/reference/compose-file/include/#env_file
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(untagged)]
pub enum EnvfileFormat {
	/// Path to a file containing environment variables.
	Simple(String),
	/// Detailed configuration for an environment file.
	Detailed(EnvFileDetailed),
}

/// Detailed configuration for an environment file.
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(deny_unknown_fields)]
pub struct EnvFileDetailed {
	/// Path to the environment file.
	pub path: String,

	/// Format attribute lets you to use an alternative file formats for env_file. When not set, env_file is parsed according to Compose rules.
	#[serde(skip_serializing_if = "Option::is_none")]
	#[serde(default)]
	pub format: Option<String>,

	/// Whether the file is required. If true and the file doesn't exist, an error will be raised. (default: true)
	#[serde(skip_serializing_if = "Option::is_none")]
	#[serde(default)]
	pub required: Option<bool>,
}

/// Defines a set of configuration options to set block I/O limits for a service.
///
/// See more: https://docs.docker.com/reference/compose-file/services/#blkio_config
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(default)]
#[serde(deny_unknown_fields)]
pub struct BlkioSettings {
	/// Limit read rate (bytes per second) from a device.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub device_read_bps: Option<BTreeSet<BlkioLimit>>,

	/// Limit read rate (IO per second) from a device.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub device_read_iops: Option<BTreeSet<BlkioLimit>>,

	/// Limit write rate (bytes per second) to a device.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub device_write_bps: Option<BTreeSet<BlkioLimit>>,

	/// Limit write rate (IO per second) to a device.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub device_write_iops: Option<BTreeSet<BlkioLimit>>,

	/// Block IO weight (relative weight) for the service, between 10 and 1000.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub weight: Option<StringOrNum>,

	/// Block IO weight (relative weight) for specific devices.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub weight_device: Option<BTreeSet<BlkioWeight>>,
}

/// Block IO limit for a specific device.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Default, Eq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(default)]
#[serde(deny_unknown_fields)]
pub struct BlkioLimit {
	/// Path to the device (e.g., '/dev/sda').
	#[serde(skip_serializing_if = "Option::is_none")]
	pub path: Option<String>,

	/// Rate limit in bytes per second or IO operations per second.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub rate: Option<StringOrNum>,
}

impl PartialOrd for BlkioLimit {
	fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
		Some(self.cmp(other))
	}
}

impl Ord for BlkioLimit {
	fn cmp(&self, other: &Self) -> Ordering {
		self.path
			.cmp(&other.path)
			.then_with(|| self.rate.cmp(&other.rate))
	}
}

/// Block IO weight for a specific device.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Default, Eq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(default)]
#[serde(deny_unknown_fields)]
pub struct BlkioWeight {
	/// Path to the device (e.g., '/dev/sda').
	#[serde(skip_serializing_if = "Option::is_none")]
	pub path: Option<String>,

	/// Relative weight for the device, between 10 and 1000.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub weight: Option<StringOrNum>,
}

impl PartialOrd for BlkioWeight {
	fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
		Some(self.cmp(other))
	}
}

impl Ord for BlkioWeight {
	fn cmp(&self, other: &Self) -> Ordering {
		self.path
			.cmp(&other.path)
			.then_with(|| self.weight.cmp(&other.weight))
	}
}

/// Specify the cgroup namespace to join. Use 'host' to use the host's cgroup namespace, or 'private' to use a private cgroup namespace.
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(rename_all = "kebab-case")]
pub enum Cgroup {
	/// Use the host's cgroup namespace.
	Host,

	/// Use a private cgroup namespace.
	Private,
}

/// Configures the credential spec for a managed service account.
///
/// See more: https://docs.docker.com/reference/compose-file/services/#credential_spec
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Default, Eq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(default)]
#[serde(deny_unknown_fields)]
pub struct CredentialSpec {
	/// The name of the credential spec Config to use.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub config: Option<String>,

	/// Path to a credential spec file.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub file: Option<String>,

	/// Path to a credential spec in the Windows registry.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub registry: Option<String>,
}

/// Specifies the development configuration for maintaining a container in sync with source.
///
/// See more: https://docs.docker.com/reference/compose-file/develop
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Default, Eq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(deny_unknown_fields)]
pub struct DevelopmentSettings {
	/// The watch attribute defines a list of rules that control automatic service updates based on local file changes. watch is a sequence, each individual item in the sequence defines a rule to be applied by Compose to monitor source code for changes.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub watch: Option<BTreeSet<WatchItem>>,
}

impl Merge for DevelopmentSettings {
	fn merge(&mut self, other: Self) {
		merge_options(&mut self.watch, other.watch);
	}
}

/// An element of the watch mode configuration.
///
/// See more: https://docs.docker.com/reference/compose-file/develop/#watch
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(deny_unknown_fields)]
pub struct WatchItem {
	/// Action to take when a change is detected.
	///
	/// See more: https://docs.docker.com/reference/compose-file/develop/#action
	pub action: WatchAction,

	/// Requires: Docker Compose 2.32.2 and later
	///
	/// Only relevant when action is set to sync+exec. Like service hooks, exec is used to define the command to be run inside the container once it has started.
	///
	/// See more: https://docs.docker.com/reference/compose-file/develop/#exec
	#[serde(skip_serializing_if = "Option::is_none")]
	#[serde(default)]
	pub exec: Option<ServiceHook>,

	/// Patterns to exclude from watching.
	///
	/// See more: https://docs.docker.com/reference/compose-file/develop/#ignore
	#[serde(skip_serializing_if = "Option::is_none")]
	#[serde(default)]
	pub ignore: Option<BTreeSet<String>>,

	/// It is sometimes easier to select files to be watched instead of declaring those that shouldn't be watched with ignore.
	///
	/// See more: https://docs.docker.com/reference/compose-file/develop/#include
	#[serde(skip_serializing_if = "Option::is_none")]
	#[serde(default)]
	pub include: Option<BTreeSet<String>>,

	/// Defines the path to source code (relative to the project directory) to monitor for changes. Updates to any file inside the path, which doesn't match any ignore rule, triggers the configured action.
	pub path: String,

	/// Only applies when action is configured for sync. Files within path that have changes are synchronized with the container's filesystem, so that the latter is always running with up-to-date content.
	#[serde(skip_serializing_if = "Option::is_none")]
	#[serde(default)]
	pub target: Option<String>,
}

impl PartialOrd for WatchItem {
	fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
		Some(self.cmp(other))
	}
}

impl Ord for WatchItem {
	fn cmp(&self, other: &Self) -> Ordering {
		self.action.cmp(&other.action)
	}
}

/// Action to take when a change is detected.
///
/// See more: https://docs.docker.com/reference/compose-file/develop/#action
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(rename_all = "kebab-case")]
pub enum WatchAction {
	Rebuild,
	Restart,
	Sync,
	#[serde(rename = "sync+restart")]
	SyncRestart,
	#[serde(rename = "sync+exec")]
	SyncExec,
}

/// Configuration for service lifecycle hooks, which are commands executed at specific points in a container's lifecycle.
///
/// See more: https://docs.docker.com/compose/how-tos/lifecycle/
#[derive(Clone, Debug, Serialize, Default, Deserialize, PartialEq, Eq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(default)]
#[serde(deny_unknown_fields)]
pub struct ServiceHook {
	/// Whether to run the command with extended privileges.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub privileged: Option<bool>,

	/// User to run the command as.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub user: Option<String>,

	/// Working directory for the command.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub working_dir: Option<String>,

	/// Environment variables for the command.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub environment: Option<ListOrMap>,

	/// Command to execute as part of the hook.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub command: Option<StringOrList>,
}

/// A device mapping for a container.
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(untagged)]
pub enum DeviceMapping {
	String(String),
	Detailed(DeviceMappingSettings),
}

/// A device mapping for a container.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(deny_unknown_fields)]
pub struct DeviceMappingSettings {
	/// Path on the host to the device.
	pub source: String,

	/// Path in the container where the device will be mapped.
	#[serde(skip_serializing_if = "Option::is_none")]
	#[serde(default)]
	pub target: Option<String>,

	/// Cgroup permissions for the device (rwm).
	#[serde(skip_serializing_if = "Option::is_none")]
	#[serde(default)]
	pub permissions: Option<String>,
}

impl PartialOrd for DeviceMappingSettings {
	fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
		Some(self.cmp(other))
	}
}

impl Ord for DeviceMappingSettings {
	fn cmp(&self, other: &Self) -> Ordering {
		self.source.cmp(&other.source)
	}
}

#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(untagged)]
pub enum ServiceVolume {
	Simple(String),
	Advanced(ServiceVolumeSettings),
}

impl PartialOrd for ServiceVolume {
	fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
		Some(self.cmp(other))
	}
}

impl Ord for ServiceVolume {
	fn cmp(&self, other: &Self) -> std::cmp::Ordering {
		match self {
			Self::Simple(s) => match other {
				Self::Simple(other_s) => s.cmp(other_s),
				Self::Advanced(_) => Ordering::Greater,
			},
			Self::Advanced(v) => match other {
				Self::Simple(_) => Ordering::Less,
				Self::Advanced(other_v) => v.type_.cmp(&other_v.type_),
			},
		}
	}
}

/// The mount type.
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(rename_all = "lowercase")]
pub enum VolumeType {
	/// For mounting host directories.
	Bind,

	/// For cluster volumes.
	Cluster,

	/// For named pipes.
	Npipe,

	/// For mounting from an image.
	Image,

	/// For temporary filesystems.
	Tmpfs,

	/// For names volumes.
	Volume,
}

/// Configuration for a service volume.
///
/// See more: https://docs.docker.com/reference/compose-file/services/#long-syntax-6
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(deny_unknown_fields)]
pub struct ServiceVolumeSettings {
	/// The mount type.
	#[serde(rename = "type")]
	pub type_: VolumeType,

	/// Flag to set the volume as read-only.
	#[serde(skip_serializing_if = "Option::is_none")]
	#[serde(default)]
	pub read_only: Option<bool>,

	/// The source of the mount, a path on the host for a bind mount, a docker image reference for an image mount, or the name of a volume defined in the top-level volumes key. Not applicable for a tmpfs mount.
	#[serde(skip_serializing_if = "Option::is_none")]
	#[serde(default)]
	pub source: Option<String>,

	/// The path in the container where the volume is mounted.
	pub target: String,

	/// The consistency requirements for the mount. Available values are platform specific.
	#[serde(skip_serializing_if = "Option::is_none")]
	#[serde(default)]
	pub consistency: Option<String>,

	/// Configuration specific to bind mounts.
	#[serde(skip_serializing_if = "Option::is_none")]
	#[serde(default)]
	pub bind: Option<Bind>,

	/// Configuration specific to image mounts.
	#[serde(skip_serializing_if = "Option::is_none")]
	#[serde(default)]
	pub image: Option<ImageVolumeSettings>,

	/// /// Configuration specific to tmpfs mounts.
	#[serde(skip_serializing_if = "Option::is_none")]
	#[serde(default)]
	pub tmpfs: Option<TmpfsSettings>,

	/// Configuration specific to volume mounts.
	#[serde(skip_serializing_if = "Option::is_none")]
	#[serde(default)]
	pub volume: Option<VolumeSettings>,
}

/// The propagation mode for the bind mount
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(rename_all = "lowercase")]
pub enum Propagation {
	Private,
	Rprivate,
	Rshared,
	Rslave,
	Shared,
	Slave,
}

/// Recursively mount the source directory.
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(rename_all = "lowercase")]
pub enum Recursive {
	Disabled,
	Enabled,
	Readonly,
	Writable,
}

#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub enum SELinux {
	/// For shared content.
	#[serde(rename = "z")]
	Shared,

	/// For private, unshared content.
	#[serde(rename = "Z")]
	Unshared,
}

/// Configuration specific to bind mounts.
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Default)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(deny_unknown_fields)]
#[serde(default)]
pub struct Bind {
	/// Create the host path if it doesn't exist.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub create_host_path: Option<bool>,

	/// The propagation mode for the bind mount:
	#[serde(skip_serializing_if = "Option::is_none")]
	pub propagation: Option<Propagation>,

	/// Recursively mount the source directory.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub recursive: Option<Recursive>,

	/// SELinux relabeling options: 'z' for shared content, 'Z' for private unshared content.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub selinux: Option<SELinux>,
}

/// Configuration specific to volume mounts.
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Default)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(deny_unknown_fields)]
#[serde(default)]
pub struct VolumeSettings {
	/// Labels to apply to the volume.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub labels: Option<ListOrMap>,

	/// Flag to disable copying of data from a container when a volume is created.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub nocopy: Option<bool>,

	/// Path within the volume to mount instead of the volume root.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub subpath: Option<String>,
}

#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Default)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(deny_unknown_fields)]
pub struct ImageVolumeSettings {
	/// Path within the image to mount instead of the image root.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub subpath: Option<String>,
}

/// Configuration specific to tmpfs mounts.
#[derive(Clone, Debug, Serialize, Default, Deserialize, Eq, PartialEq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(deny_unknown_fields)]
#[serde(default)]
pub struct TmpfsSettings {
	/// File mode of the tmpfs in octal.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub mode: Option<StringOrNum>,

	/// Size of the tmpfs mount in bytes.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub size: Option<StringOrNum>,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(rename_all = "lowercase")]
pub enum PortMode {
	Host,
	Ingress,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(rename_all = "lowercase")]
pub enum Protocol {
	Tcp,
	Udp,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(untagged)]
pub enum Port {
	Num(u64),
	String(String),
	Data(PortSettings),
}

/// Settings for a port mapping.
///
/// See more: https://docs.docker.com/reference/compose-file/services/#long-syntax-4
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Default)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(default)]
#[serde(deny_unknown_fields)]
pub struct PortSettings {
	/// A human-readable name for this port mapping.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub name: Option<String>,

	/// The host IP to bind to.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub host_ip: Option<String>,

	/// The port inside the container.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub target: Option<StringOrNum>,

	/// The publicly exposed port.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub published: Option<StringOrNum>,

	/// The port binding mode, either 'host' for publishing a host port or 'ingress' for load balancing.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub mode: Option<PortMode>,

	/// The port protocol (tcp or udp).
	#[serde(skip_serializing_if = "Option::is_none")]
	pub protocol: Option<Protocol>,

	/// The application protocol (TCP/IP level 4 / OSI level 7) this port is used for. This is optional and can be used as a hint for Compose to offer richer behavior for protocols that it understands.
	#[serde(skip_serializing_if = "Option::is_none")]
	pub app_protocol: Option<String>,
}

/// Defines the decisions Compose makes when it starts to pull images.
///
/// See more: https://docs.docker.com/reference/compose-file/services/#pull_policy
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[serde(rename_all = "lowercase")]
pub enum PullPolicy {
	/// Compose always pulls the image from the registry.
	Always,
	/// Compose builds the image. Compose rebuilds the image if it's already present.
	Build,
	/// Compose checks the registry for image updates if the last pull took place more than 24 hours ago.
	Daily,
	/// Compose pulls the image only if it's not available in the platform cache. This is the default option if you are not also using the [Compose Build Specification](https://docs.docker.com/reference/compose-file/build/). if_not_present is considered an alias for this value for backward compatibility. The latest tag is always pulled even when the missing pull policy is used.
	#[serde(alias = "if_not_present")]
	Missing,
	/// Compose doesn't pull the image from a registry and relies on the platform cached image. If there is no cached image, a failure is reported.
	Never,
	Refresh,
	/// Compose checks the registry for image updates if the last pull took place more than 7 days ago.
	Weekly,
	#[serde(untagged)]
	Other(String),
}