2 years ago
Hello, I would appreciate a sanity check for my setup, because I'm not sure how to get it right.
Due to the complexity of the project, it's a shared monorepo using Polylith approach. The structure is approximately this:
project_dir
- bases
- base1
- base3
- components
- my_application
- projects
- my_projectModules in bases are things to import (e.g. database models), modules in components are things to run (usually, entry script to the application), and directories in projects contain Dockerfile, pyproject.toml and whatever else may be required for an app.
Normally, to build an app as a docker image (non-Railway), I do so:
Run a dedicated
buildershell script whose job is to copy external files to the project's dir (if necessary), and runpoetry build-projectcommand that creates directorydistin the project's directory, and puts fresh build of the app in wheel format (and updates Dockerfile with new wheel name)Build the image with Dockerfile, where the process attempts to install the generated wheel file
(really, all of that is in the builder script, including the docker parts)
Here's an example of such Dockerfile
# syntax=docker/dockerfile:1
ARG PYTHON_VERSION=3.11.4
FROM python:${PYTHON_VERSION}-buster AS builder
ARG wheel=app_web-0.2.0.6-py3-none-any.whl
RUN apt-get update && apt-get install -y bash curl tar coreutils postgresql-client
RUN python -m pip install --upgrade pip
COPY ./dist/$wheel .
RUN pip install --no-cache-dir --upgrade $wheel
WORKDIR /usr/local/lib/python3.11/site-packages/wapagandaNow, when I try to use this Dockerfile as a builder base, I get something this:
#11 [4/6] COPY ./dist/* .
#11 ERROR: lstat /var/lib/docker/tmp/buildkit-mount54527827/dist: no such file or directory
-----
> [4/6] COPY ./dist/* .:
-----
Dockerfile:15
-------------------
13 | # WORKDIR /code
14 |
15 | >>> COPY ./dist/* .
17 | RUN pip install --no-cache-dir --upgrade $wheel
-------------------
ERROR: failed to solve: lstat /var/lib/docker/tmp/buildkit-mount54527827/dist: no such file or directory(in this one, I'm copying the whole dist directory, but essentially it's the same issue)
In the Railway's project's settings, I have set:
build command to:
docker build -t app_web projects/my_projectwatch paths to
projects/my_project(so that it rebuilds only if Dockerfile or wheel is changed)start command to
python components/namespace/web/[core.py](core.py). Not sure if this is correct, but the process never gets there, so don't know.Runtime is
legacy(if that matters)
Does this setup make sense?
What am I missing here?
ⓘ Deployment information is only viewable by project members and Railway employees.
9 Replies
2 years ago
build command to:
docker build -t app_web projects/my_project
You are using a Dockerfile so the build command in the service settings is not used whatsoever, and even so, it does not accept docker based commands.
watch paths to
projects/my_project(so that it rebuilds only if Dockerfile or wheel is changed)
For testing purposes, I would omit this until you have your project deploying correctly.
start command to
python components/namespace/web/core.py
Assuming this path is correct, seems fine to me.
Runtime is
legacy(if that matters)
The V2 Runtime is preferred but in this case, it's slightly irreverent as far as I can tell.
This is a shared monorepo, thus you need to make sure not to set a root directory in the service settings.
You said you have a Dockerfile in a path like /projects/my_project have you set a service variable RAILWAY_DOCKERFILE_PATH=/projects/my_project ?
Please note that the build would be run at the base of your project, so your Dockerfiles would need to account for this.
2 years ago
build command to:
docker build -t app_web projects/my_projectYou are using a Dockerfile so the build command in the service settings is not used whatsoever, and even so, it does not accept
dockerbased commands.
ok, fair enough
2 years ago
You said you have a Dockerfile in a path like
/projects/my_projecthave you set a service variableRAILWAY_DOCKERFILE_PATH=/projects/my_project?
Please note that the build would be run at the base of your project, so your Dockerfiles would need to account for this.
Yes, I did add this variable to the env, with value /projects/web/Dockerfile.
2 years ago
I'm most confused about why doesn't docker see files/directories that sit in the same dir as Dockerfile
2 years ago
Please see the last sentance in my first message.
Please note that the build would be run at the base of your project, so your Dockerfiles would need to account for this.
I'm not confident I 100% understand what should be changed.
2 years ago
Ok, nevermind.
@brody, thanks for pointing me in the right direction. I think I got it working
2 years ago
Glad you got it working, but for extra clarity, the build would be ran from the root of the project, not the location of the Dockerfile, so your Dockerfile would need to use the full paths for things like COPY instead of assuming the files are in the same location.
Status changed to Solved ray-chen • over 1 year ago
