Skip to content

Commit

Permalink
network-manager: validate flag value
Browse files Browse the repository at this point in the history
Dockerfile: fix ubuntu version to 20.04

Signed-off-by: Adphi <[email protected]>
  • Loading branch information
Adphi committed Sep 10, 2022
1 parent 3417f50 commit 1721146
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ bin/
dist/
images
wstation
/d2vm
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file modified cmd/d2vm/run/sparsecat-linux-amd64
Binary file not shown.
23 changes: 22 additions & 1 deletion dockerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions pkg/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down

0 comments on commit 1721146

Please sign in to comment.