Skip to content

Commit

Permalink
build: 🚀 make compose up --watch works
Browse files Browse the repository at this point in the history
  • Loading branch information
wasdee committed Jun 9, 2024
1 parent a4f81ac commit d33ae6e
Show file tree
Hide file tree
Showing 19 changed files with 1,024 additions and 102 deletions.
27 changes: 19 additions & 8 deletions .mise/tasks/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,21 @@
git = sh.Command("git")

class ComposeCmd:
def __init__(self, verb: str = "up"):
def __init__(self, verb: str = "up", dryrun: bool = False, dev: bool = False, detach: bool = False):
self.compose_files = [
"Deployment/compose.yml"
"Deployment/compose.yml",
]
if dev:
self.compose_files.append("Deployment/compose.dev.yml")
self.verb = verb
self.verb_additional_flags = {
"up": "--build"
"up": "--build --remove-orphans "
}
if dev:
self.verb_additional_flags["up"] += "--watch "
if detach:
self.verb_additional_flags["up"] += "--detach "
self.dryrun = dryrun

def run(self):
click.echo(click.style(f"Running docker-compose {self.verb}...", fg="green"))
Expand All @@ -45,16 +52,20 @@ def run(self):
git_root = git("rev-parse", "--show-toplevel").strip()
os.chdir(git_root)

# click.echo(click.style(f"cwd: {os.getcwd()}", fg="yellow"))

compose_files_cmdpart = " ".join([f"-f {file}" for file in self.compose_files])

os.system(f"docker-compose -p gebwai {compose_files_cmdpart} --project-directory . {self.verb} {self.verb_additional_flags.get(self.verb, '')}")
final_cmd = f"docker-compose -p gebwai {compose_files_cmdpart} --project-directory . {self.verb} {self.verb_additional_flags.get(self.verb, '')}"
click.echo(click.style(f"Running command: {final_cmd}\ncwd: {os.getcwd()}", fg="yellow"))
if not self.dryrun:
os.system(final_cmd)

@click.command()
@click.argument("verb", default="up")
def main(verb: str):
compose_cmd = ComposeCmd(verb)
@click.option("--dryrun", is_flag=True, help="Perform a dry run without executing actions", default=False)
@click.option("--dev", is_flag=True, help="Run in development mode", default=False)
@click.option("--detach", is_flag=True, help="Run containers in the background", default=False)
def main(verb: str, dryrun: bool, dev: bool, detach: bool):
compose_cmd = ComposeCmd(verb, dryrun, dev, detach)
compose_cmd.run()

if __name__ == "__main__":
Expand Down
31 changes: 31 additions & 0 deletions Backend/Python/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM python:3.11.4-slim-bullseye as prod
RUN apt-get update && apt-get install -y \
gcc \
&& rm -rf /var/lib/apt/lists/*


RUN pip install poetry==1.4.2

# Configuring poetry
RUN poetry config virtualenvs.create false

# Copying requirements of a project
COPY pyproject.toml poetry.lock /app/src/
WORKDIR /app/src

# Installing requirements
RUN poetry install --only main
# Removing gcc
RUN apt-get purge -y \
gcc \
&& rm -rf /var/lib/apt/lists/*

# Copying actuall application
COPY . /app/src/
RUN poetry install --only main

CMD ["/usr/local/bin/python", "-m", "gebwai"]

FROM prod as dev

RUN poetry install
12 changes: 12 additions & 0 deletions Backend/Python/gebwai/db/models/LINE/GroupSummary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from pydantic import HttpUrl
from sqlmodel import SQLModel


class GroupSummary(SQLModel):
"""
https://developers.line.biz/en/reference/messaging-api/#get-group-summary
"""

group_id: str
group_name: str
picture_url: HttpUrl | None = None
14 changes: 14 additions & 0 deletions Backend/Python/gebwai/db/models/LINE/UserProfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from sqlmodel import Field, SQLModel
from pydantic import HttpUrl


class BaseLINEUser(SQLModel):
user_id: str
display_name: str
picture_url: HttpUrl | None = None
status_message: str | None = None
language: str | None = None


class LINEUser(BaseLINEUser, table=True):
user_id: str = Field(primary_key=True)
44 changes: 44 additions & 0 deletions Backend/Python/gebwai/db/models/__base__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import uuid as uuid_pkg
from datetime import datetime

from sqlmodel import Field, SQLModel, text


class SeqModel(SQLModel):
seq: int = Field(primary_key=True)



class UUIDModel(SQLModel):
id: uuid_pkg.UUID = Field(
default_factory=uuid_pkg.uuid4,
primary_key=True,
index=True,
nullable=False,
sa_column_kwargs={
# "server_default": text("gen_random_uuid()"),
"unique": True,
},
)


class TimestampModel(SQLModel):
created_at: datetime = Field(
nullable=False,
sa_column_kwargs={"server_default": text("current_timestamp")},
)

updated_at: datetime = Field(
nullable=True,
sa_column_kwargs={
"onupdate": text("current_timestamp"),
},
)


class SoftDeleteModel(SQLModel):
deleted_at: datetime = Field(nullable=True)


class MissingModel(SQLModel):
missing_at: datetime = Field(nullable=True)
13 changes: 0 additions & 13 deletions Backend/Python/gebwai/db/models/dummy_model.py

This file was deleted.

Loading

0 comments on commit d33ae6e

Please sign in to comment.