mirror of
https://github.com/UofCBaja/Interview-Backend.git
synced 2025-06-15 13:24:19 -06:00
init^
This commit is contained in:
parent
3cd3091608
commit
d41b86cf46
17
Docker Test/Dockerfile
Normal file
17
Docker Test/Dockerfile
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Use an official Python runtime as a parent image
|
||||||
|
FROM python:3.10-slim
|
||||||
|
|
||||||
|
# Set the working directory inside the container
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy the current directory contents into the container at /app
|
||||||
|
COPY ./mock /app
|
||||||
|
|
||||||
|
# Install any necessary dependencies
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
# Expose port 8080 for the container to listen on
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
# Command to run the Python server when the container starts
|
||||||
|
CMD ["python", "server.py"]
|
10
Docker Test/docker-compose.yaml
Normal file
10
Docker Test/docker-compose.yaml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
services:
|
||||||
|
test-http-container:
|
||||||
|
container_name: test-http-container
|
||||||
|
ports:
|
||||||
|
- 8080:8080
|
||||||
|
volumes:
|
||||||
|
- ./mock:/app
|
||||||
|
build: .
|
||||||
|
networks:
|
||||||
|
- testnet
|
0
Docker Test/mock/requirements.txt
Normal file
0
Docker Test/mock/requirements.txt
Normal file
44
Docker Test/mock/server.py
Normal file
44
Docker Test/mock/server.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import json
|
||||||
|
import signal
|
||||||
|
import sys
|
||||||
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||||
|
|
||||||
|
# Function to generate the response
|
||||||
|
def send_funct():
|
||||||
|
to_send = {
|
||||||
|
"body": "Hello this is a test"
|
||||||
|
}
|
||||||
|
return json.dumps(to_send)
|
||||||
|
|
||||||
|
# Define request handler
|
||||||
|
class RequestHandler(BaseHTTPRequestHandler):
|
||||||
|
def do_GET(self):
|
||||||
|
# Send response headers
|
||||||
|
self.send_response(200)
|
||||||
|
self.send_header('Content-type', 'application/json')
|
||||||
|
self.end_headers()
|
||||||
|
|
||||||
|
# Send the response body (the JSON data)
|
||||||
|
self.wfile.write(send_funct().encode('utf-8'))
|
||||||
|
|
||||||
|
# Graceful shutdown handler
|
||||||
|
def signal_handler(sig, frame):
|
||||||
|
print("\nShutting down server gracefully...")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Set up and start the server
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# Register signal handler for graceful shutdown (e.g., Ctrl+C)
|
||||||
|
signal.signal(signal.SIGINT, signal_handler)
|
||||||
|
|
||||||
|
# Set the server address (localhost) and port (8080)
|
||||||
|
server_address = ('', 8080)
|
||||||
|
httpd = HTTPServer(server_address, RequestHandler)
|
||||||
|
|
||||||
|
print("Server started on port 8080")
|
||||||
|
try:
|
||||||
|
# Start the server and listen for requests
|
||||||
|
httpd.serve_forever()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
# Server shutdown is handled in signal_handler
|
||||||
|
pass
|
Loading…
x
Reference in New Issue
Block a user