From b2881f4c7a2a1a7b5bf4839736b3301d85bb3e3e Mon Sep 17 00:00:00 2001 From: Christian Schaefer Date: Tue, 6 Aug 2024 12:24:08 +0200 Subject: [PATCH] wip --- .github/workflows/build-and-publish.yml | 31 +++++++++++++++++++++++++ app.py | 10 ++++++++ dockerfile | 20 ++++++++++++++++ examples/app.py | 5 ---- makefile | 6 ----- pyproject.toml | 20 ---------------- src/mymath/__init__.py | 0 src/mymath/geometry/__init__.py | 0 src/mymath/geometry/point.py | 4 ---- src/mymath/geometry/rectangle.py | 12 ---------- src/mymath/lib.py | 8 ------- 11 files changed, 61 insertions(+), 55 deletions(-) create mode 100644 .github/workflows/build-and-publish.yml create mode 100644 app.py create mode 100644 dockerfile delete mode 100644 examples/app.py delete mode 100644 makefile delete mode 100644 pyproject.toml delete mode 100644 src/mymath/__init__.py delete mode 100644 src/mymath/geometry/__init__.py delete mode 100644 src/mymath/geometry/point.py delete mode 100644 src/mymath/geometry/rectangle.py delete mode 100644 src/mymath/lib.py diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml new file mode 100644 index 0000000..c0163e5 --- /dev/null +++ b/.github/workflows/build-and-publish.yml @@ -0,0 +1,31 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: ghcr.io/${{ github.repository }}/hello-flask:latest \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..8a6f901 --- /dev/null +++ b/app.py @@ -0,0 +1,10 @@ +from flask import Flask + +app = Flask(__name__) + +@app.route('/') +def hello_world(): + return 'Hello, World!' + +if __name__ == '__main__': + app.run(debug=True) \ No newline at end of file diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..d38d06c --- /dev/null +++ b/dockerfile @@ -0,0 +1,20 @@ +# Use an official Python runtime as a parent image +FROM python:3.12-slim + +# Set the working directory in the container +WORKDIR /app + +# Copy the current directory contents into the container at /app +COPY . /app + +# Install flask package +RUN pip install --no-cache-dir flask + +# Make port 8048 available to the world outside this container +EXPOSE 8048 + +# Define environment variable +ENV FLASK_APP=app.py + +# Run app.py when the container launches +CMD ["flask", "run", "--host=0.0.0.0", "--port=8048"] \ No newline at end of file diff --git a/examples/app.py b/examples/app.py deleted file mode 100644 index a79db2c..0000000 --- a/examples/app.py +++ /dev/null @@ -1,5 +0,0 @@ -from mymath.lib import RectangleService - -a = RectangleService().create(0, 0, 4, 5) - -print(a) \ No newline at end of file diff --git a/makefile b/makefile deleted file mode 100644 index feca93f..0000000 --- a/makefile +++ /dev/null @@ -1,6 +0,0 @@ -build: - python -m build - -run: build - pip install dist/$(shell ls dist | grep .whl) --force-reinstall - python examples/app.py \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index d3ae925..0000000 --- a/pyproject.toml +++ /dev/null @@ -1,20 +0,0 @@ -[project] -name = "mymath" -version = "0.0.1" -authors = [] -description = "A small example package" -readme = "README.md" -requires-python = ">=3.8" -classifiers = [ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", -] - -[project.urls] -Homepage = "https://github.com/c92s/ideal-lamp" -Issues = "https://github.com/c92s/ideal-lamp/issues" - -[build-system] -requires = ["hatchling"] -build-backend = "hatchling.build" diff --git a/src/mymath/__init__.py b/src/mymath/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/mymath/geometry/__init__.py b/src/mymath/geometry/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/mymath/geometry/point.py b/src/mymath/geometry/point.py deleted file mode 100644 index 45c5e61..0000000 --- a/src/mymath/geometry/point.py +++ /dev/null @@ -1,4 +0,0 @@ -class Point: - def __init__(self, x, y): - self.x = x - self.y = y diff --git a/src/mymath/geometry/rectangle.py b/src/mymath/geometry/rectangle.py deleted file mode 100644 index cf7c9c2..0000000 --- a/src/mymath/geometry/rectangle.py +++ /dev/null @@ -1,12 +0,0 @@ -from geometry.point import Point - - -class Rectangle: - def __init__(self, upper_left: Point, lower_right: Point): - self.upper_left = upper_left - self.upper_right = Point(lower_right.x, upper_left.y) - self.lower_right = lower_right - self.lower_left = Point(upper_left.x, lower_right.y) - - def __repr__(self) -> str: - return f"Rectangle({self.upper_left}, {self.lower_right})" diff --git a/src/mymath/lib.py b/src/mymath/lib.py deleted file mode 100644 index 232949d..0000000 --- a/src/mymath/lib.py +++ /dev/null @@ -1,8 +0,0 @@ -from .geometry.point import Point -from .geometry.rectangle import Rectangle - -class RectangleService: - def create(self, x1, y1, x2, y2): - return Rectangle(Point(x1, y1), Point(x2, y2)) - - \ No newline at end of file