Docker testing

This commit is contained in:
2024-11-23 12:01:28 -07:00
parent 58f913d3ed
commit 845438960b
5 changed files with 79 additions and 41 deletions

8
composetest/Dockerfile Normal file
View File

@ -0,0 +1,8 @@
# syntax=docker/dockerfile:1
FROM python:3.10-slim
WORKDIR /code
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
EXPOSE 5000
COPY . .
CMD ["python", "app.py"]

33
composetest/app.py Normal file
View File

@ -0,0 +1,33 @@
import time
from http.server import BaseHTTPRequestHandler, HTTPServer
hit_count = 0 # In-memory counter
def get_hit_count():
global hit_count
hit_count += 1
return hit_count
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/':
count = get_hit_count()
response = f'Hello World! I have been seen {count} times.\n'
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(response.encode('utf-8'))
else:
self.send_response(404)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(b'Not Found\n')
def run(server_class=HTTPServer, handler_class=RequestHandler, port=8000):
server_address = ('', port)
httpd = server_class(server_address, handler_class)
print(f'Starting server on port {port}...')
httpd.serve_forever()
if __name__ == '__main__':
run()

View File

@ -0,0 +1,8 @@
services:
web:
container_name: test
build: .
ports:
- "8000:8000"
volumes:
- ./:/code

View File