2
0
mirror of https://github.com/linka-cloud/d2vm.git synced 2024-11-25 17:16:25 +00:00

network-manager: validate flag value

Dockerfile: fix ubuntu version to 20.04

Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
Adphi 2022-08-09 14:30:03 +02:00
parent 3417f50e11
commit 1721146c7d
Signed by: adphi
GPG Key ID: 46BE4062DB2397FF
6 changed files with 29 additions and 2 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ bin/
dist/ dist/
images images
wstation wstation
/d2vm

View File

@ -25,7 +25,7 @@ COPY . .
RUN make .build RUN make .build
FROM ubuntu FROM ubuntu:20.04
RUN apt-get update && \ RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \

View File

@ -70,6 +70,8 @@ check-fmt:
vet: vet:
@go list ./...|grep -v scratch|GOOS=linux xargs go vet @go list ./...|grep -v scratch|GOOS=linux xargs go vet
build-dev: docker-build .build
.build: .build:
@go generate ./... @go generate ./...
@go build -o d2vm -ldflags "-s -w -X '$(MODULE).Version=$(VERSION)' -X '$(MODULE).BuildDate=$(shell date)'" ./cmd/d2vm @go build -o d2vm -ldflags "-s -w -X '$(MODULE).Version=$(VERSION)' -X '$(MODULE).BuildDate=$(shell date)'" ./cmd/d2vm

Binary file not shown.

View File

@ -50,6 +50,15 @@ const (
NetworkManagerNetplan NetworkManager = "netplan" NetworkManagerNetplan NetworkManager = "netplan"
) )
func (n NetworkManager) Validate() error {
switch n {
case NetworkManagerNone, NetworkManagerIfupdown2, NetworkManagerNetplan:
return nil
default:
return fmt.Errorf("unsupported network manager: %s", n)
}
}
type Dockerfile struct { type Dockerfile struct {
Image string Image string
Password string Password string
@ -78,14 +87,26 @@ func NewDockerfile(release OSRelease, img, password string, networkManager Netwo
case ReleaseAlpine: case ReleaseAlpine:
d.tmpl = alpineDockerfileTemplate d.tmpl = alpineDockerfileTemplate
net = NetworkManagerIfupdown2 net = NetworkManagerIfupdown2
if networkManager == NetworkManagerNetplan {
return d, fmt.Errorf("netplan is not supported on alpine")
}
case ReleaseCentOS: case ReleaseCentOS:
d.tmpl = centOSDockerfileTemplate d.tmpl = centOSDockerfileTemplate
net = NetworkManagerNone
if networkManager != "" && networkManager != NetworkManagerNone {
return Dockerfile{}, fmt.Errorf("network manager is not supported on centos")
}
default: default:
return Dockerfile{}, fmt.Errorf("unsupported distribution: %s", release.ID) return Dockerfile{}, fmt.Errorf("unsupported distribution: %s", release.ID)
} }
if d.NetworkManager == "" { if d.NetworkManager == "" {
if release.ID != ReleaseCentOS {
logrus.Warnf("no network manager specified, using distribution defaults: %s", net) logrus.Warnf("no network manager specified, using distribution defaults: %s", net)
}
d.NetworkManager = net d.NetworkManager = net
} }
if err := d.NetworkManager.Validate(); err != nil {
return Dockerfile{}, err
}
return d, nil return d, nil
} }

View File

@ -102,6 +102,9 @@ func RunD2VM(ctx context.Context, image, version, cmd string, args ...string) er
if err != nil { if err != nil {
return err return err
} }
if image == "" {
image = "linkacloud/d2vm"
}
if version == "" { if version == "" {
version = "latest" version = "latest"
} }