2
0
mirror of https://github.com/linka-cloud/d2vm.git synced 2024-11-22 07:46: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 35a50b79f1
commit 506919cbad
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/
images
wstation
/d2vm

View File

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

View File

@ -70,6 +70,8 @@ check-fmt:
vet:
@go list ./...|grep -v scratch|GOOS=linux xargs go vet
build-dev: docker-build .build
.build:
@go generate ./...
@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"
)
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 {
Image string
Password string
@ -78,14 +87,26 @@ func NewDockerfile(release OSRelease, img, password string, networkManager Netwo
case ReleaseAlpine:
d.tmpl = alpineDockerfileTemplate
net = NetworkManagerIfupdown2
if networkManager == NetworkManagerNetplan {
return d, fmt.Errorf("netplan is not supported on alpine")
}
case ReleaseCentOS:
d.tmpl = centOSDockerfileTemplate
net = NetworkManagerNone
if networkManager != "" && networkManager != NetworkManagerNone {
return Dockerfile{}, fmt.Errorf("network manager is not supported on centos")
}
default:
return Dockerfile{}, fmt.Errorf("unsupported distribution: %s", release.ID)
}
if d.NetworkManager == "" {
logrus.Warnf("no network manager specified, using distribution defaults: %s", net)
if release.ID != ReleaseCentOS {
logrus.Warnf("no network manager specified, using distribution defaults: %s", net)
}
d.NetworkManager = net
}
if err := d.NetworkManager.Validate(); err != nil {
return Dockerfile{}, err
}
return d, nil
}

View File

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