Skip to content

Commit 75615da

Browse files
committed
chore: update Haskell Dockerfile for improved caching and dependency management
- Added environment variable to ensure container rebuilds when dependency files change. - Adjusted COPY commands to prevent cache misses by excluding .git and README.md. - Removed unnecessary dummy content and streamlined the build process.
1 parent df7f28a commit 75615da

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

dockerfiles/haskell-9.8.Dockerfile

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM haskell:9.8.4-bullseye
22

3-
WORKDIR /app
3+
# Ensures the container is re-built if go.mod or go.sum changes
4+
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="stack.yaml,package.yaml,stack.yaml.lock"
45

56
RUN mkdir -p /etc/stack
67

@@ -11,24 +12,17 @@ RUN echo "allow-different-user: true" >> /etc/stack/config.yaml
1112
RUN echo "install-ghc: false" >> /etc/stack/config.yaml
1213
RUN echo "system-ghc: true" >> /etc/stack/config.yaml
1314

14-
COPY stack.yaml package.yaml stack.yaml.lock /app/
15+
WORKDIR /app
1516

16-
# Dummy static content to circumvent the /app doesn't exist warning
17-
RUN mkdir /app/app
18-
RUN echo 'main :: IO ()' >> /app/app/Main.hs
19-
RUN echo 'main = putStrLn "Hello, World!"' >> /app/app/Main.hs
17+
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
18+
COPY . /app/
19+
RUN rm -rf /app/.git /app/README.md
2020

2121
ENV STACK_ROOT=/app/.stack
22-
2322
RUN stack build
2423
RUN stack clean codecrafters-http-server
24+
2525
RUN mkdir /app-cached
2626
RUN mv .stack-work /app-cached/.stack-work
2727
RUN mv .stack /app-cached/.stack
28-
2928
RUN rm -rf /app/app
30-
31-
RUN echo "cd \${CODECRAFTERS_REPOSITORY_DIR} && stack build" > /codecrafters-precompile.sh
32-
RUN chmod +x /codecrafters-precompile.sh
33-
34-
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="stack.yaml,package.yaml,stack.yaml.lock"

0 commit comments

Comments
 (0)