Create a QR code image from an URL | Read-only mirror of https://github.com/geoadmin/service-qrcode — Bundesamt für Landestopografie swisstopo. Issues & pull requests at the source.
  • Python 75.9%
  • Makefile 21.4%
  • Dockerfile 2.7%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Terraform BGDI d4f65fe46d
Merge pull request #75 from geoadmin/master
chore: Update develop from master
2026-08-13 08:48:37 +02:00
.github Added/Modified github workflows pr-auto-semver.yml #skip-tagging-and-release 2026-08-13 08:48:30 +02:00
app PB-2205: using re.fullmatch() instead if re.match() 2026-02-10 13:33:44 +01:00
scripts BGDIINF_SB-2565: Added script to decode qrcode image 2022-08-25 11:16:30 +02:00
tests PB-2205: regex to weak 2026-02-09 16:02:55 +01:00
.dockerignore BGDIINF_SB-2025: Changed the local allowed domain 2021-11-03 11:38:14 +01:00
.env.local PB-1954: improve OTEL instrumentation and add local testing env 2026-01-21 14:15:00 +01:00
.env.test PB-2205: regex to weak 2026-02-09 16:02:55 +01:00
.gitignore Moving config (allowed domain) to infra 2021-10-29 13:47:08 +02:00
.isort.cfg BGDIINF_SB-1180: Added logging 2020-08-03 15:21:03 +02:00
.pylintrc PB-1954: fix formating and lint issues 2026-01-09 11:16:57 +01:00
.style.yapf Moving config (allowed domain) to infra 2021-10-29 13:47:08 +02:00
docker-compose-otel.yml PB-1954: improve OTEL instrumentation and add local testing env 2026-01-21 14:15:00 +01:00
docker-compose.yml BGDIINF_SB-1839: Migrate service from dockerhub to ecr 2021-06-16 10:55:02 +02:00
Dockerfile PB-1954: implement otel instrumentation 2025-12-11 14:28:46 +01:00
LICENSE.md BGDIINF_SB-2158: Adding License document 2023-03-28 15:11:37 +02:00
logging-cfg-local.yml BGDIINF_SB-2520: Updated logging utilities for better logging configuration 2022-08-29 13:36:42 +02:00
Makefile PB-1954: improve OTEL instrumentation and add local testing env 2026-01-21 14:15:00 +01:00
otel-local-config.yaml PB-1954: improve OTEL instrumentation and add local testing env 2026-01-21 14:15:00 +01:00
Pipfile PB-1954: improve OTEL instrumentation and add local testing env 2026-01-21 14:15:00 +01:00
Pipfile.lock PB-1954: improve OTEL instrumentation and add local testing env 2026-01-21 14:15:00 +01:00
README.md PB-1992: Add gunicorn keepalive env var 2025-10-13 11:04:26 +02:00
service_qrcode.py PB-934: Avoid python cyclic import 2024-08-28 11:49:03 +02:00
wsgi.py PB-1954: improve OTEL instrumentation and add local testing env 2026-01-21 14:15:00 +01:00

service-qrcode

Branch Status
develop Build Status
master Build Status

Table of content

Description

A simple REST Microservice that returns a QR code from a given URL, using Flask and Gunicorn, with docker containers as a mean of deployment.

Dependencies

This service doesn't have any external dependencies.

Service API

This service has two endpoints that are summarized below

A detailed descriptions of the endpoints can be found in the OpenAPI Spec.

Staging Environments

Environments URL
DEV https://sys-map.dev.bgdi.ch/api/qrcode/
INT https://sys-map.int.bgdi.ch/api/qrcode/
PROD https://map.geo.admin.ch/api/qrcode/

checker GET

This is a simple route meant to test if the server is up.

Path Method Argument Response Type
/checker GET - application/json

generate GET

This route takes an url in the json payload, check if the hostname and domain are part of allowed names and domains, then create a QR Code from that URL and return it in a json answer.

Path Method Argument Response Type
/generate GET url: unencoded URL to be QR coded image/png

Versioning

This service uses SemVer as versioning scheme. The versioning is automatically handled by .github/workflows/main.yml file.

See also Git Flow - Versioning for more information on the versioning guidelines.

Local Development

Make Dependencies

The Make targets assume you have python3.7, pipenv, bash, curl, tar, docker and docker-compose installed.

Setting up to work

First, you'll need to clone the repo

git clone git@github.com:geoadmin/service-qrcode.git

Then, you can run the dev target to ensure you have everything needed to develop, test and serve locally

make dev

That's it, you're ready to work.

Linting and formatting your work

In order to have a consistent code style the code should be formatted using yapf. Also to avoid syntax errors and non pythonic idioms code, the project uses the pylint linter. Both formatting and linter can be manually run using the following command:

make format-lint

Formatting and linting should be at best integrated inside the IDE, for this look at Integrate yapf and pylint into IDE

Test your work

Testing if what you developed work is made simple. You have four targets at your disposal. test, serve, gunicornserve, dockerrun

make test

This command run the integration and unit tests.

make serve

This will serve the application through Flask without any wsgi in front.

make gunicornserve

This will serve the application with the Gunicorn layer in front of the application. It also add the route prefix /api/qrcode.

make dockerrun

This will serve the application with the wsgi server, inside a container.

Docker helpers

From each github PR that is merged into master or into develop, one Docker image is built and pushed on AWS ECR with the following tag:

  • vX.X.X for tags on master
  • vX.X.X-beta.X for tags on develop

Each image contains the following metadata:

  • author
  • git.branch
  • git.hash
  • git.dirty
  • version

These metadata can be read with the following command

make dockerlogin
docker pull 974517877189.dkr.ecr.eu-central-1.amazonaws.com/service-qrcode:develop.latest

# NOTE: jq is only used for pretty printing the json output,
# you can install it with `apt install jq` or simply enter the command without it
docker image inspect --format='{{json .Config.Labels}}' 974517877189.dkr.ecr.eu-central-1.amazonaws.com/service-qrcode:develop.latest | jq

You can also check these metadata on a running container as follows

docker ps --format="table {{.ID}}\t{{.Image}}\t{{.Labels}}"

To build a local docker image tagged as service-qrcode:local-${USER}-${GIT_HASH_SHORT} you can use

make dockerbuild

To push the image on the ECR repository use the following two commands

make dockerlogin
make dockerpush

Deployment

This service is to be deployed to the Kubernetes cluster. See geoadmin/infra-kubernetes/services/service-qrcode

Deployment configuration

The service is configured by Environment Variable:

Env Default Description
LOGGING_CFG logging-cfg-local.yml Logging configuration file
ALLOWED_DOMAINS .* Comma separated list of regex that are allowed as domain in Origin header
CACHE_CONTROL public, max-age=31536000 Cache Control header value of the GET /generate endpoint
CACHE_CONTROL_4XX public, max-age=3600 Cache Control header for 4XX responses
GUNICORN_KEEPALIVE 2 The keepalive setting passed to gunicorn.