Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Dockerfile 2.6 KiB

3 år sedan
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # ================================
  2. # Build image
  3. # ================================
  4. FROM swift:5.8-jammy as build
  5. # Install OS updates and, if needed, sqlite3
  6. RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
  7. && apt-get -q update \
  8. && apt-get -q dist-upgrade -y\
  9. && rm -rf /var/lib/apt/lists/*
  10. # Set up a build area
  11. WORKDIR /build
  12. # First just resolve dependencies.
  13. # This creates a cached layer that can be reused
  14. # as long as your Package.swift/Package.resolved
  15. # files do not change.
  16. COPY ./Package.* ./
  17. RUN swift package resolve
  18. # Copy entire repo into container
  19. COPY . .
  20. # Build everything, with optimizations
  21. RUN swift build -c release --static-swift-stdlib
  22. # Switch to the staging area
  23. WORKDIR /staging
  24. # Copy main executable to staging area
  25. RUN cp "$(swift build --package-path /build -c release --show-bin-path)/App" ./
  26. # Copy resources bundled by SPM to staging area
  27. RUN find -L "$(swift build --package-path /build -c release --show-bin-path)/" -regex '.*\.resources$' -exec cp -Ra {} ./ \;
  28. # Copy any resources from the public directory and views directory if the directories exist
  29. # Ensure that by default, neither the directory nor any of its contents are writable.
  30. RUN [ -d /build/Public ] && { mv /build/Public ./Public && chmod -R a-w ./Public; } || true
  31. RUN [ -d /build/Resources ] && { mv /build/Resources ./Resources && chmod -R a-w ./Resources; } || true
  32. # ================================
  33. # Run image
  34. # ================================
  35. FROM ubuntu:jammy
  36. # Make sure all system packages are up to date, and install only essential packages.
  37. RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
  38. && apt-get -q update \
  39. && apt-get -q dist-upgrade -y \
  40. && apt-get -q install -y \
  41. ca-certificates \
  42. tzdata \
  43. # If your app or its dependencies import FoundationNetworking, also install `libcurl4`.
  44. # libcurl4 \
  45. # If your app or its dependencies import FoundationXML, also install `libxml2`.
  46. # libxml2 \
  47. && rm -r /var/lib/apt/lists/*
  48. # Create a vapor user and group with /app as its home directory
  49. RUN useradd --user-group --create-home --system --skel /dev/null --home-dir /app vapor
  50. # Switch to the new home directory
  51. WORKDIR /app
  52. # Copy built executable and any staged resources from builder
  53. COPY --from=build --chown=vapor:vapor /staging /app
  54. # Ensure all further commands run as the vapor user
  55. USER vapor:vapor
  56. # Let Docker bind to port 8080
  57. EXPOSE 8080
  58. # Start the Vapor service when the image is run, default to listening on 8080 in production environment
  59. ENTRYPOINT ["./App"]
  60. CMD ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"]