mirror of
https://github.com/UofCBaja/Interview-Backend.git
synced 2025-07-06 03:07:16 -06:00
Docker testing
This commit is contained in:
8
composetest/Dockerfile
Normal file
8
composetest/Dockerfile
Normal 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
33
composetest/app.py
Normal 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()
|
8
composetest/docker-compose.yaml
Normal file
8
composetest/docker-compose.yaml
Normal file
@ -0,0 +1,8 @@
|
||||
services:
|
||||
web:
|
||||
container_name: test
|
||||
build: .
|
||||
ports:
|
||||
- "8000:8000"
|
||||
volumes:
|
||||
- ./:/code
|
0
composetest/requirements.txt
Normal file
0
composetest/requirements.txt
Normal file
Reference in New Issue
Block a user