Skip to content

Commit

Permalink
Docker image (#13)
Browse files Browse the repository at this point in the history
* Docker image
  • Loading branch information
oittaa authored Oct 23, 2021
1 parent cae0ed8 commit 15bcc42
Show file tree
Hide file tree
Showing 11 changed files with 251 additions and 44 deletions.
31 changes: 31 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
*,cover
*.log
*.pyc
*.pyd
*.pyo
.DS_Store
.Python
.cache
.coverage
.coverage.*
.dockerignore
.editorconfig
.git
.github/
.gitignore
.pytest_cache
.tox
.vscode
/setup.cfg
app.yaml
cron.yaml
Dockerfile
LICENSE
README.md
__pycache__
cloudbuild.yaml
coverage.xml
env
nosetests.xml
pip-delete-this-directory.txt
pip-log.txt
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.py]
indent_size = 4

[*.{yml,yaml}]
indent_size = 2
4 changes: 4 additions & 0 deletions .gcloudignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ __pycache__/
coverage.xml
# Ignored by the build system
/setup.cfg
.dockerignore
.editorconfig
.github/
Dockerfile
LICENSE
README.md
requirements-dev.txt
test.py
test-data/
.DS_Store
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ updates:
schedule:
interval: daily
open-pull-requests-limit: 10
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "daily"
open-pull-requests-limit: 10
- package-ecosystem: "github-actions"
directory: "/"
schedule:
Expand Down
85 changes: 83 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install coverage flake8
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
Expand All @@ -40,7 +40,6 @@ jobs:
flake8 . --count --max-complexity=10 --max-line-length=127 --statistics
- name: Run tests with Coverage
run: |
export SSL_CERT_FILE=./ca.pem
coverage run --source=./ --omit=test.py test.py
coverage report -m
coverage xml
Expand All @@ -49,3 +48,85 @@ jobs:
if: matrix.python-version == '3.9'
with:
flags: unittests

docker-test:
runs-on: ubuntu-20.04
steps:
- uses: actions/[email protected]
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/[email protected]
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-build-x-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-x
- name: Build
uses: docker/[email protected]
with:
platforms: linux/amd64,linux/arm64
push: false
load: false
target: test
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
-
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
docker-prod:
runs-on: ubuntu-20.04
strategy:
matrix:
arch: [linux/amd64, linux/arm64]
steps:
- uses: actions/[email protected]
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/[email protected]
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-build-x-${{ matrix.arch }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-x-${{ matrix.arch }}-
- name: Build
uses: docker/[email protected]
with:
platforms: ${{ matrix.arch }}
push: false
load: true
tags: oittaa/ibkr-report-parser:latest
target: prod
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
-
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Docker container up
run: docker run -d --rm -p 8080:8080 --name ibkr-report-parser oittaa/ibkr-report-parser
- name: Wait 10 seconds
run: sleep 10
- name: Check running containers
run: docker ps -a
- name: Check the container reachability
run: curl -s --retry 10 --retry-connrefused http://localhost:8080/
- name: Check Docker logs
run: docker logs ibkr-report-parser
- name: Docker container down
run: docker stop ibkr-report-parser
85 changes: 83 additions & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install coverage flake8
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
Expand All @@ -37,7 +37,88 @@ jobs:
flake8 . --count --max-complexity=10 --max-line-length=127 --statistics
- name: Run tests with Coverage
run: |
export SSL_CERT_FILE=./ca.pem
coverage run --source=./ --omit=test.py test.py
coverage report -m
coverage xml
docker-test:
runs-on: ubuntu-20.04
steps:
- uses: actions/[email protected]
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/[email protected]
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-build-x-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-x
- name: Build
uses: docker/[email protected]
with:
platforms: linux/amd64,linux/arm64
push: false
load: false
target: test
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
-
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
docker-prod:
runs-on: ubuntu-20.04
strategy:
matrix:
arch: [linux/amd64, linux/arm64]
steps:
- uses: actions/[email protected]
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/[email protected]
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-build-x-${{ matrix.arch }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-x-${{ matrix.arch }}-
- name: Build
uses: docker/[email protected]
with:
platforms: ${{ matrix.arch }}
push: false
load: true
tags: oittaa/ibkr-report-parser:latest
target: prod
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
-
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Docker container up
run: docker run -d --rm -p 8080:8080 --name ibkr-report-parser oittaa/ibkr-report-parser
- name: Wait 10 seconds
run: sleep 10
- name: Check running containers
run: docker ps -a
- name: Check the container reachability
run: curl -s --retry 10 --retry-connrefused http://localhost:8080/
- name: Check Docker logs
run: docker logs ibkr-report-parser
- name: Docker container down
run: docker stop ibkr-report-parser
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM python:3.10.0-slim AS base

ARG DEBIAN_FRONTEND=noninteractive

# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True
ENV APP_HOME /app
ENV GUNICORN_WORKERS 1
ENV GUNICORN_THREADS 8
ENV PORT 8080

WORKDIR $APP_HOME
COPY main.py requirements.txt ./
COPY static/ ./static/
COPY templates/ ./templates/
RUN pip3 install --no-cache-dir -r requirements.txt

FROM base AS test
COPY test-data/ ./test-data/
COPY test.py requirements-dev.txt ./
RUN pip3 install --no-cache-dir -r requirements-dev.txt && \
coverage run --source=./ --omit=test.py test.py && \
coverage report -m

FROM base AS prod
ENTRYPOINT []
CMD exec gunicorn --bind :$PORT --workers $GUNICORN_WORKERS --threads $GUNICORN_THREADS --timeout 0 main:app
1 change: 0 additions & 1 deletion app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ runtime: python39
env_variables:
BUCKET_ID: ibkr-report-parser
TITLE: IBKR Report Parser
SSL_CERT_FILE: ./ca.pem

handlers:
- url: /static
Expand Down
39 changes: 0 additions & 39 deletions ca.pem

This file was deleted.

2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage==6.0.2
flake8==4.0.1
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
flask==2.0.2
google-cloud-storage==1.42.3
gunicorn==20.1.0

0 comments on commit 15bcc42

Please sign in to comment.