Dockerized Flask api with sole purpose of reading QR codes from PDFs. Decoding is done using pdf2image
and pyzbar
python libs.
Heroku automatically deploys all commits to the master branch where the CI pipeline had passed. The production server is served using gunicorn. When running on Heroku, the app uses a port supplied by Heroku, on localhost the port for testing is 5001. In case you need to debug the app, you can change the CMD
at the end of Dockerfile to use Flask instead of Gunicorn.
In case you need to add debugging prints into the app, use app.logger.debug("foo")
where app
is the flask object.
When inside the directory, type
make build
to build the imagemake run
to build and run the image with preset ENV vars and debugmake stop
to stop the running imagemake bash
to access the running container's bashmake logs
show the docker logsmake rbash
run container only with bash
If you need to see the debug log use
docker-compose up
When in production, do not forget to set the required secret ENV variable:
API_AUTHORIZATION_TOKEN
Sample website is hosted at http://127.0.0.1/5001
curl --location --request POST 'localhost:5001/upload' \
--header 'Authorization: secret' \
--form 'file=@/Users/user123/file.pdf'
Example response when 3 files are sent, 2 of them with qr codes at the first page.
[
{
"content": [
{
"data": "5499944158390",
"page": 0,
"type": "QRCODE"
},
{
"data": "5499944158390",
"page": 0,
"type": "EAN13"
}
],
"filename": "example.pdf",
"key": "somefile"
},
{
"content": [],
"filename": "LSTM_fixed.pdf",
"key": "file[]"
},
{
"content": [
{
"data": "5499944158390",
"page": 0,
"type": "QRCODE"
},
{
"data": "5499944158390",
"page": 0,
"type": "EAN13"
}
],
"filename": "example.pdf",
"key": "file[]"
}
]
To speed up the CI, we build our own image with both python and system requirements. This speeds up the CI pipeline as it just downloads the image instead of having to also build it locally. In order to upload the image (when we change/update dependencies), navigate to Actions
> Workflows
> Build docker
and click the Run workflow
button. This will build a new image with new dependencies and automatically push it to dockerhub.