In this workshop we learn to use some tools and applications to create a continuous delivery pipeline. We use a dev instance in AWS to prevent local issues with our laptops. This dev machine also has a high speed internet connection, so downloading images won't delay our learning process.
- Git
- Docker
- Docker-Compose
- Jenkins
- XL Deploy
- XL Release
Look into the some files of this repository:
- ./dockerfiles/jenkins/Dockerfile
- ./dockerfiles/xldeploy/Dockerfile
- ./dockerfiles/xlrelease/Dockerfile
- ./dockerfiles/dummy/Dockerfile
- ./docker-compose.yml
gitlab:
build: dockerfiles/gitlab/. <- location of the Dockerfile
container_name: gitlab <- name of the container to access the service
ports:
- "8090:80" <- docker_host_mapped_port:container_exposed_port
Open link in your e-mail.
Connect to your personal dev instance.
Windows
If you have a Windows machine ensure Putty and Puttygen are installed and use this procedure to convert the pem file to a ppk file. In case you received a ppk file from the instructor, start at 2.
- Start Puttygen, import pem file, save private key file
- Start Putty
- Enter Host Name (or IP address): ec2-user@IPADDRESS
- Connection > SSH > Auth > Private key file.. Browse to file and select *.ppk file.
- [Open]
- Accept the host
sudo su -
Linux
Save the pem file received and update the IPADDRESS.
ssh -i ~/path/to/CDWORKSHOP.pem ec2-user@IPADDRESS
sudo su -Lets play around with some docker commands. Remember you must be root to use Docker (sudo su -).
# try some docker commands
docker
docker ps
docker status
docker info
docker run hello-world
# Run a container in the background
docker run --name some-nginx -d -p 80:80 nginx
docker ps
docker images
curl localhost
# and try the http://ipaddress.xip.io in your browser
docker ps
# replace the 2bca.. for the id of the container
# of the previous command.
docker stop 2bcad
docker rm 2bcad
docker rmi nginx
# and finally run docker-compose to check out the options
docker-compose mkdir /var/work
cd /var/work
git clone https://github.com/martijnvandongen/cdworkshop.git
# before exec next command, get url from e-mail replace the 1234abcd24234
# make sure the last word "credentials" name remains (target folder)
cd /var/work
git clone https://gist.github.com/martijnvandongen/1234abcd24234 credentialsYour current working directories look like:
[root@ip-172-31-1-116 work]# pwd
/var/work
[root@ip-172-31-1-116 work]# tree
.
├── cdworkshop
│ ├── cloudformation
│ │ └── devmachines.json
│ ├── docker-compose.yml
│ ├── dockerfiles
│ │ ├── dummy
│ │ │ ├── Dockerfile
│ │ │ ├── index.html
│ │ │ └── start.sh
│ │ ├── gitlab
│ │ │ ├── Dockerfile
│ │ │ └── gitlab.rb
│ │ ├── jenkins
│ │ │ └── Dockerfile
│ │ ├── xldeploy
│ │ │ ├── Dockerfile
│ │ │ └── xldeploy.answers
│ │ └── xlrelease
│ │ ├── Dockerfile
│ │ └── xlrelease.answers
│ ├── readme.md
│ └── scripts
│ ├── provision.sh
│ ├── xlrelease.json
│ └── xlreleasesed.json
└── credentials
├── xldeploy.txt
└── xlrelease.txt
10 directories, 28 files
cd /var/work/cdworkshop
docker-compose up -d
#watch logging and wait until every application is booted
docker-compose logsNow each container can access other containers by the name and the exposed port. (See table for details)
Try to login to the several applications. Remember your applications are only accessible with the right IP-addresses and everything will be removed after the workshop.
- Public URLs should be accessible through your local webbrowser and mapped ports.
- From the dev machine, actually a docker host, you can access each container on mapped ports.
- Containers can access eachother by container name and the exposed ports.
| Application | Public | Docker Host | Container | User | Password |
|---|---|---|---|---|---|
| XL Deploy | http://youripaddress.nip.io:4516 | http://localhost:4516 | http://xldeploy:4516 | admin | password |
| XL Release | http://youripaddress.nip.io:5516 | http://localhost:5516 | http://xldeploy:5516 | admin | password |
| Jenkins | http://youripaddress.nip.io:8080 | http://localhost:8080 | http://jenkins:8080 | N/A | N/A |
| Gitlab | http://youripaddress.nip.io:8090 | http://localhost:8090 | http://gitlab | root | password |
| Target | http://youripaddress.nip.io | http://localhost:80 | http://dummy | N/A | N/A |
In this part we'll configure Gitlab, Jenkins, XL Deploy and XL Release manually. If you want to skip this part, go to the next chapter where (almost) everything is configured automatically.
Lets first start with a repo and add our example website to it.
- Login to Gitlab
- Create a new project with project name "website" public
cd /var/workgit clone http://localhost:8090/root/website.gitcd websitecp /var/work/cdworkshop/dockerfiles/dummy/index.html .git add . && git commit -am "auto" && git push- Authenticate with
rootandpassword - Verify through the web interface
Now create a Jenkins job which gets the source from gitlab, creates a package and upload it to XL Deploy. (No trigger in Jenkins, it's done with XLR, and no deploy with Jenkins, this trigger will be sent by XLR)
- Login to Jenkins
- Manage Jenkins > Configure System, enter XL Deploy: http://xldeploy:4516 / admin / admin / password
- Create new jobs (Name: buildwebsite, type: Freestyle Project)
- Enable Source Code Management: Git
- Repository URL: http://gitlab/root/website.git
- Skip Build Steps
- Add Post-build Action: Deploy with XL Deploy
- Select Global server credential
- Application: Applications/website
- Version: $BUILD_NUMBER
- Check Package application > Add artifact
- Deployable Type: file.File, Name: index.html, Location: index.html
- Add property: targetPath=/var/www/html
- Check Publish package to XL Deploy, Generated
- [SAVE]
Now configure XL Deploy, create the whole infrastructure.
- Create Applications/website (Application)
- Create Applications/website/examplepackage (Deployment Package)
- Create Applications/website/examplepackage/index.html (Type: file.File Target Path: /var/www/html)
- Create Infrastructure/target (see table below)
- [Check Connection]
- Create Environments/target, select the infrastructure component
- Test a deployment manually
| Key | Value |
|---|---|
| Operating System | UNIX |
| Connection Type | SCP |
| Address | dummy |
| Port | 22 |
| Username | root |
| Password | password |
- Add XL Deploy Server to XL Release
- Add XL Deploy: http://xldeploy:4516
- Add Git Repository: http://gitlab/root/website.git
- Add Jenkins: http://jenkins:8080
- Create New Template
- Add ${version} variable (uncheck both boxes, other fields default)
- Add Jenkins Build step (job name: buildwebsite, build number: ${version})
- Add XL Deploy Step (package: website/${version}, Environment: target)
- Add Trigger Git:Poll
- Title: Git Commit, Release Title: Automated Release ${commitId}, Enabled: True.
When change something in the source code, xl release is triggered. Keep all Windows open and see/show what happens.
cd /var/work/website
vi index.html
# change some contents of the html
git add .
git commit -am "some comment for your commit"
git push
# enter credentials root / passwordIf we have time left, add a task to XL Release template with JSON Webhook to verify the website we are deploying at: http://IPADDRESS/test.json.
Add this file to the build definition in Jenkins. Add the file in the GIT repo with the expected json. If the test failed, make it right. If the test succeeded, brake it.
Normally in a later stage of the CD process, this simple test will be replaced for more complex tasks and tools.
In case you run locally with docker, you should clean up:
cd /var/work/cdworkshop
docker-compose down
To provision most of the things from the manual configuration chapter, execute the following command.
./provision.shAfter this script ran, do some manual actions.
TODO
This is just for the instructor to setup the platform and send an e-mail with some web links and the pem file to connect.
- Create a key pair
- Upload and execute ./cloudformation/devinstances.json
- Add some source ip addresses to the security group
- Add users-and-ipaddresses.txt
- Create a gist.github.com repo secret
git clone gitrepo credentials- Copy resource files in folder
git add . && git commit -am "auto" && git push- Send e-mail:
pem file
link to https://github.com/martijnvandongen/cdworkshop
link to gist http url
list with names and public IP addresses