Skip to content

Commit

Permalink
feat: add editable and non editable mode for ribot-controller backenc
Browse files Browse the repository at this point in the history
  • Loading branch information
alberto-abarzua committed Nov 16, 2023
1 parent ecf56be commit 93b36c2
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 111 deletions.
26 changes: 18 additions & 8 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
# ESP32
export ESP_WIFI_SSID=ssid
export ESP_WIFI_PASSWORD=password
export ESP_WIFI_SSID=PALVI
export ESP_WIFI_PASSWORD=Palvi.1400
export ESP_CONTROLLER_SERVER_HOST=backend
export ESP_CONTROLLER_SERVER_PORT=8500
export ESP_FLASH_PORT=

# CONTROLLER DEFAULT SETTINGS
CONTROLLER_WEBSOCKET_PORT=8600
CONTROLLER_SERVER_PORT=8500

CONTROLLER_PRINT_STATUS=false

# ---PDM CONTROLLER PUBLISH SETTINGS
CONTROLLER_PDM_PUBLISH_USERNAME=__token__
CONTROLLER_PDM_PUBLISH_PASSWORD=token_here
CONTROLLER_PDM_PUBLISH_PASSWORD=tokenhere!
CONTROLLER_PDM_OVERRIDE_VERSION=None
CONTROLLER_PDM_INCREMENT_VERSION=false

# BACKEND
BACKEND_HTTP_PORT=8000


# BACKEND
BACKEND_HTTP_PORT=5000
BACKEND_UPDATE_RIBOT_CONTROLLER=false

# FRONT
VITE_BACKEND_URL=http://localhost:8000
VITE_BACKEND_URL=http://localhost:5000
VITE_ARM_SIMULATION_WEBSOCKET_PORT=8600
VITE_ARM_SIMULATION_WEBSOCKET_HOST=localhost
VITE_ARM_SIMULATION_URL=http://localhost:8080



# ARM_SIMULATION
ARM_SIMULATION_PORT=8080

# Docker compose debug buid
export COMPOSE_DOCKER_CLI_BUILD=1
export DOCKER_BUILDKIT=1



2 changes: 1 addition & 1 deletion .github/workflows/backend-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Set Env File
run: printenv | grep -v "^\(PWD\|SHLVL\|HOME\)" > .env
- name: Build backend container
run: ./manage.py build --container backend
run: ./manage.py build --container backend --no-editable

- name: Lint Backend
run: ./manage.py lint --container backend
Expand Down
35 changes: 0 additions & 35 deletions :w

This file was deleted.

1 change: 1 addition & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.pdm-python
controller
10 changes: 2 additions & 8 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,18 @@ COPY ./pdm.lock ./pdm.lock
COPY . .

RUN ls -la && sleep 5
RUN pdm remove ribot-controller || true && \
pdm remove ribot-controller --dev || true

RUN if [ "$EDITABLE_PACKAGES" = "true" ]; then \
echo "Installing editable packages"; \
pdm remove ribot-controller || true; \
pdm remove ribot-controller --dev || true; \
pdm add -e ./controller --dev; \
else \
echo "Installing non-editable packages"; \
pdm remove ribot-controller --dev; \
pdm add ribot-controller; \
fi

RUN pdm install
RUN chmod +x ./entrypoint.sh

EXPOSE 8000

ENTRYPOINT ["/app/entrypoint.sh"]

CMD ["pdm","run","start"]

12 changes: 0 additions & 12 deletions backend/entrypoint.sh

This file was deleted.

2 changes: 1 addition & 1 deletion controller/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

RUN pip install --no-cache-dir pdm==2.10.1
RUN pip install --no-cache-dir pdm==2.10.3

ENV PYTHONPATH "${PYTHONPATH}:/app/src"

Expand Down
3 changes: 3 additions & 0 deletions docker_services/backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ services:
build:
context: "../backend"
dockerfile: "Dockerfile"
args:
- EDITABLE_PACKAGES=$BACKEND_EDITABLE_PACKAGES
image: "uintuser/ribot-backend"
volumes:
- ../backend/src:/app/src
- ../backend/pyproject.toml:/app/pyproject.toml
- ../backend/pdm.lock:/app/pdm.lock
- ../controller:/app/controller
ports:
- "$CONTROLLER_WEBSOCKET_PORT:$CONTROLLER_WEBSOCKET_PORT" # websocket
- "$CONTROLLER_SERVER_PORT:$CONTROLLER_SERVER_PORT" # controller
Expand Down
3 changes: 3 additions & 0 deletions instanciator/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.pdm-python

certs
site
3 changes: 3 additions & 0 deletions instanciator/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM nginx:1.25-alpine

COPY
14 changes: 14 additions & 0 deletions instanciator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,22 @@

# Generate certificate

1. First remove the ssl server from the config file


2. Run nginx container


3. Craete the certificate
```
docker compose run --rm certbot certonly --webroot --webroot-path=/var/www/html -d api.demo.ribot.dev
```

4. Add the ssl server back to the config file

5.

```
docker compose up --build
```
12 changes: 3 additions & 9 deletions instanciator/backend/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from routers.move import router as move_router
from routers.settings import router as settings_router
from utils.general import start_controller, stop_controller


@asynccontextmanager
Expand All @@ -21,12 +18,9 @@ async def controller_lifespan(_: FastAPI): # type: ignore # noqa: ANN201

app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_origins=["https://demo.ribot.dev"], # Specific domain
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
allow_methods=["*"], # Allows all methods
allow_headers=["*"], # Allows all headers
)


app.include_router(move_router, prefix="/move")
app.include_router(settings_router, prefix="/settings")
Empty file.
30 changes: 0 additions & 30 deletions instanciator/backend/src/routers/move.py

This file was deleted.

27 changes: 27 additions & 0 deletions instanciator/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3.8'

services:
nginx:
build: .
ports:
- "80:80"
- "443:443"
volumes:
- ./certs:/etc/letsencrypt
- ./site:/var/www/html
depends_on:
- certbot

certbot:
image: certbot/certbot
volumes:
- ./certs:/etc/letsencrypt
- ./site:/var/www/html
entrypoint: /bin/sh -c
command: >
'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'
fastapi:
image: your-fastapi-image
# Define your FastAPI service configuration here

4 changes: 1 addition & 3 deletions instanciator/nginx/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ version: '3.8'
services:
nginx:
build: .
ports:
- "80:80"
- "443:443"
volumes:
- ./certs:/etc/letsencrypt
- ./site:/var/www/html
Expand All @@ -18,6 +15,7 @@ services:
volumes:
- ./certs:/etc/letsencrypt
- ./site:/var/www/html # used to serve the challenge
- ./api.demo.ribot.dev.conf:/etc/nginx/conf.d/api.demo.ribot.dev.conf
entrypoint: /bin/sh -c
command: >
'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'
Expand Down
21 changes: 17 additions & 4 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,21 @@ def up(self, **kwargs):

def build(self, **kwargs):
container_name = kwargs.get('container', None)
no_editable = kwargs.get('no_editable', False)
no_cache = kwargs.get('no_cache', False)
if container_name is not None:
self.docker_manager.dc_build([container_name], no_cache=no_cache)
else:
self.docker_manager.dc_build(self.serivice_names, no_cache=no_cache)
os.environ['BACKEND_EDITABLE_PACKAGES'] = 'true' if not no_editable else 'false'
try:
subprocess.check_call(['rm', '-rf', 'controller'], cwd='backend')
subprocess.check_call(['cp', '-r', '../controller', '.'], cwd='backend')

if container_name is not None:
self.docker_manager.dc_build([container_name], no_cache=no_cache)
else:
self.docker_manager.dc_build(self.serivice_names, no_cache=no_cache)

finally:
subprocess.check_call(['rm', '-rf', 'controller'], cwd='backend')
raise

def get_usb_port(self):
ports = serial.tools.list_ports.comports()
Expand Down Expand Up @@ -510,6 +520,9 @@ def parse_and_execute(self):
'--no-cache', action='store_true', help='Build all docker compose services without cache')
parser_build.add_argument(
'--container', '-c', choices=self.serivice_names, help='Container to build')

parser_build.add_argument(
'--no-editable', action='store_true', help='Build all docker compose services without editable mode')

# --------------
# Build esp
Expand Down

0 comments on commit 93b36c2

Please sign in to comment.