diff --git a/serving/samples/helloworld-haskell/Dockerfile b/serving/samples/helloworld-haskell/Dockerfile index 8a9626b4c..3a5871619 100644 --- a/serving/samples/helloworld-haskell/Dockerfile +++ b/serving/samples/helloworld-haskell/Dockerfile @@ -1,21 +1,26 @@ -# Use the existing Haskell image as our base +# Use the official Haskell image to create a build artifact. +# https://hub.docker.com/_/haskell/ FROM haskell:8.2.2 as builder -# Checkout our code onto the Docker container +# Copy local code to the container image. WORKDIR /app -ADD . /app +COPY . . -# Build and test our code, then install the “helloworld-haskell-exe” executable +# Build and test our code, then build the “helloworld-haskell-exe” executable. RUN stack setup RUN stack build --copy-bins -# Copy the "helloworld-haskell-exe" executable to the image using docker multi stage build +# Use a Docker multi-stage build to create a lean production image. +# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds FROM fpco/haskell-scratch:integer-gmp + +# Copy the "helloworld-haskell-exe" executable from the builder stage to the production image. WORKDIR /root/ COPY --from=builder /root/.local/bin/helloworld-haskell-exe . -# Expose a port to run our application -EXPOSE 8080 +# Configure and document the service HTTP port. +ENV PORT 8080 +EXPOSE $PORT -# Run the server command +# Run the web service on container startup. CMD ["./helloworld-haskell-exe"] diff --git a/serving/samples/helloworld-haskell/README.md b/serving/samples/helloworld-haskell/README.md index 4d9e55e68..671a67a3e 100644 --- a/serving/samples/helloworld-haskell/README.md +++ b/serving/samples/helloworld-haskell/README.md @@ -80,27 +80,32 @@ following instructions recreate the source files from this folder. block below into it. ```docker - # Use the existing Haskell image as our base - FROM haskell:8.2.2 as builder + # Use the official Haskell image to create a build artifact. + # https://hub.docker.com/_/haskell/ + FROM haskell:8.2.2 as builder - # Checkout our code onto the Docker container - WORKDIR /app - ADD . /app + # Copy local code to the container image. + WORKDIR /app + COPY . . - # Build and test our code, then install the “helloworld-haskell-exe” executable - RUN stack setup - RUN stack build --copy-bins + # Build and test our code, then build the “helloworld-haskell-exe” executable. + RUN stack setup + RUN stack build --copy-bins - # Copy the "helloworld-haskell-exe" executable to the image using docker multi stage build - FROM fpco/haskell-scratch:integer-gmp - WORKDIR /root/ - COPY --from=builder /root/.local/bin/helloworld-haskell-exe . + # Use a Docker multi-stage build to create a lean production image. + # https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds + FROM fpco/haskell-scratch:integer-gmp - # Expose a port to run our application - EXPOSE 8080 + # Copy the "helloworld-haskell-exe" executable from the builder stage to the production image. + WORKDIR /root/ + COPY --from=builder /root/.local/bin/helloworld-haskell-exe . - # Run the server command - CMD ["./helloworld-haskell-exe"] + # Configure and document the service HTTP port. + ENV PORT 8080 + EXPOSE $PORT + + # Run the web service on container startup. + CMD ["./helloworld-haskell-exe"] ``` 1. Create a new file, `service.yaml` and copy the following service definition