mirror of
https://github.com/simon987/task_tracker_drone.git
synced 2025-04-04 07:52:59 +00:00
Jenkins setup
This commit is contained in:
parent
d65b166ed7
commit
64032a22ea
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
.idea/
|
||||
work/
|
||||
env/
|
||||
worker.json
|
||||
__pycache__/
|
6
README.md
Normal file
6
README.md
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
|
||||
### Running tests
|
||||
```bash
|
||||
python -m unittest discover
|
||||
```
|
33
jenkins/Jenkinsfile
vendored
Normal file
33
jenkins/Jenkinsfile
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
def remote = [:]
|
||||
remote.name = 'remote'
|
||||
remote.host = 'localhost'
|
||||
remote.user = 'simon'
|
||||
remote.identityFile = '/var/lib/jenkins/.ssh/id_rsa'
|
||||
remote.knownHosts = '/var/lib/jenkins/.ssh/known_hosts'
|
||||
|
||||
pipeline {
|
||||
agent any
|
||||
stages {
|
||||
stage('Build') {
|
||||
steps {
|
||||
sh './jenkins/build.sh'
|
||||
stash includes: 'env/', name: 'env'
|
||||
}
|
||||
}
|
||||
stage('Test') {
|
||||
steps {
|
||||
unstash 'env'
|
||||
sh 'bash -c "source env/bin/activate && cd src && python -m unittest discover"'
|
||||
}
|
||||
}
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
unstash 'env'
|
||||
sshPut remote: remote, from: 'env', into: 'task_tracker_drone'
|
||||
sshPut remote: remote, from: 'jenkins/deploy.sh', into: 'task_tracker_drone/deploy.sh'
|
||||
sshPut remote: remote, from: 'src', into: 'task_tracker_drone'
|
||||
sshCommand remote: remote, command: 'chmod +x task_tracker_drone/deploy.sh && ./task_tracker_drone/deploy.sh'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
9
jenkins/build.sh
Executable file
9
jenkins/build.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
virtualenv env --download --always-copy --clear -p python3.7
|
||||
source env/bin/activate
|
||||
python --version
|
||||
|
||||
pip install -r requirements.txt
|
||||
deactivate
|
||||
|
9
jenkins/deploy.sh
Executable file
9
jenkins/deploy.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
export DRONEROOT="task_tracker_drone"
|
||||
|
||||
screen -S tt_drone -X quit
|
||||
echo "starting drone"
|
||||
screen -S tt_drone -d -m bash -c "cd ${DRONEROOT} && source env/bin/activate && python src/tt_drone/drone.py"
|
||||
sleep 1
|
||||
screen -list
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
||||
requests
|
0
src/tt_drone/__init__.py
Normal file
0
src/tt_drone/__init__.py
Normal file
20
src/tt_drone/drone.py
Normal file
20
src/tt_drone/drone.py
Normal file
@ -0,0 +1,20 @@
|
||||
import signal
|
||||
import time
|
||||
|
||||
die = False
|
||||
|
||||
|
||||
def cleanup(signum, frame):
|
||||
global die
|
||||
die = True
|
||||
|
||||
|
||||
signal.signal(signal.SIGINT, cleanup)
|
||||
signal.signal(signal.SIGTERM, cleanup)
|
||||
|
||||
while True:
|
||||
time.sleep(1)
|
||||
print("tick")
|
||||
if die:
|
||||
break
|
||||
|
0
src/tt_drone/test/__init__.py
Normal file
0
src/tt_drone/test/__init__.py
Normal file
10
src/tt_drone/test/test_worker.py
Normal file
10
src/tt_drone/test/test_worker.py
Normal file
@ -0,0 +1,10 @@
|
||||
import unittest
|
||||
|
||||
|
||||
class WorkerTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def test_true(self):
|
||||
self.assertTrue(True)
|
@ -1,11 +1,13 @@
|
||||
import datetime
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
import shutil
|
||||
import subprocess
|
||||
import time
|
||||
from subprocess import Popen
|
||||
|
||||
from api import Project, Worker, TaskTrackerApi, Task
|
||||
from tt_drone.api import Project, Worker, TaskTrackerApi, Task
|
||||
|
||||
|
||||
class WorkerContext:
|
||||
@ -86,3 +88,19 @@ class WorkerContext:
|
||||
print("SUBMIT: %s <%d>" % (task, r.status_code))
|
||||
|
||||
|
||||
api = TaskTrackerApi("https://tt.simon987.net/api")
|
||||
w1 = Worker.from_file(api)
|
||||
ctx = WorkerContext(w1, "main")
|
||||
|
||||
while True:
|
||||
try:
|
||||
t = w1.fetch_task()
|
||||
ctx.execute_task(t)
|
||||
|
||||
time.sleep(random.randint(5, 45))
|
||||
except KeyboardInterrupt:
|
||||
print("Cancel current task...")
|
||||
try:
|
||||
w1.release_task(t.id, 2, 0)
|
||||
except NameError:
|
||||
pass
|
Loading…
x
Reference in New Issue
Block a user