vanpet
vanpet12mo ago

RUN deno task in Dockerfile

I have made a script to make DB migrations happen using "deno task migration", and I'd love for it to run that during deployment, using a Dockerfile. Currently my dockerfile looks like this: FROM denoland/deno:1.37.1 WORKDIR /app USER deno EXPOSE 3001 RUN deno task migration init RUN deno task migration run CMD ["deno", "run", "--allow-env", "--allow-read", "--allow-write", "--allow-net", "./src/app.ts"] But during the deployment (using Fly.io), I get an error " > [3/4] RUN deno task migration init: #0 0.242 error: No config file found" I'm a bit lost on what to do next, because those tasks run well locally, the deno.json is there at the root of my project. It looks like this: { "tasks": { "prod": "deno run --allow-env --allow-read --allow-net ./src/app.ts", "dev": "deno run --allow-env --allow-read --allow-net --watch ./src/app.ts", "migration": "deno run --allow-env --allow-read --allow-write --allow-net ./src/database/migrate.ts" } } Can someone point me to the correct direction? Thanks.
1 Reply
Deno AI Helper
Deno AI Helper12mo ago
Based on the documentation, the error message you're seeing suggests that the deno.json configuration file is not being found in the Docker container. This could be because the deno.json file is not being copied into the Docker container during the build process. In your Dockerfile, you need to copy your application files (including deno.json) into the Docker container. You can do this using the COPY command in Dockerfile. Here's how you can modify your Dockerfile:
FROM denoland/deno:1.37.1
WORKDIR /app
COPY . .
USER deno
EXPOSE 3001
RUN deno task migration init
RUN deno task migration run
CMD ["deno", "run", "--allow-env", "--allow-read", "--allow-write", "--allow-net", "./src/app.ts"]
FROM denoland/deno:1.37.1
WORKDIR /app
COPY . .
USER deno
EXPOSE 3001
RUN deno task migration init
RUN deno task migration run
CMD ["deno", "run", "--allow-env", "--allow-read", "--allow-write", "--allow-net", "./src/app.ts"]
The COPY . . command copies all files from your current directory (including deno.json) into the /app directory in the Docker container. Please note that this is a general advice and not explicitly stated in the documentation.