Skip to content

Commit

Permalink
feat: DOCKERIZED
Browse files Browse the repository at this point in the history
  • Loading branch information
tushar5526 committed Dec 27, 2023
1 parent bb38ef4 commit 5c433b1
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
1 change: 1 addition & 0 deletions server/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env*
7 changes: 7 additions & 0 deletions server/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# vars mostly used in local development
BASE_DIR='/Users/tusharsamagra/projects/sarthi/server/deployments'
NGINX_PROXY_CONF_LOCATION='/Users/tusharsamagra/projects/sarthi/server/nginx-confs'
ENV=local
DEPLOYMENT_HOST='localhost'
# mac hack
DOCKER_MOUNT_DIR='/Users/tusharsamagra/projects/sarthi/server/deployments'
15 changes: 15 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM python:3.11

WORKDIR /app

RUN apt update -y && apt install docker-compose -y

COPY requirements.txt ./

RUN pip install -r requirements.txt

COPY . .

EXPOSE 5000

CMD [ "flask", "run", "--host=0.0.0.0", "--port=5000"]
14 changes: 14 additions & 0 deletions server/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,17 @@ services:
- "80:80"
volumes:
- ./nginx-confs:/etc/nginx/conf.d

sarthi:
build: .
ports:
- 5000:5000
volumes:
# hack to bypass file resource sharing error to make my development easy on mac
- ./deployments:${DOCKER_MOUNT_DIR:-/deployments}
- ./nginx-confs:/nginx-confs
- /var/run/docker.sock:/var/run/docker.sock
environment:
BASE_DIR: '/Users/tusharsamagra/projects/sarthi/server/deployments'
NGINX_PROXY_CONF_LOCATION: '/nginx-confs'
ENV: local
3 changes: 2 additions & 1 deletion server/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pyyaml
flask
pyjwt
Flask - HTTPAuth
Flask-HTTPAuth
python-dotenv
9 changes: 5 additions & 4 deletions server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,12 @@ def find_free_port(self) -> str:
while current_port <= self._end_port:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
try:
s.bind((self._host_name, current_port))
s.connect((self._host_name, current_port))
s.close()
current_port += 1
except ConnectionRefusedError:
self._port = current_port
return current_port
except socket.error:
current_port += 1

raise RuntimeError(f"Could not find a free port in the specified range.")

Expand Down Expand Up @@ -251,7 +252,7 @@ def _test_nginx_config(self):
def reload_nginx(self):
self._test_nginx_config()
subprocess.run(
["docker", "exec", "-it", "sarthi_nginx", "nginx", "-s", "reload"],
["docker", "exec", "sarthi_nginx", "nginx", "-s", "reload"],
check=True,
)
logger.info("Nginx reloaded successfully.")
Expand Down

0 comments on commit 5c433b1

Please sign in to comment.