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

Create options #179

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
import com.github.kostyasha.yad.DockerConnector.DescriptorImpl;
import com.github.kostyasha.yad.DockerContainerLifecycle;
import com.github.kostyasha.yad.DockerSlaveTemplate;
import com.github.kostyasha.yad.commons.DockerCreateContainer;
import com.github.kostyasha.yad.commons.DockerLogConfig;
import com.github.kostyasha.yad.commons.DockerPullImage;
import com.github.kostyasha.yad.commons.DockerRemoveContainer;
import com.github.kostyasha.yad.docker_java.com.github.dockerjava.api.model.LogConfig;
import com.github.kostyasha.yad.launcher.DockerComputerJNLPLauncher;
import com.github.kostyasha.yad.other.ConnectorType;
import com.github.kostyasha.yad.strategy.DockerOnceRetentionStrategy;
Expand Down Expand Up @@ -49,6 +52,7 @@
import static com.github.kostyasha.it.utils.JenkinsRuleHelpers.waitUntilNoActivityUpTo;
import static com.github.kostyasha.yad.DockerConnector.DEFAULT_API_VERSION;
import static com.github.kostyasha.yad.commons.DockerImagePullStrategy.PULL_LATEST;
import static com.github.kostyasha.yad.docker_java.com.github.dockerjava.api.model.LogConfig.LoggingType.JSON_FILE;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
Expand Down Expand Up @@ -165,13 +169,20 @@ public Boolean call() throws Throwable {
final DockerPullImage pullImage = new DockerPullImage();
pullImage.setPullStrategy(PULL_LATEST);

// create
final DockerCreateContainer createContainer = new DockerCreateContainer();
final DockerLogConfig logConfig = new DockerLogConfig();
logConfig.setLoggingType(JSON_FILE);
createContainer.setLogConfig(logConfig);

//remove
final DockerRemoveContainer removeContainer = new DockerRemoveContainer();
removeContainer.setRemoveVolumes(true);
removeContainer.setForce(true);

//lifecycle
final DockerContainerLifecycle containerLifecycle = new DockerContainerLifecycle();
containerLifecycle.setCreateContainer(createContainer);
containerLifecycle.setImage(slaveImage);
containerLifecycle.setPullImage(pullImage);
containerLifecycle.setRemoveContainer(removeContainer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import static com.github.kostyasha.yad.utils.BindUtils.joinToStr;
import static com.github.kostyasha.yad.utils.BindUtils.splitAndFilterEmpty;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
import static org.apache.commons.lang.StringUtils.trimToNull;
import static org.apache.commons.lang.builder.ToStringStyle.SHORT_PREFIX_STYLE;

Expand Down Expand Up @@ -123,6 +124,9 @@ public class DockerCreateContainer extends AbstractDescribableImpl<DockerCreateC
@CheckForNull
private String cpusetMems;

@CheckForNull
private DockerLogConfig logConfig;

@DataBoundConstructor
public DockerCreateContainer() {
}
Expand Down Expand Up @@ -406,6 +410,16 @@ public void setCpusetMems(String cpusetMems) {
this.cpusetMems = cpusetMems;
}

@CheckForNull
public DockerLogConfig getLogConfig() {
return logConfig;
}

@DataBoundSetter
public void setLogConfig(DockerLogConfig logConfig) {
this.logConfig = logConfig;
}

/**
* Fills user specified values
*
Expand Down Expand Up @@ -513,6 +527,10 @@ public CreateContainerCmd fillContainerConfig(CreateContainerCmd containerConfig
containerConfig.withCpusetMems(getCpusetMems());
}

if (nonNull(getLogConfig())) {
containerConfig.withLogConfig(getLogConfig().getLogConfig());
}

return containerConfig;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.github.kostyasha.yad.commons;

import com.github.kostyasha.yad.docker_java.com.github.dockerjava.api.model.LogConfig;
import com.github.kostyasha.yad.docker_java.com.github.dockerjava.api.model.LogConfig.LoggingType;
import com.github.kostyasha.yad.docker_java.org.apache.commons.lang.builder.EqualsBuilder;
import com.github.kostyasha.yad.docker_java.org.apache.commons.lang.builder.HashCodeBuilder;
import com.github.kostyasha.yad.docker_java.org.apache.commons.lang.builder.ToStringBuilder;
import com.github.kostyasha.yad.docker_java.org.apache.commons.lang.builder.ToStringStyle;
import hudson.Extension;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.CheckForNull;
import java.util.Map;

/**
* @author Kanstantsin Shautsou
*/
public class DockerLogConfig extends AbstractDescribableImpl<DockerLogConfig> {
private static final Logger LOG = LoggerFactory.getLogger(DockerLogConfig.class);

@CheckForNull
private LoggingType loggingType = LoggingType.DEFAULT;

@CheckForNull
private Map<String, String> config = null;

@DataBoundConstructor
public DockerLogConfig() {
}


@CheckForNull
public LogConfig.LoggingType getLoggingType() {
return loggingType;
}

@DataBoundSetter
public void setLoggingType(LoggingType loggingType) {
this.loggingType = loggingType;
}

@CheckForNull
public Map<String, String> getConfig() {
return config;
}

@DataBoundSetter
public void setConfig(Map<String, String> config) {
this.config = config;
}

@CheckForNull
public LogConfig getLogConfig() {
return new LogConfig(getLoggingType(), getConfig());
}


@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}

@Override
public boolean equals(Object o) {
return EqualsBuilder.reflectionEquals(this, o);
}

@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}

@Extension
public static class DescriptorImpl extends Descriptor<DockerLogConfig> {

@Override
public String getDisplayName() {
return "Create Container Log Config";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ f.advanced(title: _("Container settings"), align: "left") {
f.textbox()
}

f.property(field: "logConfig")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.github.kostyasha.yad.commons.DockerLogConfig

import lib.FormTagLib

def f = namespace(FormTagLib);


f.entry(title: _("Logging Type"), field: "loggingType") {
f.enum() {
text(my.name())
}
}

// No good UI for binding.
//
//f.entry(title: _("Logging Config"), field: "configStr") {
// f.expandableTextbox()
//}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
See <a href="https://docs.docker.com/engine/admin/logging/overview/"> Docker Engine Logging Overview</a>
DEFAULT is "json-file".