AlbanAndrieu.ansible_jenkins_slave_docker
Jenkins slave Docker image
// spell-checker:disable
Table of contents
- Initialize
- Requirements
- Usage
- Folder Structure Conventions
- Dependency Graph
- mega-linter
- Check secret
- Check cspell
- Update README.md
- License
- Contact
// cSpell:enable
Initialize
direnv allow
pyenv install 3.10.4
pyenv local 3.10.4
python -m pipenv install --dev --ignore-pipfile
direnv allow
pre-commit install
Requirements
- Requires Ansible core 2.13.2 or newer
- Expects Ubuntu
This playbook deploy a very basic jenkins slave with all the required tool needed for a developper or buildmaster or devops to work on NABLA projects. This playbook is be used by Docker Hub to create a Docker image.
Goal of this project is to integrate of several roles done by the community. Goal is to contribuate to the community as much as possible instead of creating a new role. Goal is to ensure following roles (GIT submodules) to work in harmony.
python 3.8
Install python 3.8 and virtualenv
virtualenv --no-site-packages /opt/ansible/env38 -p python3.8
source /opt/ansible/env38/bin/activate
pip install -r requirements-current-3.8.txt
Install AWS cli
# Since Ubuntu 22
sudo snap remove aws-cli
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
/usr/local/bin/aws --version
# aws-cli/2.7.16 Python/3.9.11 Linux/5.15.0-40-generic exe/x86_64.ubuntu.22 prompt/off
# In ~/.docker/config.json remove credStore
pre-commit
See pre-commit
Run pre-commit install
First time run cp hooks/hooks/* .git/hooks/
or git clone [email protected]:AlbanAndrieu/nabla-hooks.git hooks && rm -Rf ./.git/hooks && ln -s ../hooks/hooks ./.git/hooks
Run pre-commit run --all-files
Run SKIP=ansible-lint git commit -am 'Add key'
Run git commit -am 'Add key' --no-verify
// cSpell:words formating Jenkinsfile
npm-groovy-lint groovy formating for Jenkinsfile
Tested with nodejs 12 and 16 on ubuntu 20 and 21 (not working with nodejs 11 and 16)
npm install -g npm-groovy-lint@8.2.0
npm-groovy-lint --format
ls -lrta .groovylintrc.json
Usage
Run the playbook, like this:
ansible-playbook playbooks/python-bootstrap.yml -i inventory/hosts --limit localhost -c local --ask-become-pass -vvvv
ansible-playbook -i inventory/hosts -c local -v jenkins-slave-docker.yml -vvvv
#or
setup.sh
Create the docker hub image, like this:
docker build -f docker/ubuntu18/Dockerfile -t "nabla/ansible-jenkins-slave-docker" . --no-cache --tag "latest"
or
./scripts/docker-build.sh
Run Jenkins See https://github.com/jenkinsci/parallel-test-executor-plugin/tree/master/demo
docker volume create --name=m2repo
sudo chmod a+rw $(docker volume inspect -f '{{.Mountpoint}}' m2repo)
docker run --rm -p 127.0.0.1:8080:8080 -v m2repo:/m2repo -v /var/run/docker.sock:/var/run/docker.sock --group-add=$(stat -c %g /var/run/docker.sock) -ti jenkinsci/parallel-test-executor-demo
Use the docker hub image, like this:
#Pull image
docker pull nabla/ansible-jenkins-slave-docker
#Start container
docker run -ti -d -w /sandbox/project-to-build -v /workspace/users/albandri30/:/sandbox/project-to-build:rw --name sandbox nabla/ansible-jenkins-slave-docker:latest cat
#Build
docker exec sandbox /opt/maven/apache-maven-3.5.0/bin/mvn -B -Djava.io.tmpdir=./tmp -Dmaven.repo.local=/home/jenkins/.m2/.repository -Dmaven.test.failure.ignore=true -s /home/jenkins/.m2/settings.xml -f nabla-servers-bower-sample/pom.xml clean install
#Stop & remove container
docker stop sandbox
docker rm sandbox
When the playbook run completes, you should be able to build and test any NABLA projects, on the using the docker image in Jenkins with Jenkins Docker plugin.
This is a very simple playbook and could serve as a starting point for more complex projects.
Linting
ansible-lint --write playbooks/
ansible-lint -v playbooks/*.yml
Ideas for improvement
Here are some ideas for ways that these playbooks could be extended:
- Feel free to ask.
We would love to see contributions and improvements, so please fork this repository and send us your changes via pull requests.
Folder Structure Conventions
Folder structure options and naming conventions for software projects
A typical top-level directory layout
.
├── docs # Documentation files (alternatively `doc`)
docker # Where to put image Dockerfile
├── scripts # Source files
├── inventory
│ production
├── playbooks # Ansible playbooks
├── roles # Ansible roles
bower.json # Bower not build directly, using maven instead
Dockerfile # A link to default Dockerfile to build (DockerHub)
Jenkinsfile
package.json # Nnpm not build directly, using maven instead
pom.xml # Will run maven clean install
.pre-commit-config.yaml
requirements.testing.txt # Python package used for test and build only
requirements.txt # Python package used for production only
requirements.yml # Ansible requirements, will be add to roles directory
tox.ini
sonar-project.properties # Will run sonar standalone scan
LICENSE
CHANGELOG.md
README.md
└── target # Compiled files (alternatively `dist`) for maven
docker directory is used only to build project
.
├── ...
├── docker # Docker files used to build project
│ ├── centos7 # End-to-end, integration tests (alternatively `e2e`)
│ ├── ubuntu18 # End-to-end, integration tests (alternatively `e2e`)
│ └── ubuntu20
│ Dockerfile # File to build
│ config.yaml # File to run CST
└── ...
.
├── ...
├── docs # Documentation files
│ ├── index.rst # Table of contents
│ ├── faq.rst # Frequently asked questions
│ ├── misc.rst # Miscellaneous information
│ ├── usage.rst # Getting started guide
│ └── ... # etc.
└── ...
.
├── ...
├── packs # Files used to build docker image and chart
│ config.yaml # File to run CST
│ Dockerfile # File to build docker image
│ └── jenkins-slave # Name of the helm chart
│ └── charts
│ Chart.yaml
│ README.md
│ └── templates
│ deployment.yaml
│ └── tests
│ test-connection.yaml
│ values.yaml
Dependency Graph
Python 3.8 graphviz
python3 ./docs/files/ansible-roles-dependencies.py
mega-linter
npx mega-linter-runner
Check secret
npx @secretlint/quick-start "**/*"
Check cspell
npx cspell "**/*.{txt,js,md}"
Update README.md
npm install -g markdown-toc
markdown-toc README.md
markdown-toc CHANGELOG.md -i
git add README.md
pre-commit run markdown-toc
Contributing
The issue tracker is the preferred channel for bug reports, features requests and submitting pull requests.
For pull requests, editor preferences are available in the editor config for easy use in common text editors. Read more and download plugins at http://editorconfig.org.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests and examples for any new or changed functionality.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
Authors and license
roles/alban_andrieu_jenkins_slave role was written by:
- Alban Andrieu | e-mail | Twitter | GitHub
License
- License: GPLv3
Feedback, bug-reports, requests
Are welcome!
This role is part of the Nabla project. README generated by Ansigenome.
Contact
Alban Andrieu
ansible-galaxy install AlbanAndrieu.ansible_jenkins_slave_docker