Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
654c9af
jenkins file
nastyak6 Aug 3, 2024
c0f6472
Merge branch 'zero-pytagoras:master' into nastya
nastyak6 Aug 3, 2024
127a3db
fix
nastyak6 Aug 3, 2024
de59fc0
X
nastyak6 Aug 3, 2024
ee3cc86
aa
nastyak6 Aug 3, 2024
1af5be5
s
nastyak6 Aug 3, 2024
5d1d6f4
fix path
nastyak6 Aug 3, 2024
2c96ba5
added docstring
nastyak6 Aug 3, 2024
c488768
change path
nastyak6 Aug 3, 2024
6ae1899
useing poetry
nastyak6 Aug 3, 2024
92ca427
python3.11
nastyak6 Aug 3, 2024
a963612
ss
nastyak6 Aug 3, 2024
a99f841
a
nastyak6 Aug 3, 2024
4c99340
s
nastyak6 Aug 3, 2024
6e31711
poetry env use python3.11# modified: Jenkinsfile
nastyak6 Aug 3, 2024
2af83ac
fa
nastyak6 Aug 3, 2024
b0418a0
gji
nastyak6 Aug 3, 2024
2a41f6d
jf
nastyak6 Aug 3, 2024
d66833d
label
nastyak6 Aug 3, 2024
a94885c
fd
nastyak6 Aug 3, 2024
ac6626c
sd
nastyak6 Aug 3, 2024
b70390a
dd
nastyak6 Aug 3, 2024
3ff9f4e
j
nastyak6 Aug 3, 2024
813e22f
.
nastyak6 Aug 3, 2024
728ef55
.
nastyak6 Aug 3, 2024
4660fb3
.
nastyak6 Aug 3, 2024
900234a
.
nastyak6 Aug 3, 2024
7f5f9b4
fl
nastyak6 Aug 3, 2024
0abd71b
j
nastyak6 Aug 3, 2024
1b860cc
x
nastyak6 Aug 3, 2024
20d5ebf
.
nastyak6 Aug 3, 2024
98af6ae
e
nastyak6 Aug 3, 2024
ec06224
.
nastyak6 Aug 3, 2024
c4efd0b
.
nastyak6 Aug 3, 2024
493d115
.
nastyak6 Aug 3, 2024
4ea6e39
.
nastyak6 Aug 3, 2024
9e56463
.
nastyak6 Aug 3, 2024
439dcf2
.
nastyak6 Aug 3, 2024
af3e87e
.
nastyak6 Aug 3, 2024
6ce23dd
.
nastyak6 Aug 3, 2024
32abdb5
.
nastyak6 Aug 3, 2024
36f1c43
pyinstaller = "^5.3"
nastyak6 Aug 3, 2024
cbbc28d
lock file
nastyak6 Aug 3, 2024
b0f3eff
3.11
nastyak6 Aug 3, 2024
73590dd
.
nastyak6 Aug 3, 2024
bc1217b
.
nastyak6 Aug 3, 2024
9a59b00
try method from lesson
nastyak6 Aug 3, 2024
e21cf5b
.
nastyak6 Aug 3, 2024
9a306fa
.
nastyak6 Aug 3, 2024
816c553
.
nastyak6 Aug 5, 2024
c1f5fa7
remove build
nastyak6 Aug 5, 2024
ddc2d74
.
nastyak6 Aug 5, 2024
05010fe
pipx
nastyak6 Aug 5, 2024
383ed9d
.
nastyak6 Aug 5, 2024
dcf95d9
.
nastyak6 Aug 5, 2024
38bb444
.
nastyak6 Aug 5, 2024
d9e22f1
.
nastyak6 Aug 5, 2024
3d91a60
.
nastyak6 Aug 5, 2024
78374f8
new
nastyak6 Aug 5, 2024
db2440b
.
nastyak6 Aug 5, 2024
b1e3d94
.
nastyak6 Aug 5, 2024
ffaa946
.
nastyak6 Aug 5, 2024
09f078f
lock
nastyak6 Aug 5, 2024
5f8319a
shellcheck
nastyak6 Aug 5, 2024
a4681cd
.
nastyak6 Aug 5, 2024
f62e7d9
.
nastyak6 Aug 5, 2024
648f00b
.
nastyak6 Aug 5, 2024
c435813
fix script
nastyak6 Aug 5, 2024
8d7a1a4
.
nastyak6 Aug 5, 2024
e825fdf
pytest
nastyak6 Aug 5, 2024
7978222
linting
nastyak6 Aug 5, 2024
2500012
details appp docker
nastyak6 Aug 5, 2024
9394e45
readme file
nastyak6 Aug 5, 2024
24d3069
pytest
nastyak6 Aug 5, 2024
8b72bf5
.
nastyak6 Aug 5, 2024
cf9b01b
Update README.md
nastyak6 Aug 5, 2024
77eceed
Update README.md
nastyak6 Aug 5, 2024
ad12a4d
Update README.md
nastyak6 Aug 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 76 additions & 54 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,64 +1,86 @@
pipeline{
agent {label 'workers'} // needs to have ssh agent
parameters{
string(name: 'sleep_time', defaultValue:'2', description:'time to sleep')
string(name: 'UNAME', defaultValue:'silentmobius', description:'docker_username')
string(name: 'PASSWD', description:'docker_password')
string(name: 'docker_image_name', defaultValue:'details_app', description:'docker image name')
string(name: 'docker_image_version', defaultValue:'latest', description:'docker image version')
string(name: 'registry_user', defaultValue:'silentmobius', description:'docker hub user')

}
stages{
stage('Pre-Build'){
steps{
echo 'Checking pre-requisites'
sleep "${sleep_time}"
sh'''
export PATH=$PATH:~/.local/bin
sudo apt-get update
sudo apt-get install -y wget curl python3 python3-poetry codespell
curl -L get.docker.com| sudo bash
poetry install
'''
pipeline {
agent any
stages {
stage('Pre-Build: Install Dependencies') {
steps {
script {
sh '''
# Update package lists and install system dependencies
sudo apt-get update
sudo apt-get install -y wget curl python3 python3-pip python3-venv shellcheck aspell

# Install Poetry
curl -sSL https://install.python-poetry.org | python3 -

# Add Poetry to PATH
export PATH="$HOME/.local/bin:$PATH"

# Configure Poetry to create and use virtual environments in the project directory
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true

if [ -f "poetry.lock" ]; then
poetry lock --no-update
else
echo "poetry.lock not found. Skipping lock file regeneration."
fi

poetry install
'''
}
}
}
stage('Spell Check') {
steps {
script {
sh '''
. .venv/bin/activate
aspell list < README.md > spelling_errors.txt

# fail the build if there are spelling mistakes
if [ -s spelling_errors.txt ]; then
echo "Spelling mistakes found. Failing the build."
cat spelling_errors.txt
exit 1
else
echo "No spelling mistakes found."
fi
'''
}
}
}
stage('Linter'){
steps{
echo 'Static code analysis check'
sleep "${sleep_time}"
sh '''
codespell app.py
'''
} // error app syntax --> fix the strings in app or bypass them
stage('Shellcheck') {
steps {
script {
sh '''
shellcheck build.sh
'''
}
}
}
stage('Build'){
steps{
echo 'Building the Project'
sleep "${sleep_time}"
sh '''
sudo docker build -t details-app:latest .
'''
} // error with builds clean up
stage('Test') {
steps {
script {
sh '''
. .venv/bin/activate
# poetry run pytest
'''
}
}
}
stage('Docker image Save'){
steps{
echo 'Testing'
sleep "${sleep_time}"
sh"""
sudo docker login -u ${UNAME} -p ${PASSWD}
sudo docker tag ${docker_image_name}:${docker_image_version} ${registry_user}/${docker_image_name}:${docker_image_version}
sudo docker push ${registry_user}/${docker_image_name}:${docker_image_version}
"""
stage('Build Docker Image') {
steps {
script {
sh '''
docker build -t details-app:latest .
'''
}
}
}
}// comment to check things
}
post {
success{
sh""""
docker save ${registry_user}/${docker_image_name}:${docker_image_version} -o "${docker_image_name}:${docker_image_version}.tgz"
"""
archiveArtifacts artifacts: 'details_app_docker.latest.tgz', followSymlinks: false, onlyIfSuccessful: true
always {
cleanWs()
}
}
}
81 changes: 68 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,75 @@
# Details App
# Jenkins Pipeline Configuration
![image](https://github.com/user-attachments/assets/d5ba7c2d-6c93-4f5e-ba47-39ddddeaf339)

Applications that can store your personal details and list all the written users on html

### Requirements:
## Description

- Python: 3.11
- SQLite3
- Bash Shell
- Docker
- Postgresql container needed
- Docker compose for multi container environment
- k3s for simple testing
- Virtualbox for k8s setup for more deep dive into world of container orchestrations
This repository contains a Jenkins pipeline configuration designed to automate several tasks related to Python development and Docker image building. The pipeline performs the following stages:

### Install
1. **Pre-Build: Install Dependencies**:
- Updates system packages.
- Installs essential system dependencies such as `wget`, `curl`, `python3`, `python3-pip`, `python3-venv`, `shellcheck`, and `aspell`.
- Installs and configures [Poetry](https://python-poetry.org/) for managing Python dependencies.

### Setup
2. **Spell Check**:
- Activates the virtual environment created by Poetry.
- Uses `aspell` to check for spelling mistakes in the `README.md` file.
- Fails the build if any spelling errors are found.

3. **Shellcheck**:
- Checks the syntax of shell scripts using `shellcheck`.
- Currently configured to check `build.sh`.

4. **Test**:
- Activates the virtual environment.
- Runs Python tests using `pytest`. (Note: This stage is currently commented out due to non existing pytests in the project.)

5. **Build Docker Image**:
- Builds a Docker image with the tag `details-app:latest` using a Dockerfile in the repository.

## What It Actually Does

The Jenkins pipeline automates the setup of the development environment, performs code quality checks (spell checking and shell script linting), and builds a Docker image. However, the pipeline faces a permission issue when attempting to build the Docker image.

## Identified Gaps

1. **Docker Permission Issue**:
- **Error**: `permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock`.
- **Cause**: The Jenkins user does not have the necessary permissions to access the Docker daemon.
- **Resolution**: Ensure the Jenkins user is added to the `docker` group and has appropriate permissions. Restart Jenkins and Docker services after making changes.

2. **Pytest Not Executing**:
- **Issue**: The `pytest` command is commented out in the pipeline configuration.
- **Resolution**: Add tests to ensure Python tests are executed.

## How to Use

1. **Set Up Jenkins**:
- Ensure Jenkins is installed and configured.
- Add Jenkins user to the Docker group: `sudo usermod -aG docker jenkins`.
- Restart Jenkins: `sudo systemctl restart jenkins`.

2. **Configure Pipeline**:
- Copy the Jenkins pipeline configuration into a Jenkinsfile and place it in the repository.

3. **Build Docker Image**:
- Ensure that Docker is running and accessible.
- Verify that all required system dependencies are installed.

4. **Run Pipeline**:
- Trigger the Jenkins pipeline to execute the defined stages.

## Installation and Running Instructions

Clone the repository:

```sh
git clone https://github.com/nastyak6/details-app/tree/nastya


Contributors

Anastasia Kokin
Charlie Haimov

No Mamon agreement, so 50-50 it is :)
4 changes: 3 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
# Version: 0.0.1
# Date: 14.06.2024
#################################################
APP_VERSION=${1:'0.0.1'}
APP_VERSION=${1:'0.0.1'}

echo "$APP_VERSION"
43 changes: 43 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
services:
main:
hostname: jenkins_main
build:
context: .
dockerfile: Dockerfile.main
ports:
- "80:8080"
networks:
- jenkins
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ../jenkins_data:/var/jenkins_home

worker1:
hostname: jenkins_worker1
build:
context: .
dockerfile: Dockerfile.deb.worker

networks:
- jenkins
environment:
SSH_USERNAME: jenkins
SSH_USERPASS: jenkins
volumes:
- /var/run/docker.sock:/var/run/docker.sock

worker2:
hostname: jenkins_worker2
build:
context: .
dockerfile: Dockerfile.rpm.worker

networks:
- jenkins
environment:
SSH_USERNAME: jenkins
SSH_USERPASS: jenkins
volumes:
- /var/run/docker.sock:/var/run/docker.sock
networks:
jenkins:
Loading