Skip to content

Commit

Permalink
Merge pull request #89 from grafana/julienduchesne/expose-ports
Browse files Browse the repository at this point in the history
Add configuration to expose ports
  • Loading branch information
bradrydzewski committed Jan 7, 2022
2 parents 216e4dd + 096546e commit 84913ae
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
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"`
NamePrefix string `envconfig:"DRONE_AGENT_NAME_PREFIX" default:"agent-"`
}
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

0 comments on commit 84913ae

Please sign in to comment.