Skip to content

Commit 9d052dc

Browse files
committed
refactor image import and add Alpine docker image
- dynamic import of QR reader - build docker also for arm64
1 parent 915efcf commit 9d052dc

21 files changed

+912
-523
lines changed

.github/workflows/ci.yml

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ on:
44
push:
55
pull_request:
66
schedule:
7-
- cron: '47 3 * * *'
7+
- cron: '37 3 * * *'
88

99
jobs:
1010
build:
1111

1212
strategy:
1313
matrix:
14-
python-version: ["3.x", "3.11", "3.10", "3.9", "pypy-3.9", "3.8", "pypy-3.8", "3.7", "pypy-3.7"]
14+
python-version: ["3.x", "3.11", "3.10", "3.9", "3.8", "3.7"]
1515
platform: [ubuntu-latest, macos-latest, windows-latest]
1616
exclude:
1717
- platform: windows-latest
@@ -25,6 +25,14 @@ jobs:
2525
uses: actions/setup-python@v4
2626
with:
2727
python-version: ${{ matrix.python-version }}
28+
- name: Install zbar shared lib for QReader (Linux)
29+
if: runner.os == 'Linux'
30+
run: |
31+
sudo apt-get install -y libzbar0
32+
- name: Install zbar shared lib for QReader (macOS)
33+
if: runner.os == 'macOS'
34+
run: |
35+
brew install zbar
2836
- name: Install dependencies
2937
run: |
3038
python -m pip install --upgrade pip

.github/workflows/ci_docker.yml

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: "Docker: build and publish"
2+
3+
# How to setup: https://event-driven.io/en/how_to_buid_and_push_docker_image_with_github_actions/
4+
# How to run: https://aschmelyun.com/blog/using-docker-run-inside-of-github-actions/
5+
6+
on:
7+
# run it on push to the default repository branch
8+
push:
9+
# branches: [master]
10+
# run it during pull request
11+
# pull_request:
12+
13+
jobs:
14+
# define job to build and publish docker image
15+
build-and-push-docker-image:
16+
name: Build Docker image and push to repositories
17+
# run only when code is compiling and tests are passing
18+
runs-on: ubuntu-latest
19+
20+
# steps to perform in job
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v3
24+
25+
- name: Set up QEMU
26+
uses: docker/setup-qemu-action@v2
27+
28+
# setup Docker build action
29+
- name: Set up Docker Buildx
30+
id: buildx
31+
uses: docker/setup-buildx-action@v2
32+
33+
- name: Login to DockerHub
34+
uses: docker/login-action@v2
35+
with:
36+
username: ${{ secrets.DOCKERHUB_USERNAME }}
37+
password: ${{ secrets.DOCKERHUB_TOKEN }}
38+
39+
- name: Login to Github Packages
40+
uses: docker/login-action@v2
41+
with:
42+
registry: ghcr.io
43+
username: ${{ github.actor }}
44+
password: ${{ secrets.GHCR_IO_TOKEN }}
45+
46+
- name: "no_qr_reader: Build image and push to Docker Hub and GitHub Container Registry"
47+
uses: docker/build-push-action@v2
48+
with:
49+
# relative path to the place where source code with Dockerfile is located
50+
platforms: linux/amd64,linux/arm64
51+
context: .
52+
file: Dockerfile_no_qr_reader
53+
# Note: tags has to be all lower-case
54+
tags: |
55+
scit0/extract_otp_secret_keys_no_qr_reader:latest
56+
ghcr.io/scito/extract_otp_secret_keys_no_qr_reader:latest
57+
# build on feature branches, push only on master branch
58+
# TODO push: ${{ github.ref == 'refs/heads/master' }}
59+
push: true
60+
61+
- name: "qr_reader: Build image and push to Docker Hub and GitHub Container Registry"
62+
uses: docker/build-push-action@v2
63+
with:
64+
platforms: linux/amd64,linux/arm64
65+
# relative path to the place where source code with Dockerfile is located
66+
context: .
67+
# Note: tags has to be all lower-case
68+
tags: |
69+
scit0/extract_otp_secret_keys:latest
70+
ghcr.io/scito/extract_otp_secret_keys:latest
71+
# build on feature branches, push only on master branch
72+
# TODO push: ${{ github.ref == 'refs/heads/master' }}
73+
push: true
74+
75+
- name: Image digest
76+
run: echo ${{ steps.docker_build.outputs.digest }}

Dockerfile

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
FROM python:3.11-alpine
1+
FROM python:3.11-slim-bullseye
22

33
WORKDIR /extract
44

55
COPY . .
66

7-
RUN pip install -r requirements.txt
7+
ARG run_tests=true
8+
9+
RUN apt-get update && apt-get install -y libzbar0 python3-opencv nano \
10+
&& pip install -r requirements.txt \
11+
&& if [[ "$run_tests" == "true" ]] ; then /extract/run_pytest.sh ; else echo "Not running tests..." ; fi
812

913
WORKDIR /files
1014

11-
ENTRYPOINT [ "python", "/extract/extract_otp_secret_keys.py" ]
15+
ENTRYPOINT ["python", "/extract/extract_otp_secret_keys.py"]
16+
17+
LABEL org.opencontainers.image.source https://github.com/scito/extract_otp_secret_keys

Dockerfile_no_qr_reader

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM python:3.11-alpine
2+
3+
WORKDIR /extract
4+
5+
COPY . .
6+
7+
ARG run_tests=true
8+
9+
RUN pip install protobuf qrcode Pillow \
10+
&& if [[ "$run_tests" == "true" ]] ; then /extract/run_pytest.sh test_extract_otp_secret_keys_pytest.py -k "not qreader" --relaxed ; else echo "Not running tests..." ; fi
11+
12+
WORKDIR /files
13+
14+
ENTRYPOINT ["python", "/extract/extract_otp_secret_keys.py"]
15+
16+
LABEL org.opencontainers.image.source https://github.com/scito/extract_otp_secret_keys

Pipfile

+3-7
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ verify_ssl = true
44
name = "pypi"
55

66
[packages]
7-
protobuf = "==4.21.12"
7+
protobuf = "*"
88
qrcode = "*"
99
pillow = "*"
10-
wheel = "==0.38.4"
11-
pytest = "==7.2.0"
12-
flake8 = "==6.0.0"
13-
pylint = "==2.15.9"
14-
qreader = "==1.3.1"
15-
opencv-python = "==4.6.0.66"
10+
qreader = "*"
11+
opencv-python = "*"
1612

1713
[dev-packages]
1814
pytest = "*"

0 commit comments

Comments
 (0)