Skip to content

Commit

Permalink
build: build image from code instead of pypi package
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobi-De committed Nov 30, 2023
1 parent 1273d84 commit 9c9e7f1
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 41 deletions.
22 changes: 8 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,24 @@ RUN adduser \
--uid "${UID}" \
appuser


# Remove the problematic line from requirements.lock and create requirements.txt
# RUN --mount=type=cache,target=/root/.cache/pip \
# --mount=type=bind,source=requirements.lock,target=requirements.lock \
# sed '/-e/d' requirements.lock > requirements.txt

# Download dependencies as a separate step to take advantage of Docker's caching.
# Leverage a cache mount to /root/.cache/pip to speed up subsequent builds.
# Leverage a bind mount to requirements.txt to avoid having to copy them into
# into this layer.
# RUN --mount=type=cache,target=/root/.cache/pip \
# --mount=type=bind,source=requirements.txt,target=requirements.txt \
# python -m pip install sse-server-relay

RUN python -m pip install sse-relay-server==1.0.9
RUN --mount=type=cache,target=/root/.cache/pip \
--mount=type=bind,source=requirements.lock,target=requirements.txt \
sh -c "sed '/-e file/d' requirements.txt > /tmp/requirements.txt && python -m pip install -r /tmp/requirements.txt"

# Switch to the non-privileged user to run the application.
USER appuser

# Copy the source code into the container.
COPY . .
COPY src/sse_relay_server /app/sse_relay_server

# Expose the port that the application listens on.
EXPOSE 80
EXPOSE 8001

ENV WORKER_COUNT=4

# Run the application.
CMD sse-relay-server
CMD uvicorn sse_relay_server.main:app --workers $WORKER_COUNT --port 8001 --host 0.0.0.0
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ sse-relay-server --port 8001 --host 0.0.0.0 --workers 4
For Docker users, override the running command as follows:

```sh
docker run -it sse_relay_server sse-relay-server --port 8001 --host 0.0.0.0 --workers 4
docker run -it sse_relay_server sse-relay-server --port 8001:8001 --workers 4
```

## Establishing an SSE Connection with the Relay Service
Expand Down
65 changes: 41 additions & 24 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,53 @@ services:
build:
context: .
ports:
- 8001:80
- 8001:8001
environment:
- DATABASE_URL=postgres://postgres:postgres@db:5432/relay_db

# The commented out section below is an example of how to define a PostgreSQL
# database that your application can use. `depends_on` tells Docker Compose to
# start the database before your application. The `db-data` volume persists the
# database data between container restarts. The `db-password` secret is used
# to set the database password. You must create `db/password.txt` and add
# a password of your choosing to it before running `docker compose up`.
- REDIS_URL=redis://redis:6379
- LOG_LEVEL=DEBUG
depends_on:
db:
condition: service_healthy
db:
image: postgres
- redis

redis:
image: redis
restart: always
user: postgres
volumes:
- db-data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=relay_db
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=postgres
expose:
- 5432
- 6379
healthcheck:
test: [ "CMD", "pg_isready" ]
test: [ "CMD", "redis-cli", "ping" ]
interval: 10s
timeout: 5s
retries: 5
volumes:
db-data:

# The commented out section below is an example of how to define a PostgreSQL
# database that your application can use. `depends_on` tells Docker Compose to
# start the database before your application. The `db-data` volume persists the
# database data between container restarts. The `db-password` secret is used
# to set the database password. You must create `db/password.txt` and add
# a password of your choosing to it before running `docker compose up`.
# depends_on:
# db:
# condition: service_healthy
# db:
# image: postgres
# restart: always
# user: postgres
# secrets:
# - db-password
# volumes:
# - db-data:/var/lib/postgresql/data
# environment:
# - POSTGRES_DB=example
# - POSTGRES_PASSWORD_FILE=/run/secrets/db-password
# expose:
# - 5432
# healthcheck:
# test: [ "CMD", "pg_isready" ]
# interval: 10s
# timeout: 5s
# retries: 5
# volumes:
# db-data:
# secrets:
# db-password:
# file: db/password.txt
2 changes: 1 addition & 1 deletion requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pathspec==0.11.2
platformdirs==4.0.0
pre-commit==3.5.0
psycopg==3.1.13
psycopg-c==3.1.13
psycopg-binary==3.1.13
pydantic==2.5.2
pydantic-core==2.14.5
pygments==2.17.2
Expand Down
2 changes: 1 addition & 1 deletion requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ idna==3.4
markdown-it-py==3.0.0
mdurl==0.1.2
psycopg==3.1.13
psycopg-c==3.1.13
psycopg-binary==3.1.13
pydantic==2.5.2
pydantic-core==2.14.5
pygments==2.17.2
Expand Down

0 comments on commit 9c9e7f1

Please sign in to comment.