mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-10-22 05:09:46 +00:00
Renamed procs/jobs to steps in code (#1331)
Renamed `procs` to `steps` in code for the issue #1288 Co-authored-by: Harikesh Prajapati <harikesh.prajapati@druva.com> Co-authored-by: qwerty287 <ndev@web.de> Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
@@ -12,73 +12,73 @@ import (
|
||||
)
|
||||
|
||||
// returns a container configuration.
|
||||
func toConfig(proc *types.Step) *container.Config {
|
||||
func toConfig(step *types.Step) *container.Config {
|
||||
config := &container.Config{
|
||||
Image: proc.Image,
|
||||
Labels: proc.Labels,
|
||||
WorkingDir: proc.WorkingDir,
|
||||
Image: step.Image,
|
||||
Labels: step.Labels,
|
||||
WorkingDir: step.WorkingDir,
|
||||
AttachStdout: true,
|
||||
AttachStderr: true,
|
||||
}
|
||||
if len(proc.Environment) != 0 {
|
||||
config.Env = toEnv(proc.Environment)
|
||||
if len(step.Environment) != 0 {
|
||||
config.Env = toEnv(step.Environment)
|
||||
}
|
||||
if len(proc.Command) != 0 {
|
||||
config.Cmd = proc.Command
|
||||
if len(step.Command) != 0 {
|
||||
config.Cmd = step.Command
|
||||
}
|
||||
if len(proc.Entrypoint) != 0 {
|
||||
config.Entrypoint = proc.Entrypoint
|
||||
if len(step.Entrypoint) != 0 {
|
||||
config.Entrypoint = step.Entrypoint
|
||||
}
|
||||
if len(proc.Volumes) != 0 {
|
||||
config.Volumes = toVol(proc.Volumes)
|
||||
if len(step.Volumes) != 0 {
|
||||
config.Volumes = toVol(step.Volumes)
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
// returns a container host configuration.
|
||||
func toHostConfig(proc *types.Step) *container.HostConfig {
|
||||
func toHostConfig(step *types.Step) *container.HostConfig {
|
||||
config := &container.HostConfig{
|
||||
Resources: container.Resources{
|
||||
CPUQuota: proc.CPUQuota,
|
||||
CPUShares: proc.CPUShares,
|
||||
CpusetCpus: proc.CPUSet,
|
||||
Memory: proc.MemLimit,
|
||||
MemorySwap: proc.MemSwapLimit,
|
||||
CPUQuota: step.CPUQuota,
|
||||
CPUShares: step.CPUShares,
|
||||
CpusetCpus: step.CPUSet,
|
||||
Memory: step.MemLimit,
|
||||
MemorySwap: step.MemSwapLimit,
|
||||
},
|
||||
LogConfig: container.LogConfig{
|
||||
Type: "json-file",
|
||||
},
|
||||
Privileged: proc.Privileged,
|
||||
ShmSize: proc.ShmSize,
|
||||
Sysctls: proc.Sysctls,
|
||||
Privileged: step.Privileged,
|
||||
ShmSize: step.ShmSize,
|
||||
Sysctls: step.Sysctls,
|
||||
}
|
||||
|
||||
// if len(proc.VolumesFrom) != 0 {
|
||||
// config.VolumesFrom = proc.VolumesFrom
|
||||
// if len(step.VolumesFrom) != 0 {
|
||||
// config.VolumesFrom = step.VolumesFrom
|
||||
// }
|
||||
if len(proc.NetworkMode) != 0 {
|
||||
config.NetworkMode = container.NetworkMode(proc.NetworkMode)
|
||||
if len(step.NetworkMode) != 0 {
|
||||
config.NetworkMode = container.NetworkMode(step.NetworkMode)
|
||||
}
|
||||
if len(proc.IpcMode) != 0 {
|
||||
config.IpcMode = container.IpcMode(proc.IpcMode)
|
||||
if len(step.IpcMode) != 0 {
|
||||
config.IpcMode = container.IpcMode(step.IpcMode)
|
||||
}
|
||||
if len(proc.DNS) != 0 {
|
||||
config.DNS = proc.DNS
|
||||
if len(step.DNS) != 0 {
|
||||
config.DNS = step.DNS
|
||||
}
|
||||
if len(proc.DNSSearch) != 0 {
|
||||
config.DNSSearch = proc.DNSSearch
|
||||
if len(step.DNSSearch) != 0 {
|
||||
config.DNSSearch = step.DNSSearch
|
||||
}
|
||||
if len(proc.ExtraHosts) != 0 {
|
||||
config.ExtraHosts = proc.ExtraHosts
|
||||
if len(step.ExtraHosts) != 0 {
|
||||
config.ExtraHosts = step.ExtraHosts
|
||||
}
|
||||
if len(proc.Devices) != 0 {
|
||||
config.Devices = toDev(proc.Devices)
|
||||
if len(step.Devices) != 0 {
|
||||
config.Devices = toDev(step.Devices)
|
||||
}
|
||||
if len(proc.Volumes) != 0 {
|
||||
config.Binds = proc.Volumes
|
||||
if len(step.Volumes) != 0 {
|
||||
config.Binds = step.Volumes
|
||||
}
|
||||
config.Tmpfs = map[string]string{}
|
||||
for _, path := range proc.Tmpfs {
|
||||
for _, path := range step.Tmpfs {
|
||||
if !strings.Contains(path, ":") {
|
||||
config.Tmpfs[path] = ""
|
||||
continue
|
||||
|
@@ -104,19 +104,19 @@ func (e *docker) Setup(_ context.Context, conf *backend.Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *docker) Exec(ctx context.Context, proc *backend.Step) error {
|
||||
config := toConfig(proc)
|
||||
hostConfig := toHostConfig(proc)
|
||||
func (e *docker) Exec(ctx context.Context, step *backend.Step) error {
|
||||
config := toConfig(step)
|
||||
hostConfig := toHostConfig(step)
|
||||
|
||||
// create pull options with encoded authorization credentials.
|
||||
pullopts := types.ImagePullOptions{}
|
||||
if proc.AuthConfig.Username != "" && proc.AuthConfig.Password != "" {
|
||||
pullopts.RegistryAuth, _ = encodeAuthToBase64(proc.AuthConfig)
|
||||
if step.AuthConfig.Username != "" && step.AuthConfig.Password != "" {
|
||||
pullopts.RegistryAuth, _ = encodeAuthToBase64(step.AuthConfig)
|
||||
}
|
||||
|
||||
// automatically pull the latest version of the image if requested
|
||||
// by the process configuration.
|
||||
if proc.Pull {
|
||||
if step.Pull {
|
||||
responseBody, perr := e.client.ImagePull(ctx, config.Image, pullopts)
|
||||
if perr == nil {
|
||||
defer responseBody.Close()
|
||||
@@ -128,7 +128,7 @@ func (e *docker) Exec(ctx context.Context, proc *backend.Step) error {
|
||||
}
|
||||
// Fix "Show warning when fail to auth to docker registry"
|
||||
// (https://web.archive.org/web/20201023145804/https://github.com/drone/drone/issues/1917)
|
||||
if perr != nil && proc.AuthConfig.Password != "" {
|
||||
if perr != nil && step.AuthConfig.Password != "" {
|
||||
return perr
|
||||
}
|
||||
}
|
||||
@@ -136,7 +136,7 @@ func (e *docker) Exec(ctx context.Context, proc *backend.Step) error {
|
||||
// add default volumes to the host configuration
|
||||
hostConfig.Binds = append(hostConfig.Binds, e.volumes...)
|
||||
|
||||
_, err := e.client.ContainerCreate(ctx, config, hostConfig, nil, nil, proc.Name)
|
||||
_, err := e.client.ContainerCreate(ctx, config, hostConfig, nil, nil, step.Name)
|
||||
if client.IsErrNotFound(err) {
|
||||
// automatically pull and try to re-create the image if the
|
||||
// failure is caused because the image does not exist.
|
||||
@@ -150,15 +150,15 @@ func (e *docker) Exec(ctx context.Context, proc *backend.Step) error {
|
||||
log.Error().Err(err).Msg("DisplayJSONMessagesStream")
|
||||
}
|
||||
|
||||
_, err = e.client.ContainerCreate(ctx, config, hostConfig, nil, nil, proc.Name)
|
||||
_, err = e.client.ContainerCreate(ctx, config, hostConfig, nil, nil, step.Name)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(proc.NetworkMode) == 0 {
|
||||
for _, net := range proc.Networks {
|
||||
err = e.client.NetworkConnect(ctx, net.Name, proc.Name, &network.EndpointSettings{
|
||||
if len(step.NetworkMode) == 0 {
|
||||
for _, net := range step.Networks {
|
||||
err = e.client.NetworkConnect(ctx, net.Name, step.Name, &network.EndpointSettings{
|
||||
Aliases: net.Aliases,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -168,24 +168,24 @@ func (e *docker) Exec(ctx context.Context, proc *backend.Step) error {
|
||||
|
||||
// join the container to an existing network
|
||||
if e.network != "" {
|
||||
err = e.client.NetworkConnect(ctx, e.network, proc.Name, &network.EndpointSettings{})
|
||||
err = e.client.NetworkConnect(ctx, e.network, step.Name, &network.EndpointSettings{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return e.client.ContainerStart(ctx, proc.Name, startOpts)
|
||||
return e.client.ContainerStart(ctx, step.Name, startOpts)
|
||||
}
|
||||
|
||||
func (e *docker) Wait(ctx context.Context, proc *backend.Step) (*backend.State, error) {
|
||||
wait, errc := e.client.ContainerWait(ctx, proc.Name, "")
|
||||
func (e *docker) Wait(ctx context.Context, step *backend.Step) (*backend.State, error) {
|
||||
wait, errc := e.client.ContainerWait(ctx, step.Name, "")
|
||||
select {
|
||||
case <-wait:
|
||||
case <-errc:
|
||||
}
|
||||
|
||||
info, err := e.client.ContainerInspect(ctx, proc.Name)
|
||||
info, err := e.client.ContainerInspect(ctx, step.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -200,8 +200,8 @@ func (e *docker) Wait(ctx context.Context, proc *backend.Step) (*backend.State,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (e *docker) Tail(ctx context.Context, proc *backend.Step) (io.ReadCloser, error) {
|
||||
logs, err := e.client.ContainerLogs(ctx, proc.Name, logsOpts)
|
||||
func (e *docker) Tail(ctx context.Context, step *backend.Step) (io.ReadCloser, error) {
|
||||
logs, err := e.client.ContainerLogs(ctx, step.Name, logsOpts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user