From 8c0b81bdcf90aaf044d1bab5b932b76db81da30b Mon Sep 17 00:00:00 2001 From: Anupam Date: Sun, 3 Aug 2025 02:31:39 +0530 Subject: [PATCH 1/4] chore: add editorconfig --- .editorconfig | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..b097c31 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,50 @@ +# EditorConfig is awesome: http://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +# Unix-style newlines at the bottom of every file +end_of_line = lf +charset = utf-8 + +# indentation style and size +indent_style = space +indent_size = 2 + +# Make sure every file has a blank line at the end +insert_final_newline = true + +# Remove any whitespace characters preceding newline characters +trim_trailing_whitespace = true + +# Give operators breathing room, but not brackets +spaces_around_operators = true +spaces_around_brackets = false + +# 4 space indentation +[*.{py,java}] +indent_size = 4 + +[*.json] +indent_size = 4 + +# 2 space indentation +[*.{js,html}] +indent_size = 2 + +[*.{tf}] +indent_size = 2 + +[*.rb] +indent_size = 2 + +[*.yml] +indent_size = 2 + +[*.yaml] +indent_size = 2 + +[*.{md}] +indent_size = unset +trim_trailing_whitespace = false From d583473391f1b173c92ce3c1fe0389db6732e860 Mon Sep 17 00:00:00 2001 From: Anupam Date: Sun, 3 Aug 2025 02:32:38 +0530 Subject: [PATCH 2/4] chore: kzb-24 update readme --- README.md | 81 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 7fb53ca..c174075 100644 --- a/README.md +++ b/README.md @@ -12,57 +12,84 @@ Resources in this repository are meant for use with Python 3.x (check the versio ### Bootstrap Virtual Environment It is a best practice to create a virtual environment for your application to avoid any conflict in dependencies between multiple applications. Hence, it is recommended to create a virtual environment (using python's default package "venv" or of your choice) and install all the dependencies. Follow below according to your operating system. -``` -Linux OS: + +```bash +# Linux OS: python3 -m venv example-app-venv source example-app-venv/bin/activate pip install -r requirements.txt -Windows OS: +# Windows OS: python -m venv example-app-venv example-app-venv\Scripts\activate pip install -r requirements.txt ``` -**Note:** -- Activation makes the virtual environment the default Python interpreter for the duration of a shell session. Because, This will prepend that directory to your PATH, so that running python will invoke the virtual environment’s Python interpreter. As an indication of virtual environment activation, current shell prompt will prepend the name of the virtual environment you are currently using. - -- To deactivate the environment, simply type `deactivate` and you will return to your normal shell. - -- Within the virtual environment, you can use the command `pip` instead of `pip3` and `python` instead of `python3`. +> [!NOTE] +> Activation makes the virtual environment the default Python interpreter for the duration of a shell session. Because, This will prepend that directory to your PATH, so that running python will invoke the virtual environment’s Python interpreter. As an indication of virtual environment activation, current shell prompt will prepend the name of the virtual environment you are currently using. +> +> To deactivate the environment, simply type `deactivate` and you will return to your normal shell. +> +> Within the virtual environment, you can use the command `pip` instead of `pip3` and `python` instead of `python3`. ## Run and Test the App on Local Machine -To start the web server of the app, execute the below command - +Flask has the built-in Werkzeug server. To start the default dev web server of the app, execute the below command - + +```bash +# To start the default dev web server of the app +python python/run.py ``` - python python/run.py + +To start the production grade wsgi gunicorn server, execute the below command - + +```bash +gunicorn main:app +gunicorn --bind :9090 --workers 1 --threads 8 main:app + +# Where: +# gunicorn -> Runs the Gunicorn WSGI server +# --bind :9090 -> Bind to all network interfaces (0.0.0.0) on port 9090 +# --workers -> 1 Start 1 worker process +# --threads -> 8 Each worker can run 8 threads concurrently +# main:app -> main is the Python file name (i.e., main.py), and app is the Flask app object inside it ``` To check the webapp, open a browser and hit the below URL - -``` - http://:Port - http://127.0.0.1:4999/ + +``` bash +http://:Port +http://127.0.0.1:4999/ ``` ## Run and Test the App on Docker 1. Clone the repository and switch inside the directory. -2. Build the docker image using one of below command: -``` - docker build -t eapp:latest . - docker build -t eapp:latest -f Dockerfile.dev . -``` -3. To run the docker container from built image in the background with port mapping, use one of below command: -``` - docker run -d -p 5000:4999 --name eapp-container eapp:latest # To explicitly specify the what port to map in the form, : - docker run -d -P --name eapp-container eapp:latest # To map the exposed port (via EXPOSE) to random ports on the host machine +2. Build the docker image using one of below command: + +```bash +docker build -t eapp:latest . +docker build -t eapp:latest -f Dockerfile.dev . ``` -4. To test the app on host machine, open the browser or use curl command: + +3. To run the docker container from built image in the background with port mapping, use one of below command: + +```bash +# To explicitly specify the what port to map in the form, : + # with --rm flag, Docker will automatically remove the container after the container exits. +docker run -d -p 5000:4999 --name eapp-container eapp:latest + +# To map the exposed port (via EXPOSE) to random ports on the host machine +docker run -d -P --name eapp-container eapp:latest ``` + +4. To test the app on host machine, open the browser or use curl command: +```bash curl http://localhost:5000 ``` -**Note:** -- ( . ) tells about the build context. The build context is the current directory (.), which should contain your application code and the Dockerfile. Pass the Dockerfile, if its name is not exactly Dockerfile. -- Port mapping is used to access the services running inside a Docker container. In the above case, we can now access the application using port 5000 on the host machine. +> [!NOTE] +> ( . ) tells about the build context. The build context is the current directory (.), which should contain your application code and the Dockerfile. Pass the Dockerfile, if its name is not exactly Dockerfile. +> +> Port mapping is used to access the services running inside a Docker container. In the above case, we can now access the application using port 5000 on the host machine. ## References - https://www.warp.dev/terminus/docker-logs-tail From 4c2cde45b2df160500ede26273d33b9b5594202a Mon Sep 17 00:00:00 2001 From: Anupam Date: Sun, 3 Aug 2025 02:36:06 +0530 Subject: [PATCH 3/4] feat: disabled gh actions --- .../workflows/{build-release.yml => build-release.yml.disabled} | 0 .github/workflows/{lower-build.yml => lower-build.yml.disabled} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{build-release.yml => build-release.yml.disabled} (100%) rename .github/workflows/{lower-build.yml => lower-build.yml.disabled} (100%) diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml.disabled similarity index 100% rename from .github/workflows/build-release.yml rename to .github/workflows/build-release.yml.disabled diff --git a/.github/workflows/lower-build.yml b/.github/workflows/lower-build.yml.disabled similarity index 100% rename from .github/workflows/lower-build.yml rename to .github/workflows/lower-build.yml.disabled From f2bbbf49d6890bf3ca0a25628c0a29a7a57c73b1 Mon Sep 17 00:00:00 2001 From: Anupam Date: Sun, 3 Aug 2025 02:37:23 +0530 Subject: [PATCH 4/4] feat: add dockerfile for tst and tmp --- Dockerfile.tmp | 14 ++++++++++++++ Dockerfile.tst | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 Dockerfile.tmp create mode 100644 Dockerfile.tst diff --git a/Dockerfile.tmp b/Dockerfile.tmp new file mode 100644 index 0000000..0e1123c --- /dev/null +++ b/Dockerfile.tmp @@ -0,0 +1,14 @@ +FROM ubuntu + +# Case-01 +CMD ["echo", "hello world"] + +# Case-02 +# ENTRYPOINT ["echo", "hello world"] + +# Case-03 +# ENTRYPOINT ["echo"] + +# Case-04 +# ENTRYPOINT ["echo"] +# CMD ["hello world"] diff --git a/Dockerfile.tst b/Dockerfile.tst new file mode 100644 index 0000000..97d4e69 --- /dev/null +++ b/Dockerfile.tst @@ -0,0 +1,50 @@ +ARG IMAGE_TAG=3.10-slim +FROM python:${IMAGE_TAG} + +# Labels for docker image +LABEL maintainer="Anupam Yadav" +LABEL email="anupaminit@gmail.com" + +# Arguments for docker file +ARG USERNAME=python +ARG GROUPNAME=$USERNAME +ARG USERID=1100 +ARG GROUPID=$USERID + +# Environment variable +# Prevents .pyc/__pycache__ creation +ENV PYTHONDONTWRITEBYTECODE=1 +# Forces real-time logging/output (no buffering) +ENV PYTHONUNBUFFERED=1 + +# Check the current user and create a new user +RUN whoami +RUN groupadd --gid $GROUPID $GROUPNAME && useradd --uid $USERID --gid $GROUPID -m $USERNAME + +# Install the tools required for the project +RUN apt-get update && apt-get install -y \ + python3 \ + python3-pip \ + python3-venv + +# Copy requirements file and install all the required python packages +WORKDIR /app +COPY python/requirements.txt /app +# RUN pip3 install --no-cache-dir --break-system-packages -r requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +COPY python /app + +# Change the user to newly created user +USER $USERNAME +RUN whoami + +# Expose the container port +EXPOSE 5001 + +# Change the working directory +WORKDIR /app + +# Run the main application file on container startup +ENTRYPOINT ["gunicorn"] +CMD ["--bind", "0.0.0.0:5001", "--workers", "1", "--threads", "8", "main:app"]