Last active
August 2, 2021 00:23
-
-
Save ndeloof/d701cbe1b11deb07dcef729776736361 to your computer and use it in GitHub Desktop.
dockerNode without remoting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stage 'build' { | |
withDocker(image: 'node_js:4.4', | |
environment: [foo: 'bar'], | |
volumes: [node_cache: '/node_modules'], | |
commands: """ | |
npm install | |
npm test | |
... | |
""", | |
stash: [jar: '/dist/app.tar.gz']) | |
get actually executed as : | |
# Create volume | |
id=sha(jobID+node_cache) | |
docker volume inspect $id | |
# if none exists | |
node_cache = ${docker volume create $id} | |
# create container | |
container = $(docker create -v $node_cache:/node_modules node_js:4.4 /tmp/command.sh) | |
# create command script | |
echo $commands > docker cp - container:/tmp/command.sh | |
# run container | |
docker start -d container | |
# container is ran detached, so we don't need longRunningTask hack and status polling. | |
# wait for container to stop | |
# (a single process could listen to all docker 'stop|die' events then dispatch to running pipelines) | |
docker events --filter container=$container | |
# if jenkins has been restarted, pipeline resume would need to check container status | |
docker inspect container=$container | |
# pipe logs info web console for live view | |
docker logs -f $container | |
# stash | |
docker cp $container:/dist/app.tar.gz some_path_on_master | |
For actual usage in a pipeline, will also need some : | |
def workspace = dockerVolume() | |
withDocker(image: 'git'), | |
volumes: [workspace: '/work'], | |
workdir:'/work', | |
commands: "git clone $scm") | |
could be made simpler : | |
(def workspace = ) dockerVolume($scm) | |
such a workspace volume could be implicitely bound to all subsequent containers in pipeline. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment