This repository has been archived by the owner on Sep 19, 2023. It is now read-only.
/
run_config.go
210 lines (157 loc) · 5.55 KB
/
run_config.go
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
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"strconv"
"github.com/go-openapi/errors"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// RunConfig All the properties that define how the application runs in docker
//
// swagger:model RunConfig
type RunConfig struct {
// The ID of the app the run config is for
// Required: true
// Format: uuid4
AppID strfmt.UUID4 `json:"appId" gorm:"primaryKey"`
// command
Command []string `json:"command"`
// The currently running image digest (hash). Used internally when running applications
// instead of the tag because the when a new image is pushed, the tag stays the same but the
// digest changes
//
// Required: true
ImageDigest string `json:"imageDigest"`
// A list of other apps that the service communicates with using their service name and docker's internal DNS. Services don't have to be two way; only the service that accesses the other needs the other network added
// Unique: true
Networks []string `json:"networks"`
// The placement constraints specifying which nodes the app will be ran on. Any valid value for the [`--constraint` flag](https://docs.docker.com/engine/swarm/services/#placement-constraints) is valid item in this list
// Unique: true
Placement []string `json:"placement"`
// The ports that you access the app through in the swarm. This field can, and should be left empty. Miasma automatically manages assigning published ports between 3001-4999. If you need to specify a port, make sure it's outside that range or the port has not been taken. Plugins have set ports starting with 4000, so avoid 4000-4020 if you want to add a plugin at a later date. If these ports are ever cleared, the app will continue using the same ports it was published to before, so that the ports don't change unnecessarily. If you removed it to clear a port for another app/plugin, make sure to restart the app and a new, random port will be allocated for the app, freeing the old port
// Unique: true
PublishedPorts []uint32 `json:"publishedPorts"`
// The ports that the app is listening to inside the container. If no target ports are specified, then the container should respect the `PORT` env var.
// Unique: true
TargetPorts []uint32 `json:"targetPorts"`
// volume bindings for the app
Volumes []*RunConfigVolume `json:"volumes"`
}
// Validate validates this run config
func (m *RunConfig) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateAppID(formats); err != nil {
res = append(res, err)
}
if err := m.validateImageDigest(formats); err != nil {
res = append(res, err)
}
if err := m.validateNetworks(formats); err != nil {
res = append(res, err)
}
if err := m.validatePlacement(formats); err != nil {
res = append(res, err)
}
if err := m.validatePublishedPorts(formats); err != nil {
res = append(res, err)
}
if err := m.validateTargetPorts(formats); err != nil {
res = append(res, err)
}
if err := m.validateVolumes(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *RunConfig) validateAppID(formats strfmt.Registry) error {
if err := validate.Required("appId", "body", strfmt.UUID4(m.AppID)); err != nil {
return err
}
if err := validate.FormatOf("appId", "body", "uuid4", m.AppID.String(), formats); err != nil {
return err
}
return nil
}
func (m *RunConfig) validateImageDigest(formats strfmt.Registry) error {
if err := validate.RequiredString("imageDigest", "body", string(m.ImageDigest)); err != nil {
return err
}
return nil
}
func (m *RunConfig) validateNetworks(formats strfmt.Registry) error {
if swag.IsZero(m.Networks) { // not required
return nil
}
if err := validate.UniqueItems("networks", "body", m.Networks); err != nil {
return err
}
return nil
}
func (m *RunConfig) validatePlacement(formats strfmt.Registry) error {
if swag.IsZero(m.Placement) { // not required
return nil
}
if err := validate.UniqueItems("placement", "body", m.Placement); err != nil {
return err
}
return nil
}
func (m *RunConfig) validatePublishedPorts(formats strfmt.Registry) error {
if swag.IsZero(m.PublishedPorts) { // not required
return nil
}
if err := validate.UniqueItems("publishedPorts", "body", m.PublishedPorts); err != nil {
return err
}
return nil
}
func (m *RunConfig) validateTargetPorts(formats strfmt.Registry) error {
if swag.IsZero(m.TargetPorts) { // not required
return nil
}
if err := validate.UniqueItems("targetPorts", "body", m.TargetPorts); err != nil {
return err
}
return nil
}
func (m *RunConfig) validateVolumes(formats strfmt.Registry) error {
if swag.IsZero(m.Volumes) { // not required
return nil
}
for i := 0; i < len(m.Volumes); i++ {
if swag.IsZero(m.Volumes[i]) { // not required
continue
}
if m.Volumes[i] != nil {
if err := m.Volumes[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("volumes" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
// MarshalBinary interface implementation
func (m *RunConfig) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *RunConfig) UnmarshalBinary(b []byte) error {
var res RunConfig
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}