The goal of this workshop is to setup a simple CI server. Furthermore, you will engage in hands-on exploration of docker. Several docker-related concepts and tasks are investigated.
- You will need a computing environment with docker and nodejs. You can follow the computing environments workshop if you have not setup a virtual environment/vagrant yet.
Clone this repo. Run baker bake
.
Create a virtual machine, then install.
The recommended method for installing docker on ubuntu can be found here. But in the interest of time: ๐ฌ :
curl -sSL https://get.docker.com/ | sh
After installation, it is recommended you allow docker to be run without needing sudo. IMPORTANT You'd need to restart your shell (exit and log back in) to see the changes reflected.
sudo usermod -aG docker $(whoami)
Verify you can run docker:
docker run hello-world
- A docker image contains a set of layers which describe stateful changes to the environment.
- An image can be based on other base images.
- A container is an instance of image.
- Containers are generally stateless, that is any change to a container has no effect on its image; however, you can commit a change to a new image.
- A docker container only stays alive as long as there is an active process being run in it.
We'll explore some of these concepts below.
Build a docker environment for running build. Create a "Dockerfile" and place this content inside:
FROM ubuntu:16.04
MAINTAINER Chris Parnin, [email protected]
RUN apt-get -y update
# update packages and install
RUN apt-get install -y wget openjdk-8-jdk curl unzip
RUN apt-get -y install git
RUN apt-get -y install maven
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
Build the docker image
sudo docker build -t ncsu/buildserver .
See what images are current available on the machine.
sudo docker images
Verify image works and can run a maven command.
sudo docker run -it ncsu/buildserver mvn --version
Run an interactive terminal.
sudo docker run -it ncsu/buildserver
Inside docker
ls
rm -rf --no-preserve-root /
exit
Check if its still there.
sudo docker run -it ncsu/buildserver
Look at all the containers you've created by running commands above.
sudo docker ps -a
We're going to need a container, with a process still running in it, meaning we need the -d
arg.
sudo docker run -it -d ncsu/buildserver
This will show you last container id created.
sudo docker ps -l
Let's take last container, and update it.
sudo docker exec -it 674183b76a10 script /dev/null -c "echo 'Hello' > foo.txt"
Make sure we can see change:
docker exec -it 674183b76a10 ls
Now, let's commit this to our image.
docker commit 674183b76a10 ncsu/buildserver
Now, any new container created from this image will have the new chanage.
In your host VM, create 'build.sh' and place the following inside:
git clone https://github.com/CSC-326/JSPDemo
cd JSPDemo
git checkout HEAD~2
mvn compile -DskipTests -Dmaven.javadoc.skip=true
Execute script
chmod +x build.sh
sudo docker run -v /home/<username>/:/vol ncsu/buildserver sh -c /vol/build.sh
Success!
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 5 source files to /JSPDemo/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 24.570s
[INFO] Finished at: Mon Mar 14 22:34:35 UTC 2016
[INFO] Final Memory: 12M/30M
[INFO] ------------------------------------------------------------------------
Let's create a simple server to trigger a build server.
Note: If you did not use baker to create your VM, you'll have to manually install node.js on your VM.
Extend server.js to run a build when a http request is made.
var exec = require('child_process').exec;
var cmd = 'YOUR docker command';
Run node server.js
when you're ready.
- Find the ip of your host VM (
ifconfig
). - In your browser, visit
http://192.168.28.28:8080
, and trigger a build. - You will see the results eventually stream over to the webpage.