Forcing fresh Docker builds on Railway (cache not invalidating)

dc-aaia
HOBBY

2 months ago

I’m technically shallow from a Railway systems standpoint and had GPT-5 draft the specifics for the support or guidance I am needing.  I appreciate any suggestions or guidance on this and apologize in advance for the lengthy read.

Context

  • Project: n8n-mcp Core on Railway VPC, service “open-webui-mcpo” (Streamable HTTP MCP proxy).

  • Source Repo: DC-AAIA/open-webui-mcpo (branch: main).

  • Region: us-west2. One replica. Auth via HTTP Bearer.

  • Relevant docs I’m instructing GPT-5 to use as its source of truth as part of a dedicated Abacus AI Project knowledge collection: DC-AAIA fork of Railway docs: https://github.com/DC-AAIA/railwayapp-docs

Observed behavior

  • open-webui-mcpo service redeploys consistently reuse cached layers from a previous/original build version end-to-end, so intended code revision commits to my forked Dockerfile or other mcpo service files are not included in the redeploy builds. Build time ~9s. All Docker steps show “CACHED,” including:

    • COPY . /app

    • RUN uv venv "/app/.venv"

    • RUN uv pip install . && rm -rf ~/.cache

  • I purposely changed the app code (FastAPI OpenAPI spec output) but the running service still serves the old OpenAPI. This indicates the redeployed image did not include my latest source.

  • I do see a RUN echo "BUILD_REV=2025-08-14T17-35-00Z" > /build-rev.txt in the Dockerfile, but it is static and shows as CACHED in logs, so it does not invalidate anything downstream.

Questions

  1. What’s the recommended/most reliable way on Railway to force a rebuild without cache for GitHub-based Docker builds? In the UI, should I use a “Clear build cache” or “Rebuild without cache” action for the service? If using the Railway CLI, which exact flag/command should I use for a no-cache rebuild? I’m deferring to the DC-AAIA Railway docs fork but want to confirm best practice from the Railway team / community.

  2. Does the “Upstream Repo: Check for updates” control in the Source section affect builds from my connected repo? My understanding is it’s for syncing template updates, not for pulling the latest code from DC-AAIA/open-webui-mcpo (which the service already points to). Please confirm.

  3. Are there any project-level cache settings I should verify (e.g., build cache scope or retention) that could be causing overly aggressive caching across builds for this service?

  4. Any known pitfalls with ARG-based cache busters on Railway? GPT-5 recommended a plan to switch to:

    • Dockerfile
      ARG BUILD_REV
      RUN echo "BUILD_REV=${BUILD_REV}" > /build-rev.txt

    • And pass a new BUILD_REV per deploy (timestamp/sha) so COPY and pip install steps invalidate as expected.

Artifacts

  • Build Logs excerpt (Aug 15, 2025): all steps “CACHED” including COPY and uv pip install; total build time 9.43 seconds.

  • Deploy logs show app starts and connects to my MCP backend. /openapi.json returns, but expected code changes are not present.

Goal

  • Confirm the simplest, Railway-approved path to force a fresh image when building from DC-AAIA/open-webui-mcpo:main, and ensure we’re not missing a quicker alternative to break the cache for this service.

Thanks in advance. Railway is a fantastic platform and support has been great for me, and I  want to ensure I stay aligned to Railway best practices.

Solved$10 Bounty

9 Replies

Railway
BOT

2 months ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


clashing
HOBBY

2 months ago

https://docs.railway.com/guides/build-configuration#disable-build-layer-caching

You can set the NO_CACHE variable to 1 for that service. That would disable the use of cached copies of the Docker image.

By the way, this caching problem can sometimes be persistent. So, I follow these steps:

a. Create a Docker file for my project (Python/node server), along with .dockerignore to stop pushing unnecessary files to my Docker account (Docker Hub).

b. Create an account on Docker Hub

c. Docker Desktop should also be installed on your local machine.

d. Run the following commands from the project folder to make a Docker image for the same: (Docker Desktop should be running in the background)

docker build -t dockerhub_username/imageName:tag .

If my Docker Hub username is "test" & I want to name the image as serverImg, then the command would look like:

docker build -t test/serverImg:0.1 .

e. docker push test/serverImg:0.1

Then, rather than using the GitHub repo, you can right-click on the Railway dashboard, and click on Docker Image, & provide the image URL along with the tag test/serverImg:0.1 & it would work perfectly.

It is important to use the tag number because otherwise the image gets built with the latest tag & the caching issue doesn't go away. So, the best thing is to increment the tag each time you change the files, so that the new tag will always point to the latest image with the correct code changes. This works for me every time.

First, try setting the NO_CACHE variable to 1 in the service's variables tab. If that does not work, try creating the Docker image on your own (for which you can refer this: https://docs.railway.com/quick-start#deploying-your-project---from-a-docker-image)


dc-aaia
HOBBY

2 months ago

@clashing, outstanding! Thank you for these detailed instructions. I've chased this for 2 days and wish I had the sense to have raised my hand sooner for assistance. The env var would be a very nice and quick fix and am off to try that now. If caching persists, the Docker build route most certainly will aleviate it.

Thanks once again - DC


dc-aaia

@clashing, outstanding! Thank you for these detailed instructions. I've chased this for 2 days and wish I had the sense to have raised my hand sooner for assistance. The env var would be a very nice and quick fix and am off to try that now. If caching persists, the Docker build route most certainly will aleviate it. Thanks once again - DC

clashing
HOBBY

2 months ago

Great dc-aaia

But I guess you mistakenly marked the bot's reply as the solution.


dc-aaia

@clashing, outstanding! Thank you for these detailed instructions. I've chased this for 2 days and wish I had the sense to have raised my hand sooner for assistance. The env var would be a very nice and quick fix and am off to try that now. If caching persists, the Docker build route most certainly will aleviate it. Thanks once again - DC

clashing
HOBBY

2 months ago

If my post helped you, then do mark that as the solution


dc-aaia
HOBBY

2 months ago

Ah got it. I thought I was crediting you.

Obviously I really do need assistance with Railway ... LoL ... Thanks again - DC


dc-aaia

Ah got it. I thought I was crediting you. Obviously I really do need assistance with Railway ... LoL ... Thanks again - DC

clashing
HOBBY

2 months ago

You have to click the Mark as solution button for my initial post that helped you, so that the solution can be marked by the team


dc-aaia
HOBBY

2 months ago

@clashing, thanks and went to your initial post and selected Accept Solution, as adding the env var NO_CACHE=1 in the open-webui-mcpo service worked perfectly! Build time increased from 9 sec to 54 sec and bypassed the cache end-to-end meaning most importantly, all of my src/mcpo/main.py updates finally were applied.

Thank you again for sharing your Railway expertise and experience to solve my issue.

Best - DC


dc-aaia

@clashing, thanks and went to your initial post and selected Accept Solution, as adding the env var NO_CACHE=1 in the open-webui-mcpo service worked perfectly! Build time increased from 9 sec to 54 sec and bypassed the cache end-to-end meaning most importantly, all of my src/mcpo/main.py updates finally were applied. Thank you again for sharing your Railway expertise and experience to solve my issue. Best - DC

clashing
HOBBY

2 months ago

Always there to help


Forcing fresh Docker builds on Railway (cache not invalidating) - Railway Help Station