Skip to content

Commit 4057c9c

Browse files
committed
add Dockerfiles and root volume type / size options
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
1 parent 33ad845 commit 4057c9c

4 files changed

Lines changed: 128 additions & 10 deletions

File tree

Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM golang:alpine
2+
3+
WORKDIR /docker-machine-driver-scaleway
4+
5+
COPY go.mod go.sum ./
6+
7+
RUN go mod download
8+
9+
COPY main.go ./
10+
COPY driver ./driver
11+
12+
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" .
13+
14+
FROM golang:alpine
15+
16+
RUN apk add --no-cache git
17+
18+
WORKDIR /go/src/github.com/docker/machine
19+
20+
RUN git clone --branch=v0.16.2-gitlab.21 https://gitlab.com/gitlab-org/ci-cd/docker-machine .
21+
RUN CGO_ENABLED=0 GO111MODULE=off go build -o docker-machine -trimpath -ldflags="-s -w" ./cmd/docker-machine
22+
23+
24+
FROM alpine
25+
26+
RUN apk add --no-cache ca-certificates
27+
28+
COPY --from=0 /docker-machine-driver-scaleway/docker-machine-driver-scaleway /usr/local/bin/docker-machine-driver-scaleway-v2
29+
COPY --from=1 /go/src/github.com/docker/machine/docker-machine /usr/local/bin/docker-machine
30+
31+
VOLUME /root/.docker/machine
32+
33+
ENTRYPOINT ["docker-machine"]

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
DOCKER_MACHINE_IMAGE := linkacloud/docker-machine-scaleway
2+
RUNNER_IMAGE := linkacloud/gitlab-runner-docker-machine-scaleway
3+
4+
docker: docker-build docker-push
5+
6+
docker-build:
7+
@docker build -t $(DOCKER_MACHINE_IMAGE) .
8+
@docker build -t $(RUNNER_IMAGE) -f gitlab-runner.Dockerfile .
9+
docker-push:
10+
@docker push $(DOCKER_MACHINE_IMAGE)
11+
@docker push $(RUNNER_IMAGE)

driver/scaleway.go

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ type Driver struct {
5050
stopping bool
5151
created bool
5252
ipv6 bool
53+
rootVolumeSize int
54+
rootVolumeType string
55+
5356
// userDataFile string
5457
}
5558

@@ -159,6 +162,18 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
159162
// Usage: "Attach additional volume (e.g., 50G)",
160163
// Value: "",
161164
// },
165+
mcnflag.IntFlag{
166+
EnvVar: "SCALEWAY_ROOT_VOLUME_SIZE",
167+
Name: "scaleway-root-volume-size",
168+
Usage: "Root Volume Size in GiB (e.g., 50)",
169+
Value: 0,
170+
},
171+
mcnflag.StringFlag{
172+
EnvVar: "SCALEWAY_ROOT_VOLUME_TYPE",
173+
Name: "scaleway-root-volume-type",
174+
Usage: "Root Volume Type: block or local",
175+
Value: "",
176+
},
162177
// mcnflag.StringFlag{
163178
// EnvVar: "SCALEWAY_USER",
164179
// Name: "scaleway-user",
@@ -231,6 +246,14 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) (err error) {
231246
d.bootscript = flags.String("scaleway-bootscript")
232247
d.ip = flags.String("scaleway-ip")
233248
// d.volumes = flags.String("scaleway-volumes")
249+
d.rootVolumeSize = flags.Int("scaleway-root-volume-size")
250+
d.rootVolumeType = flags.String("scaleway-root-volume-type")
251+
if d.rootVolumeType != "" && d.rootVolumeType != "block" && d.rootVolumeType != "local" {
252+
return fmt.Errorf("You must provide an known root-volume-type: local or block")
253+
}
254+
if d.rootVolumeType != "" && d.rootVolumeSize == 0 {
255+
return fmt.Errorf("You must provide root-volume-size with root-volume-type")
256+
}
234257
d.ipv6 = flags.Bool("scaleway-ipv6")
235258
// d.BaseDriver.SSHUser = flags.String("scaleway-user")
236259
// d.BaseDriver.SSHPort = flags.Int("scaleway-port")
@@ -262,6 +285,7 @@ func (d *Driver) Create() (err error) {
262285
var name string = d.name
263286
var image string = d.image
264287
var zone scw.Zone = d.Zone
288+
265289
log.Debugf("Creating server bootType: %s", bootType)
266290
log.Debugf("Creating server Bootscript: %s", bootscript)
267291
log.Debugf("Creating server projectId: %s", string(*projectId))
@@ -270,16 +294,36 @@ func (d *Driver) Create() (err error) {
270294
log.Debugf("Creating server name: %s", name)
271295
log.Debugf("Creating server image: %s", image)
272296
log.Debugf("Creating server zone: %s", zone)
297+
var volumes map[string]*instance.VolumeTemplate
298+
if d.rootVolumeSize != 0 {
299+
var t instance.VolumeVolumeType
300+
switch d.rootVolumeType {
301+
case "local":
302+
t = instance.VolumeVolumeTypeLSSD
303+
case "block":
304+
t = instance.VolumeVolumeTypeBSSD
305+
default:
306+
return fmt.Errorf("You must provide an known root-volume-type: local or block")
307+
}
308+
volumes = map[string]*instance.VolumeTemplate{
309+
"0": {
310+
Size: scw.Size(d.rootVolumeSize) * scw.GB,
311+
VolumeType: t,
312+
},
313+
}
314+
log.Debugf("Creating server volume type: %s", d.rootVolumeType)
315+
log.Debugf("Creating server volume size: %d GB", d.rootVolumeSize)
316+
}
273317

274318
config := instance.CreateServerRequest{
275319
Zone: zone,
276320
Name: name,
277321
// DynamicIPRequired: &dynamicIP,
278322
CommercialType: commercialType,
279323
Image: image,
280-
// Volumes: volumes,
281-
EnableIPv6: ipv6,
282-
BootType: &bootType,
324+
Volumes: volumes,
325+
EnableIPv6: ipv6,
326+
BootType: &bootType,
283327
// Bootscript: &bootscript,
284328
// Organization: organizationId,
285329
Project: projectId,
@@ -436,15 +480,15 @@ func (d *Driver) getClient() (err error) {
436480
}
437481

438482
/*
439-
cloudInit used to add docker-machine sshkey to Scaleway Instance
483+
cloudInit used to add docker-machine sshkey to Scaleway Instance
440484
441-
Multiple choices are possible:
442-
- Use Modules "users":
443-
- without runcmd to reload cloud-init config no sshkey added to root user :thinking: why ? so KO
444-
- with runcmd to reload cloud-init config to apply config, sshkey is added to root user but sshkey from scaleway are setted to 'no-port-forwarding, ...' :thinking: why ? so OK and KO
445-
- Use Scaleway implementation with instance_keys file and scw-fetch-ssh-keys command is OK
485+
Multiple choices are possible:
486+
- Use Modules "users":
487+
- without runcmd to reload cloud-init config no sshkey added to root user :thinking: why ? so KO
488+
- with runcmd to reload cloud-init config to apply config, sshkey is added to root user but sshkey from scaleway are setted to 'no-port-forwarding, ...' :thinking: why ? so OK and KO
489+
- Use Scaleway implementation with instance_keys file and scw-fetch-ssh-keys command is OK
446490
447-
***** It's very "sensible"... *****
491+
***** It's very "sensible"... *****
448492
*/
449493
func (d *Driver) cloudInit() (contentByte string, err error) {
450494
pub := d.GetSSHKeyPath() + ".pub"

gitlab-runner.Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM golang:alpine
2+
3+
WORKDIR /docker-machine-driver-scaleway
4+
5+
COPY go.mod go.sum ./
6+
7+
RUN go mod download
8+
9+
COPY main.go ./
10+
COPY driver ./driver
11+
12+
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" .
13+
14+
FROM golang:alpine
15+
16+
RUN apk add --no-cache git
17+
18+
WORKDIR /go/src/github.com/docker/machine
19+
20+
RUN git clone --branch=v0.16.2-gitlab.21 https://gitlab.com/gitlab-org/ci-cd/docker-machine .
21+
RUN CGO_ENABLED=0 GO111MODULE=off go build -o docker-machine -trimpath -ldflags="-s -w" ./cmd/docker-machine
22+
23+
24+
FROM gitlab/gitlab-runner
25+
26+
COPY --from=0 /docker-machine-driver-scaleway/docker-machine-driver-scaleway /usr/local/bin/docker-machine-driver-scaleway-v2
27+
COPY --from=1 /go/src/github.com/docker/machine/docker-machine /usr/local/bin/docker-machine
28+
29+
VOLUME /root/.docker/machine
30+

0 commit comments

Comments
 (0)