Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration to expose ports #89

Merged
merged 1 commit into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type (
EnvironFile string `envconfig:"DRONE_AGENT_ENV_FILE"`
Environ []string
Volumes []string
Ports []string `envconfig:"DRONE_AGENT_PUBLISHED_PORTS"`
Labels map[string]string `envconfig:"DRONE_AGENT_LABELS"`
}

Expand Down
1 change: 1 addition & 0 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func New(
secret: config.Agent.Token,
envs: config.Agent.Environ,
volumes: config.Agent.Volumes,
ports: config.Agent.Ports,
labels: config.Agent.Labels,
proto: config.Server.Proto,
host: config.Server.Host,
Expand Down
15 changes: 13 additions & 2 deletions engine/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/mount"
docker "github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
)

type installer struct {
Expand All @@ -33,6 +34,7 @@ type installer struct {
image string
secret string
volumes []string
ports []string
host string
proto string
envs []string
Expand Down Expand Up @@ -216,13 +218,21 @@ poller:
mounts = nil
}

exposedPorts, portBindings, err := nat.ParsePortSpecs(i.ports)
if err != nil {
i.metrics.IncrServerInitError()
logger.WithError(err).Errorln("could not create port binding")
return i.errorUpdate(ctx, instance, err)
}

res, err := client.ContainerCreate(ctx,
&container.Config{
Image: i.image,
AttachStdout: true,
AttachStderr: true,
Env: envs,
Volumes: toVol(volumes),
ExposedPorts: exposedPorts,
Labels: map[string]string{
"com.centurylinklabs.watchtower.enable": "true",
"com.centurylinklabs.watchtower.stop-signal": "SIGHUP",
Expand All @@ -234,8 +244,9 @@ poller:
},
},
&container.HostConfig{
Binds: volumes,
Mounts: mounts,
Binds: volumes,
Mounts: mounts,
PortBindings: portBindings,
RestartPolicy: container.RestartPolicy{
Name: "always",
},
Expand Down