Skip to content

Commit 33c856c

Browse files
authored
Merge pull request abi#7 from Jonathan-Adly/dockerfile
Add dockerfiler & docker compose
2 parents 82c4488 + fb9f4da commit 33c856c

File tree

7 files changed

+84
-3
lines changed

7 files changed

+84
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22

33
# Run logs
44
backend/run_logs/*
5+
6+
.env

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ See the [Examples](#examples) section below for more demos.
1515
- Nov 19 - Support for dark/light code editor theme - thanks https://github.com/kachbit
1616
- Nov 16 - Added a setting to disable DALL-E image generation if you don't need that
1717
- Nov 16 - View code directly within the app
18-
- Nov 15 - 🔥 You can now instruct the AI to update the code as you wish. It is helpful if the AI messed up some styles or missed a section.
18+
- Nov 15 - 🔥 You can now instruct the AI to update the code as you wish. It is helpful if the AI messed up some styles or missed a section.
1919

2020
## 🛠 Getting Started
2121

@@ -28,7 +28,7 @@ cd backend
2828
echo "OPENAI_API_KEY=sk-your-key" > .env
2929
poetry install
3030
poetry shell
31-
poetry run uvicorn main:app --reload --port 7000
31+
poetry run uvicorn main:app --reload --port 7001
3232
```
3333

3434
Run the frontend:
@@ -43,6 +43,17 @@ Open http://localhost:5173 to use the app.
4343

4444
If you prefer to run the backend on a different port, update VITE_WS_BACKEND_URL in `frontend/.env.local`
4545

46+
## Docker
47+
48+
If you have Docker installed on your system, in the root directory, run:
49+
50+
```bash
51+
echo "OPENAI_API_KEY=sk-your-key" > .env
52+
docker-compose up -d --build
53+
```
54+
55+
The app will be up and running at http://localhost:5173. Note that you can't develop the application with this setup as the file changes won't trigger a rebuild.
56+
4657
## 🙋‍♂️ FAQs
4758

4859
- **I'm running into an error when setting up the backend. How can I fix it?** [Try this](https://github.com/abi/screenshot-to-code/issues/3#issuecomment-1814777959). If that still doesn't work, open an issue.

backend/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM python:3.12-slim-bullseye
2+
3+
ENV POETRY_VERSION 1.4.1
4+
5+
# Install system dependencies
6+
RUN pip install "poetry==$POETRY_VERSION"
7+
8+
# Set work directory
9+
WORKDIR /app
10+
11+
# Copy only requirements to cache them in docker layer
12+
COPY poetry.lock pyproject.toml /app/
13+
14+
# Disable the creation of virtual environments
15+
RUN poetry config virtualenvs.create false
16+
17+
# Install dependencies
18+
RUN poetry install
19+
20+
# Copy the current directory contents into the container at /app
21+
COPY ./ /app/

docker-compose.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
version: '3.9'
2+
3+
services:
4+
backend:
5+
build:
6+
context: ./backend
7+
dockerfile: Dockerfile
8+
9+
env_file:
10+
- .env
11+
12+
# or
13+
# environment:
14+
#- BACKEND_PORT=7001 # if you change the port, make sure to also change the VITE_WS_BACKEND_URL at frontend/.env.local
15+
# - OPENAI_API_KEY=your_openai_api_key
16+
17+
ports:
18+
- "${BACKEND_PORT:-7001}:${BACKEND_PORT:-7001}"
19+
20+
command: poetry run uvicorn main:app --host 0.0.0.0 --port ${BACKEND_PORT:-7001}
21+
22+
frontend:
23+
build:
24+
context: ./frontend
25+
dockerfile: Dockerfile
26+
ports:
27+
- "5173:5173"

frontend/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_WS_BACKEND_URL=ws://127.0.0.1:7001

frontend/Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM node:20.9-bullseye-slim
2+
3+
# Set the working directory in the container
4+
WORKDIR /app
5+
6+
# Copy package.json and yarn.lock
7+
COPY package.json yarn.lock /app/
8+
9+
# Install dependencies
10+
RUN yarn install
11+
12+
# Copy the current directory contents into the container at /app
13+
COPY ./ /app/
14+
15+
# Expose port 5173 to access the server
16+
EXPOSE 5173
17+
18+
# Command to run the application
19+
CMD ["yarn", "dev", "--host", "0.0.0.0"]

frontend/src/generateCode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import toast from "react-hot-toast";
22

33
const WS_BACKEND_URL =
4-
import.meta.env.VITE_WS_BACKEND_URL || "ws://127.0.0.1:7000";
4+
import.meta.env.VITE_WS_BACKEND_URL || "ws://127.0.0.1:7001";
55
const ERROR_MESSAGE =
66
"Error generating code. Check the Developer Console for details. Feel free to open a Github issue";
77

0 commit comments

Comments
 (0)