Compare commits

...

12 Commits

Author SHA1 Message Date
Pavel Dmitriev 623ec65fff Merge pull request 'ci added' (#5) from ci-test into develop
continuous-integration/drone/push Build is failing Details
Reviewed-on: #5
2023-02-09 15:32:42 +03:00
Pavel Dmitriev a5f83400ec ci added
continuous-integration/drone/push Build is failing Details
2023-02-08 20:49:28 +03:00
Pavel Dmitriev 624cbc95b0 python version 2023-02-08 20:40:05 +03:00
Pavel Dmitriev 11f4059a3b vhost fix
continuous-integration/drone/push Build is passing Details
2023-01-22 11:49:15 +03:00
Pavel Dmitriev 983ffcf445 ci fix
continuous-integration/drone/push Build is passing Details
2023-01-22 11:37:32 +03:00
Pavel Dmitriev a86fb52fd3 drone fix
continuous-integration/drone/push Build is failing Details
2023-01-22 11:35:31 +03:00
Pavel Dmitriev 868753ed8c sonar fix
continuous-integration/drone/push Build is failing Details
2023-01-22 11:34:09 +03:00
Pavel Dmitriev b4ec5c915b sonar fix
continuous-integration/drone/push Build is failing Details
2023-01-22 11:32:29 +03:00
Pavel Dmitriev 8fb0336a3c fix2
continuous-integration/drone/push Build is failing Details
2023-01-22 11:21:37 +03:00
Pavel Dmitriev 856068d61f fix
continuous-integration/drone/push Build was killed Details
2023-01-22 11:18:02 +03:00
Pavel Dmitriev 55a3b08e81 ci-test
continuous-integration/drone Build is failing Details
2023-01-22 11:08:08 +03:00
Pavel Dmitriev a359883a74 CI test 2023-01-22 09:21:15 +03:00
5 changed files with 186 additions and 0 deletions

70
.drone.yml Normal file
View File

@ -0,0 +1,70 @@
---
kind: pipeline
name: SonarQube check
image_pull_secrets:
- dockerconfig
trigger:
branch:
- develop
- ci-test
event:
- push
- custom
steps:
- name: SonarQube check
image: sonarsource/sonar-scanner-cli
environment:
SONAR_PROJECT:
from_secret: sonarProjectId
SONAR_TOKEN:
from_secret: sonarToken
SONAR_HOST:
from_secret: sonarHost
TEST: test
commands:
- sonar-scanner -Dsonar.projectKey=$${SONAR_PROJECT} -Dsonar.sources=. -Dsonar.host.url=$${SONAR_HOST} -Dsonar.login=$${SONAR_TOKEN}
depends_on:
- clone
---
kind: pipeline
name: Build image
image_pull_secrets:
- dockerconfig
trigger:
ref:
- refs/heads/ci-test
- refs/heads/testing
- refs/heads/master
- refs/tags/*
steps:
- name: Build docker image
image: mxfox.ru/mxfox/docker-dind.buildx:latest
privileged: true
environment:
DOCKER_AUTH:
from_secret: dockerconfig
IMAGE_PREFIX: mxfox.ru/mxfox/barcode-scanner-client
commands:
- buildx-bgstart.sh
- echo $${DOCKER_AUTH} > ~/.docker/config.json
- echo "CB ${CI_COMMIT_BRANCH}"
- echo "DT ${DRONE_TAG}"
- |
if [ -n "${DRONE_TAG}" ]
then
export xBuildSuffix=" -t $${IMAGE_PREFIX}:${DRONE_TAG} -t $${IMAGE_PREFIX}:latest --push"
else
export xBuildSuffix=" -t $${IMAGE_PREFIX}:${CI_COMMIT_BRANCH}-${CI_BUILD_NUMBER}-${DRONE_COMMIT_SHA:0:10} -t $${IMAGE_PREFIX}:${CI_COMMIT_BRANCH} --push"
fi
- docker buildx build --platform linux/arm,linux/amd64,linux/arm64 . $${xBuildSuffix}

5
Dockerfile Normal file
View File

@ -0,0 +1,5 @@
FROM python:3
WORKDIR /foxScanner
COPY . .
RUN pip install --no-cache-dir -r requirements
CMD ["python","scanner.py"]

View File

@ -1,2 +1,10 @@
# foxBarcodeScannerClient # foxBarcodeScannerClient
Клиент для работы со сканером штрих-кода через последовательный порт. Клиент получает данные со сканера и отправляет в очередь RabbitMQ, указанную при регистрации. Регистрация происходит через считывания специального штрих-кода.
## Параметры конфигурации
* SCANNER_PORT - /dev/ttyACM0
* RABBITMQ_HOST
* RABBITMQ_USER
* RABBITMQ_PASSWORD
* RABBITMQ_USE_SSL

2
requirements Normal file
View File

@ -0,0 +1,2 @@
pyserial
pika

101
scanner.py Executable file
View File

@ -0,0 +1,101 @@
#!/usr/bin/python3
import serial
import time
import codecs
import re
import pika
import json
import os
import hashlib
# docker run -v "`pwd`:/src:ro" --device "/dev/ttyACM0:/dev/ttyACM0" -e "RABBIT_HOST=100.64.240.14" -e "RABBIT_PORT=5672" -e "RABBIT_USER=guest" -e "RABBIT_PASSWORD=itrw8pyNK8a7hipM" -e "RABBIT_USESSL=false" -e "RABBIT_EXCHANGE=fox.barcode" -e "ALLOW_SHORT_PAIRING_TAG=true" -e "ALLOW_LONG_PAIRING_TAG=true" -ti python:3 bash
# pip install --no-cache-dir -r list.txt
# pip3 install serial
# pip3 install pika
scannerPort=os.environ.get('SCANNER_PORT', "/dev/ttyACM0")
pingTimeout=os.environ.get('PING_TIMEOUT', 5)
rabbitHost=os.environ.get('RABBIT_HOST', None)
rabbitPort=os.environ.get('RABBIT_PORT', 5672)
#rabbitUser="guest"
rabbitUser=os.environ.get('RABBIT_USER', None)
#rabbitPass="itrw8pyNK8a7hipM"
rabbitPass=os.environ.get('RABBIT_PASSWORD', None)
rabbitSSL=os.environ.get('RABBIT_USE_SSL', "false").lower()=="true"
rabbitExchange=os.environ.get('RABBIT_EXCHANGE', "fox.barcode")
allowShortPairingTag=os.environ.get('ALLOW_SHORT_PAIRING', "true").lower()=="true"
allowLongPairingTag=os.environ.get('ALLOW_LONG_PAIRING', "true").lower()=="true"
routingTag=os.environ.get('DEFAULT_TAG', None)
debug_enabled=os.environ.get('DEBUG_ENABLED', "false").lower()=="true"
codelist = []
ser = serial.Serial(
port = scannerPort,\
timeout=0)
print("Scanner connected to: " + ser.portstr)
count=1
parameters = pika.URLParameters('amqp://'+rabbitUser+':'+rabbitPass+'@'+rabbitHost+':'+str(rabbitPort)+'/%2F')
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
if (routingTag):
channel.basic_publish(exchange=rabbitExchange,
routing_key=routingTag,
body=json.dumps({"type": "service", "data": "scannerReady","timeout":pingTimeout}))
tmx=0;
while True:
tmx+=1
if (tmx > pingTimeout*10):
tmx=0
if (debug_enabled):
print("Ping sent "+str(routingTag))
if (routingTag):
channel.basic_publish(exchange=rabbitExchange,
routing_key=routingTag,
body=json.dumps({"type": "service", "data": "scannerReady","timeout":pingTimeout}))
time.sleep(0.1)
for byte in ser.readline():
if (byte==128):
continue
if (byte=="\r"):
continue
if byte==13:
try:
codestring=codecs.decode(bytes(codelist),"utf-8")
if (len(codestring)>1):
m = re.match('^fxc([0-9a-f]{20})xf$', codestring)
m2=re.match('^70918([0-9]{9})819070$', codestring)
if (m and allowLongPairingTag):
print("Pairing request. RoutingTag: "+m.group(1))
routingTag=m.group(1)
channel.basic_publish(exchange=rabbitExchange,
routing_key=routingTag,
body=json.dumps({"type": "service", "data": "scannerReady","timeout":pingTimeout}))
elif(m2 and allowShortPairingTag):
rt2=hashlib.sha256(m2.group(1).encode());
routingTag=rt2.hexdigest()[5:25];
print("Pairing request. RoutingTag: "+routingTag)
channel.basic_publish(exchange=rabbitExchange,
routing_key=routingTag,
body=json.dumps({"type": "service", "data": "scannerReady","timeout":pingTimeout}))
else:
if (debug_enabled):
print("Read: "+codestring)
tmx=0
if (routingTag):
channel.basic_publish(exchange=rabbitExchange,
routing_key=routingTag,
body=json.dumps({"type": "code", "data": codestring,"timeout":pingTimeout}))
if (debug_enabled):
print("Sent")
except:
print("read failed")
codelist=[]
else:
codelist.append(byte)