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 an option to pause after container startup #50

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 @@ -75,11 +75,14 @@ public class DockerBuildWrapper extends BuildWrapper {

private final boolean noCache;

private int pauseAfterContainerLaunch = 0;

@DataBoundConstructor
public DockerBuildWrapper(DockerImageSelector selector, String dockerInstallation, DockerServerEndpoint dockerHost, String dockerRegistryCredentials, boolean verbose, boolean privileged,
List<Volume> volumes, String group, String command,
boolean forcePull,
String net, String memory, String cpu, boolean noCache) {
String net, String memory, String cpu, boolean noCache,
boolean isLaunchPause, int pauseAfterContainerLaunch) {
this.selector = selector;
this.dockerInstallation = dockerInstallation;
this.dockerHost = dockerHost;
Expand All @@ -94,6 +97,7 @@ public DockerBuildWrapper(DockerImageSelector selector, String dockerInstallatio
this.memory = memory;
this.cpu = cpu;
this.noCache = noCache;
this.pauseAfterContainerLaunch = isLaunchPause ? pauseAfterContainerLaunch : 0;
}

public DockerImageSelector getSelector() {
Expand Down Expand Up @@ -136,6 +140,10 @@ public boolean isForcePull() {
return forcePull;
}

public int getPauseAfterContainerLaunch() {
return pauseAfterContainerLaunch;
}

public String getNet() { return net;}

public String getMemory() { return memory;}
Expand Down Expand Up @@ -193,6 +201,13 @@ public Environment setUp(AbstractBuild build, final Launcher launcher, BuildList
listener.getLogger().println("Docker container " + runInContainer.container + " started to host the build");
}

// pause after container launch if configured
if ( pauseAfterContainerLaunch > 0 ) {
listener.getLogger().println("Pausing for " + pauseAfterContainerLaunch + " seconds to allow the container to complete startup");
try {Thread.sleep(pauseAfterContainerLaunch * 1000);}
catch ( InterruptedException ex ) {}
}

// We are all set, DockerDecoratedLauncher now can wrap launcher commands with docker-exec
runInContainer.enable();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ THE SOFTWARE.
<f:entry field="cpu" title="CPU shares">
<f:textbox/>
</f:entry>
<f:optionalBlock field="isLaunchPause" title="${%Pause after container launch}" checked="${instance.pauseAfterContainerLaunch>0}"
help="/descriptor/com.cloudbees.jenkins.plugins.docker_build_env.DockerBuildWrapper/help/launch-pause" inline="true">
<f:entry title="${%Pause Seconds}">
<f:number clazz="number" field="pauseAfterContainerLaunch" min="0" max="30" step="1" />
</f:entry>
</f:optionalBlock>
</f:advanced>

</f:nested>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
For some container setups, it may be desirable to pause briefly after the container has completed startup to allow a startup script to complete prior to launching the first build command.
<br>
If enabled, the build will pause for this number of seconds after container startup.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void run_inside_pulled_container() throws Exception {
project.getBuildWrappersList().add(
new DockerBuildWrapper(
new PullDockerImageSelector("ubuntu:14.04"),
"", new DockerServerEndpoint("", ""), "", true, false, Collections.<Volume>emptyList(), null, "cat", false, "bridge", null, null, false)
"", new DockerServerEndpoint("", ""), "", true, false, Collections.<Volume>emptyList(), null, "cat", false, "bridge", null, null, false, false, 0)
);
project.getBuildersList().add(new Shell("lsb_release -a"));

Expand All @@ -52,7 +52,7 @@ public void run_inside_built_container() throws Exception {
project.getBuildWrappersList().add(
new DockerBuildWrapper(
new DockerfileImageSelector(".", "Dockerfile"),
"", new DockerServerEndpoint("", ""), "", true, false, Collections.<Volume>emptyList(), null, "cat", false, "bridge", null, null, true)
"", new DockerServerEndpoint("", ""), "", true, false, Collections.<Volume>emptyList(), null, "cat", false, "bridge", null, null, true, false, 0)
);
project.getBuildersList().add(new Shell("lsb_release -a"));

Expand All @@ -77,7 +77,7 @@ public void run_inside_built_python_pip_container() throws Exception {
project.getBuildWrappersList().add(
new DockerBuildWrapper(
new DockerfileImageSelector(".", "Dockerfile"),
"", new DockerServerEndpoint("", ""), "", true, false, Collections.<Volume>emptyList(), null, "cat", false, "bridge", null, null, true)
"", new DockerServerEndpoint("", ""), "", true, false, Collections.<Volume>emptyList(), null, "cat", false, "bridge", null, null, true, false, 0)
);
project.getBuildersList().add(new Shell("python -V"));

Expand Down