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

fixes for launching one-off processes #2970

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions provider/aws/processes.go
Expand Up @@ -819,6 +819,7 @@ func (p *Provider) generateTaskDefinition1(app, service string, opts structs.Pro
cd := &ecs.ContainerDefinition{
DockerLabels: map[string]*string{
"convox.process.type": aws.String("oneoff"),
"convox.release": aws.String(release),
},
Essential: aws.Bool(true),
Image: aws.String(fmt.Sprintf("%s.dkr.ecr.%s.amazonaws.com/%s:%s.%s", a.Outputs["RegistryId"], p.Region, a.Outputs["RegistryRepository"], service, r.Build)),
Expand Down
3 changes: 2 additions & 1 deletion provider/aws/processes_test.go
Expand Up @@ -1219,7 +1219,8 @@ var cycleProcessRegisterTaskDefinitionDetached = awsutil.Cycle{
"containerDefinitions": [
{
"dockerLabels": {
"convox.process.type": "oneoff"
"convox.process.type": "oneoff",
"convox.release": "RVFETUHHKKD"
},
"environment": [
{
Expand Down
116 changes: 47 additions & 69 deletions provider/local/process.go
Expand Up @@ -15,7 +15,6 @@ import (
"time"

"github.com/convox/rack/pkg/helpers"
"github.com/convox/rack/pkg/manifest"
"github.com/convox/rack/pkg/structs"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -239,91 +238,74 @@ func (p *Provider) argsFromOpts(app, service string, opts processStartOptions) (
}

release = a.Release

}

// get release and manifest for initial environment and volumes
var m *manifest.Manifest
var r *structs.Release
var s *manifest.Service
var err error
image := opts.Image

if opts.Release != "" {
m, r, err = helpers.ReleaseManifest(p, app, opts.Release)
if err != nil {
return nil, errors.WithStack(err)
}
} else {
m, r, err = helpers.AppManifest(p, app)
if image == "" {
m, r, err := helpers.ReleaseManifest(p, app, release)
if err != nil {
return nil, errors.WithStack(err)
return nil, err
}
}

// if service is not defined in manifest, i.e. "build", carry on
s, err = m.Service(service)
if err != nil && !strings.Contains(err.Error(), "no such service") {
return nil, errors.WithStack(err)
}
image = fmt.Sprintf("%s/%s:%s.%s", p.Rack, app, service, r.Build)

if s != nil {
// manifest environment
env, err := m.ServiceEnvironment(s.Name)
s, err := m.Service(service)
if err != nil {
return nil, errors.WithStack(err)
return nil, err
}

for k, v := range env {
args = append(args, "-e", fmt.Sprintf("%s=%s", k, v))
}
if s != nil {
// manifest environment
env, err := m.ServiceEnvironment(s.Name)
if err != nil {
return nil, errors.WithStack(err)
}

for _, sr := range s.Resources {
for _, r := range m.Resources {
if r.Name == sr {
u, err := p.resourceURL(app, r.Type, r.Name)
if err != nil {
return nil, err
}
for k, v := range env {
args = append(args, "-e", fmt.Sprintf("%s=%s", k, v))
}

args = append(args, "-e", fmt.Sprintf("%s=%s", fmt.Sprintf("%s_URL", strings.ToUpper(sr)), u))
for _, sr := range s.Resources {
for _, r := range m.Resources {
if r.Name == sr {
u, err := p.resourceURL(app, r.Type, r.Name)
if err != nil {
return nil, err
}

args = append(args, "-e", fmt.Sprintf("%s=%s", fmt.Sprintf("%s_URL", strings.ToUpper(sr)), u))
}
}
}
}

// app environment
menv, err := helpers.AppEnvironment(p, app)
if err != nil {
return nil, err
}
// app environment
menv, err := helpers.AppEnvironment(p, app)
if err != nil {
return nil, err
}

for k, v := range menv {
args = append(args, "-e", fmt.Sprintf("%s=%s", k, v))
}
for k, v := range menv {
args = append(args, "-e", fmt.Sprintf("%s=%s", k, v))
}

// volumes
s, err := m.Service(s.Name)
if err != nil {
return nil, errors.WithStack(err)
}
// volumes
s, err := m.Service(s.Name)
if err != nil {
return nil, errors.WithStack(err)
}

vv, err := p.serviceVolumes(app, s.Volumes)
if err != nil {
return nil, errors.WithStack(err)
}
vv, err := p.serviceVolumes(app, s.Volumes)
if err != nil {
return nil, errors.WithStack(err)
}

for _, v := range vv {
args = append(args, "-v", v)
for _, v := range vv {
args = append(args, "-v", v)
}
}
}

image := ""

if opts.Image != "" {
image = opts.Image
} else {
image = fmt.Sprintf("%s/%s:%s.%s", p.Rack, app, service, r.Build)
}

// FIXME try letting docker daemon pass through dns
// if this works long term can delete this
// if p.Router != "" {
Expand Down Expand Up @@ -371,11 +353,7 @@ func (p *Provider) argsFromOpts(app, service string, opts processStartOptions) (
args = append(args, "--label", fmt.Sprintf("convox.app=%s", app))
args = append(args, "--label", fmt.Sprintf("convox.rack=%s", p.Rack))
args = append(args, "--label", fmt.Sprintf("convox.type=%s", "process"))

if opts.Release != "" {
args = append(args, "--label", fmt.Sprintf("convox.release=%s", opts.Release))
}

args = append(args, "--label", fmt.Sprintf("convox.release=%s", release))
args = append(args, "--label", fmt.Sprintf("convox.service=%s", service))

for from, to := range opts.Volumes {
Expand Down