R
Railway13mo ago
Tista

Mount Type Cache in Dockerfile

FROM python:3.11-buster as builder

RUN pip install poetry==1.3.2

ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache

RUN rm -rf /var/lib/apt/lists/*

WORKDIR /src

COPY pyproject.toml poetry.lock ./
RUN touch README.md

RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --without dev --no-root

FROM python:3.11-buster as runtime

ENV VIRTUAL_ENV=/src/.venv \
PATH="/src/.venv/bin:$PATH"

COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}

WORKDIR /src
COPY . ./

RUN chmod +x /src/bin/run

CMD ["/src/bin/run"]
FROM python:3.11-buster as builder

RUN pip install poetry==1.3.2

ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache

RUN rm -rf /var/lib/apt/lists/*

WORKDIR /src

COPY pyproject.toml poetry.lock ./
RUN touch README.md

RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --without dev --no-root

FROM python:3.11-buster as runtime

ENV VIRTUAL_ENV=/src/.venv \
PATH="/src/.venv/bin:$PATH"

COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}

WORKDIR /src
COPY . ./

RUN chmod +x /src/bin/run

CMD ["/src/bin/run"]
Hi Railway, I tried to use this dockerfile but it's refusing to build because it says that I need to specfiy an ID for the cache mount. I added the ID but then docker couldn't find the ID. This dockerfile built just fine locally but I couldn't get it to work in Railway. I thought about adding a volume but it seems that the option to add a volume is not there anymore.
4 Replies
Percy
Percy13mo ago
Project ID: 56943544-81c5-486d-8741-d8cca3f88ed1
Tista
Tista13mo ago
56943544-81c5-486d-8741-d8cca3f88ed1
Brody
Brody13mo ago
the id it wants is your service id, there's a very strict format you must use, my recommendation would be to use nixpacks to build your app since this doesn't look like something nixpacks couldn't do
Tista
Tista13mo ago
Right, ok I'll try n give it a go, thanks @Brody
Want results from more Discord servers?
Add your server