ZeroxAdvanced
ZeroxAdvanced
RRailway
Created by ZeroxAdvanced on 12/21/2023 in #✋|help
Help with Dockerfile, mouting volumes and executing python scripts from subfolders
@Brody hi the scripts will only be uploaded by our dev team. Nu public release but only internal usage. plus2 . Ok you mean i would have just place the scripts in another folder that is not mounted essentially? Can you confirm ? Then I know the right approach.
10 replies
RRailway
Created by ZeroxAdvanced on 12/21/2023 in #✋|help
Help with Dockerfile, mouting volumes and executing python scripts from subfolders
@Brody ok i have archieved similar with below dockerfile. However I have one question: Here is my docker file.
# Pull the official base image
FROM python:3.10-slim-buster

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# The port environment variable is set by Railway when the container is run
# But we can default it to 8080 for local development
ENV PORT=8080

# Expose the port
EXPOSE $PORT

# Set work directory in the container
WORKDIR /code

# Install dependencies
# Copying the requirements file and installing dependencies separately
# from copying the entire project ensures that Docker's cache is used more effectively,
# and dependencies are not unnecessarily reinstalled upon every build.
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt


# Copy project all files to media directory
COPY . /code/


# Command to run on container start ter
#CMD ["python", "main.py"]

# Command to run on container start
CMD uvicorn main:app --host 0.0.0.0 --port $PORT
# Pull the official base image
FROM python:3.10-slim-buster

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# The port environment variable is set by Railway when the container is run
# But we can default it to 8080 for local development
ENV PORT=8080

# Expose the port
EXPOSE $PORT

# Set work directory in the container
WORKDIR /code

# Install dependencies
# Copying the requirements file and installing dependencies separately
# from copying the entire project ensures that Docker's cache is used more effectively,
# and dependencies are not unnecessarily reinstalled upon every build.
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt


# Copy project all files to media directory
COPY . /code/


# Command to run on container start ter
#CMD ["python", "main.py"]

# Command to run on container start
CMD uvicorn main:app --host 0.0.0.0 --port $PORT
and my volume path is /code/media I can access and save files fine e.g. csv files in my media folder that i create at runtime. However I would like to run scripts from my media folder, so you say the approach is to have my scripts in another folder? e..g media/supplier/allcam/products.csv <-- persistant file create new folder (that is not in media volume) scripts/supplier/allcam/import.py and deploy the scripts via github? then I only use the media/supplier folder as a persistant storage? So in general the volume is used to create only files at runtime and not place my scripts? My endgoals is that users also can modify and upload scripts in the volume and not only via deployment.
10 replies
RRailway
Created by ZeroxAdvanced on 12/21/2023 in #✋|help
Help with Dockerfile, mouting volumes and executing python scripts from subfolders
Using this configuration I cannot execute the scripts in my folder structure from my media/suppliers/allcam and it seems that not all files are copied. Question: Can someone provide an example how to make the dockerfile copy the whole project and setup the railway volume? My goals is to execute the scripts at runtime not from the root but media/suppliers/allcam folder. Locally the script exection is working fine with the workdir() which provides me the current workdir. I think something must be mis configured in the Volume or Dockerfile. Any help or suggestions are appriciated!
async def start_script():
log = ui.log(max_lines=1000).classes('w-full h-20')

#refer to the media/suppliers/allcam/get_full_data.py script
script_path = workdir() + 'media/suppliers/allcam/get_fulldata.py'
log.push('Starting script...')
try:
process = await asyncio.create_subprocess_exec(
'python', script_path,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.STDOUT # Combine stdout and stderr
)

# Read output line by line as it is produced
while True:
line = await process.stdout.readline()
if not line:
break
# Push the output to the log object
log.push(line.decode().strip())

await process.wait()
if process.returncode == 0:
log.push('Script executed successfully')
else:
log.push('An error occurred while executing the script')

except OSError as e:
log.push('Execution failed: ' + str(e))
async def start_script():
log = ui.log(max_lines=1000).classes('w-full h-20')

#refer to the media/suppliers/allcam/get_full_data.py script
script_path = workdir() + 'media/suppliers/allcam/get_fulldata.py'
log.push('Starting script...')
try:
process = await asyncio.create_subprocess_exec(
'python', script_path,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.STDOUT # Combine stdout and stderr
)

# Read output line by line as it is produced
while True:
line = await process.stdout.readline()
if not line:
break
# Push the output to the log object
log.push(line.decode().strip())

await process.wait()
if process.returncode == 0:
log.push('Script executed successfully')
else:
log.push('An error occurred while executing the script')

except OSError as e:
log.push('Execution failed: ' + str(e))
10 replies
RRailway
Created by ZeroxAdvanced on 12/19/2023 in #✋|help
Not correct python version in Nixpack when using dockerfile (used to work)
@Brody Hi there I think you are right! I had vscode open en had it named .Dockerfile should of course be "Dockerfile"...Deployed already 8 projects to Railway and never forgot this. Well now is the first time! Thanks for the solution!👍 Deployed again and working!
7 replies
RRailway
Created by ZeroxAdvanced on 11/7/2023 in #✋|help
NiceGUI deployment to Railway help with dockerfile
@Brody thanks for the help! You pointed me in the good direction with the example in the github code! I was able to solve it with some more code examples. Hope this solution will help the railway community. Thanks again and have nice evening.
49 replies
RRailway
Created by ZeroxAdvanced on 11/7/2023 in #✋|help
NiceGUI deployment to Railway help with dockerfile
After this you can just add the below dockerfile
# Pull the official base image
FROM python:3.10-slim-buster

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# The port environment variable is set by Railway when the container is run
# But we can default it to 8080 for local development
ENV PORT=8080

# Expose the port
EXPOSE $PORT

# Set work directory in the container
WORKDIR /code

# Install dependencies
COPY requirements.txt /code/
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

# Copy project
COPY . /code/

# Command to run on container start
#CMD ["python", "main.py"]

CMD uvicorn main:app --host 0.0.0.0 --port $PORT
# Pull the official base image
FROM python:3.10-slim-buster

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# The port environment variable is set by Railway when the container is run
# But we can default it to 8080 for local development
ENV PORT=8080

# Expose the port
EXPOSE $PORT

# Set work directory in the container
WORKDIR /code

# Install dependencies
COPY requirements.txt /code/
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

# Copy project
COPY . /code/

# Command to run on container start
#CMD ["python", "main.py"]

CMD uvicorn main:app --host 0.0.0.0 --port $PORT
49 replies
RRailway
Created by ZeroxAdvanced on 11/7/2023 in #✋|help
NiceGUI deployment to Railway help with dockerfile
Hi got it running Solution: You need to declare fast api in the project e.g. in main.py
from fastapi import FastAPI
from nicegui import events, ui

app = FastAPI()

# Create an init function which will be called with the FastAPI app
def init(fastapi_app: FastAPI) -> None:

@ui.page('/index')
def page_layout():
ui.label('Acces your orders easily')
[rest of your code]

# Run the NiceGUI with the FastAPI app instance and a secret for storage
ui.run_with(
fastapi_app,
storage_secret='pick your private secret here', # Choose a secure secret here
)

[at the end of your code]
# Finally, call the init function with the FastAPI app instance
init(app)
from fastapi import FastAPI
from nicegui import events, ui

app = FastAPI()

# Create an init function which will be called with the FastAPI app
def init(fastapi_app: FastAPI) -> None:

@ui.page('/index')
def page_layout():
ui.label('Acces your orders easily')
[rest of your code]

# Run the NiceGUI with the FastAPI app instance and a secret for storage
ui.run_with(
fastapi_app,
storage_secret='pick your private secret here', # Choose a secure secret here
)

[at the end of your code]
# Finally, call the init function with the FastAPI app instance
init(app)
49 replies
RRailway
Created by ZeroxAdvanced on 11/7/2023 in #✋|help
NiceGUI deployment to Railway help with dockerfile
ERROR: Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 677, in lifespan async with self.lifespan_context(app) as maybe_state: File "/usr/local/lib/python3.10/contextlib.py", line 199, in __aenter__ return await anext(self.gen) File "/usr/local/lib/python3.10/site-packages/nicegui/nicegui.py", line 29, in _lifespan _startup() File "/usr/local/lib/python3.10/site-packages/nicegui/nicegui.py", line 83, in _startup raise RuntimeError('\n\n' RuntimeError: You must call ui.run() to start the server. If ui.run() is behind a main guard if __name__ == "__main__": remove the guard or replace it with if __name__ in {"__main__", "__mp_main__"}: to allow for multiprocessing. ERROR: Application startup failed. Exiting. I think it must be configured in the main.app aswell as shown in the link provided earlier. Just changing the dockerfile with the CMD uvicorn doesnt help yet. Will let you know and tinker more
49 replies
RRailway
Created by ZeroxAdvanced on 11/7/2023 in #✋|help
NiceGUI deployment to Railway help with dockerfile
uvicorn main:app --host 0.0.0.0 --port $PORT will check again but i believe it tested it. will do it again and let you know
49 replies
RRailway
Created by ZeroxAdvanced on 11/7/2023 in #✋|help
NiceGUI deployment to Railway help with dockerfile
ui.run_with( fastapi_app, storage_secret='pick your private secret here', # NOTE setting a secret is optional but allows for persistent storage per user ) I see they using the run_with and then some parameters for Fast API..
49 replies
RRailway
Created by ZeroxAdvanced on 11/7/2023 in #✋|help
NiceGUI deployment to Railway help with dockerfile
i will do some rework on this and post the results here..need to add fastapi then separately
49 replies
RRailway
Created by ZeroxAdvanced on 11/7/2023 in #✋|help
NiceGUI deployment to Railway help with dockerfile
49 replies
RRailway
Created by ZeroxAdvanced on 11/7/2023 in #✋|help
NiceGUI deployment to Railway help with dockerfile
yes but already that, that was why i was consulting the discord. Perhaps i need to contact them
49 replies
RRailway
Created by ZeroxAdvanced on 11/7/2023 in #✋|help
NiceGUI deployment to Railway help with dockerfile
yes tried this already but there is no main:app defnition in my main.py as NiceGui doesnt require this. Basically i do this when creating a fast API app, but here its not required and i dont see it in the code examples
49 replies
RRailway
Created by ZeroxAdvanced on 11/7/2023 in #✋|help
NiceGUI deployment to Railway help with dockerfile
I did 🙂 The help is really appriciated🙏
49 replies
RRailway
Created by ZeroxAdvanced on 11/7/2023 in #✋|help
NiceGUI deployment to Railway help with dockerfile
can you help? I think this is all the info we get
49 replies
RRailway
Created by ZeroxAdvanced on 11/7/2023 in #✋|help
NiceGUI deployment to Railway help with dockerfile
49 replies
RRailway
Created by ZeroxAdvanced on 11/7/2023 in #✋|help
NiceGUI deployment to Railway help with dockerfile
No description
49 replies
RRailway
Created by ZeroxAdvanced on 11/7/2023 in #✋|help
NiceGUI deployment to Railway help with dockerfile
PORT=8080 I always just use the raw data editer in Railway.
49 replies
RRailway
Created by ZeroxAdvanced on 11/7/2023 in #✋|help
NiceGUI deployment to Railway help with dockerfile
aiofiles==23.2.1 aiohttp==3.8.6 aiosignal==1.3.1 annotated-types==0.6.0 anyio==3.7.1 async-timeout==4.0.3 attrs==23.1.0 bidict==0.22.1 certifi==2023.7.22 charset-normalizer==3.3.2 click==8.1.7 exceptiongroup==1.1.3 fastapi==0.104.1 fastapi-socketio==0.0.10 frozenlist==1.4.0 h11==0.14.0 httpcore==1.0.1 httptools==0.6.1 httpx==0.25.1 idna==3.4 ifaddr==0.2.0 itsdangerous==2.1.2 Jinja2==3.1.2 markdown2==2.4.10 MarkupSafe==2.1.3 multidict==6.0.4 nicegui==1.4.2 orjson==3.9.10 pscript==0.7.7 pydantic==2.4.2 pydantic_core==2.10.1 Pygments==2.16.1 python-dotenv==1.0.0 python-engineio==4.8.0 python-multipart==0.0.6 python-socketio==5.10.0 PyYAML==6.0.1 requests==2.31.0 simple-websocket==1.0.0 sniffio==1.3.0 starlette==0.27.0 typing_extensions==4.8.0 urllib3==2.0.7 uvicorn==0.22.0 uvloop==0.19.0 vbuild==0.8.2 watchfiles==0.21.0 websockets==12.0 wsproto==1.2.0 yarl==1.9.2
49 replies