Task 04. Setup CI/CD for WordPress with containers using Jenkins.
Task
1. Repository
- Fork repository for task04 and clone forked repo.
- Fork repository with thank-after-post WordPress plugin and clone forked repo.
2. Start up local jenkins from repository
- Set proper values for
.env
file: In.env
file change value of SEED_JOBS_URL variable to url of your forked repo. This repo would be used to store your pipeline configuration changes. - Start jenkins server: On your cloned repository from task 4 start docker-compose.
3. Create manual job to add tags to wordpress plugin.
- Create your first Jenkins job:
You should create job that will take two string parameters:
plugin_url
- it will be used to point to repo for your plugin URLnew_tag
- new version of plugin that you can set manualy
Job should do following:
- Clone repository of your
thank-after-post
forked repo - Get the latest tag
- Increment minor version of the tag. For examle, you had tag
v0.9.0
then next version should bev0.10.0
. For more info check this site - Uag repo with incremented version and push to remote
- Trigger
deploy_dev
pipeline and setplugin_version
as your updated version,git_url
- repo ofthank-after-post
plugin.
4. Update pipeline deploy_dev
.
4.1. Update build_wp_image
stage.
- Build docker wordpress image with newly created plugin: build wordpress image with provided version of plugin.
- Push docker wordpress image with plugin to Docker Hub
4.2. Run docker-compose with new wordpress image.
Configure this stage to do following things:
- On the repo from task 02 update
docker-compose.yaml
file, so that exposed port on wordpress and image version of the wordpress would be readed from environment variable. For more help check out this page. - Clone repo from task 02.
- export variable for wordpress tag from
plugin_version
- Export variable for exposed port by wordpress on dev enivronment. For example:
81
- Run
docker-compose
in detached mode, so that you are able to login to started wordpress blog.
4.3. Run tests.
- Run container with tests that you created for task 03 to test that new plugin was successfully deployed on wordpress.
4.4. Clean dev environment.
- Run
docker-compose down -v
for dev environment
5. Create deploy_prod
pipeline.
-
Copy
deploy_dev
job configuration: copy filejob_configs/deploy_dev.groovy
todeploy_prod
. And make proper changes in this file. -
Copy
deploy_dev
job: copy filejobs/deploy_dev.groovy
todeploy_prod
. And make proper changes in this file. -
Input parameters should be same as for
deploy_dev
pipeline -
Key difference in
deploy_prod
fromdeploy_dev
:- exposed port should be
80
, not81
.
- exposed port should be
4.5. Add trigger to start deploy_prod
from deploy_dev
6. Make your work visible
- Create Pull Request with all changes for task 4.
- Create Pull Request with all changes for task 3.
Additional tasks if you feel that it was too easy.
- N/A
Tips:
- Take your time to understand how jenkins work.
- If you check out job configuration
scriptPath
it reads file. This file is also calledJenkinsfile
. - After jenkins creation there would be only one
z_seed_job
in dashboard. To load all your pipelines you should run this job. - To check your changes to any stage you need to commit and push your changes to the repo.
- If you make changes to job configuration (for example create new
deploy_prod
pipeline) you need to commit and push your changes, then to runz_seed_job
manualy. - If you make changes to job, you only need to commit and push changes to repo and just manualy trigger
deploy_dev
job.
Recommended soft:
Useful links:
- Job configuration manual
- Jenkins configuration examples
- Docker Quickstart
- Overview of Docker Compose
- Selenium with Python
FAQ
- N/A