Skip to content

Commit

Permalink
ci: cache NPM and Deno dependencies in Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacThoman committed Jan 28, 2025
1 parent 7651d78 commit b40db8c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
35 changes: 22 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
FROM denoland/deno:2.1.2
LABEL authors="Candiru <[email protected]>"
# Build stage
FROM denoland/deno:2.1.2 AS builder
WORKDIR /app

# Copy all source files
COPY . .

# Cache dependencies
RUN deno cache --import-map=import_map.json main.ts

# Build the application
RUN deno task build

# Set working directory
# Runtime stage
FROM denoland/deno:2.1.2
WORKDIR /app

# Install curl
# Install curl for runtime
USER root
RUN apt-get update && apt-get install -y curl

# Copy the project files
COPY . .
# Copy ALL source files and build artifacts
COPY --from=builder /app/ ./

# Copy the Deno cache
COPY --from=builder /deno-dir/ /deno-dir/

# Ensure the deno user has ownership of the necessary files and directories
# Set permissions
RUN chown -R deno:deno /app

# Switch back to deno user
USER deno

# Expose the port
EXPOSE 3000

# Run the task
CMD ["task", "start"]
CMD ["task", "startnobuild"]
4 changes: 3 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
"tasks": {
"dev": "deno run -A --node-modules-dir npm:vite",
"build": "deno run -A --node-modules-dir npm:vite build",
"cache": "deno cache --import-map=import_map.json main.ts",
"preview": "deno run -A --node-modules-dir npm:vite preview",
"serve": "deno run --allow-net --allow-read jsr:@std/http@1/file-server dist/",
"start": "deno task build && deno run --allow-read --allow-env --allow-net --allow-write main.ts"
"start": "deno task build && deno run --allow-read --allow-env --allow-net --allow-write main.ts",
"startnobuild": "deno run --allow-read --allow-env --allow-net --allow-write main.ts"
},
"compilerOptions": {
"lib": ["ES2020", "DOM", "DOM.Iterable", "deno.ns"]
Expand Down
8 changes: 8 additions & 0 deletions import_map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"imports": {
"@deno/vite-plugin": "npm:@deno/vite-plugin@^1.0.0",
"@oak/oak": "jsr:@oak/oak@^17.1.3",
"@std/http": "jsr:@std/http@^1.0.10",
"vite": "npm:vite@^5.4.8"
}
}

0 comments on commit b40db8c

Please sign in to comment.