diff --git a/app_python/.dockerignore b/app_python/.dockerignore new file mode 100644 index 000000000..1d1fe94df --- /dev/null +++ b/app_python/.dockerignore @@ -0,0 +1 @@ +Dockerfile \ No newline at end of file diff --git a/app_python/Dockerfile b/app_python/Dockerfile new file mode 100644 index 000000000..b9c98775a --- /dev/null +++ b/app_python/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3-alpine +RUN addgroup -S lowuser && adduser -S lowuser -G lowuser +WORKDIR /main +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt +COPY main.py . +RUN chown -R lowuser:lowuser /main +USER lowuser +CMD ["python3", "main.py"] \ No newline at end of file diff --git a/app_python/README.md b/app_python/README.md new file mode 100644 index 000000000..0be939514 --- /dev/null +++ b/app_python/README.md @@ -0,0 +1,31 @@ +# Current Time in Moscow + +## Overview +This is a simple Python web application that displays the current time in Moscow. It uses the Flask web framework and the datetime module to get the current time in the Europe/Moscow timezone. The time is displayed in a user-friendly format on a web page. + +## Build +To build this application, you need to create a Python file with a main.py extension, for example, app.py. Then, copy the code in main.py to your file. Save the file and run it using the command python app.py in a terminal or command prompt. +The application will start running on your local machine. + +## Usage +To use the application, open a web browser and navigate to http://localhost:5000/. The current time in Moscow will be displayed on the web page. The time will be updated every time you refresh the page. + +## To run the Dockerfile in your project, you can follow these steps: + +1. Make sure that you have Docker installed on your local machine. You can download Docker from the official website: https://www.docker.com/products/docker-desktop + +2. Open a terminal or command prompt and navigate to the directory that contains your Dockerfile. + +3. Build the Docker image using the following command: + docker build -t . + Make sure to replace with the name that you want to give to your Docker image. The . at the end of the command specifies that the build context is the current directory. + +4. Once the build is complete, you can run the Docker container using the following command: + docker run -p : + +Make sure to replace with the port number on your local machine that you want to use to access the container, with the port number that your application is listening on inside the container, and with the name of the Docker image that you built in step 3. + +For example, if your application is listening on port 80 inside the container and you want to access it on port 8080 on your local machine, you can use the following command: + docker run -p 8080:80 + +5. Once the container is running, you can access your application by opening a web browser and navigating to http://localhost:. In the example above, you would navigate to http://localhost:8080. diff --git a/app_python/main.py b/app_python/main.py new file mode 100644 index 000000000..1c43ff072 --- /dev/null +++ b/app_python/main.py @@ -0,0 +1,17 @@ +from datetime import datetime + +from flask import Flask + +app = Flask(__name__) + +def get_current_time(): + now = datetime.now() + current_time = now.strftime("Current Time in Moscow: %Y-%m-%d %H:%M:%S") + return current_time + +@app.route('/') +def home(): + return get_current_time() + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=8081) \ No newline at end of file diff --git a/app_python/requirements.txt b/app_python/requirements.txt new file mode 100644 index 000000000..496a52930 --- /dev/null +++ b/app_python/requirements.txt @@ -0,0 +1,2 @@ +pytz +Flask==2.0.1