Vapor Access Services Repository
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

66 linhas
2.2 KiB

  1. # ================================
  2. # Build image
  3. # ================================
  4. FROM swift:5.3-focal 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 and test discovery
  21. RUN swift build --enable-test-discovery -c release
  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)/Run" ./
  26. # Copy any resouces from the public directory and views directory if the directories exist
  27. # Ensure that by default, neither the directory nor any of its contents are writable.
  28. RUN [ -d /build/Public ] && { mv /build/Public ./Public && chmod -R a-w ./Public; } || true
  29. RUN [ -d /build/Resources ] && { mv /build/Resources ./Resources && chmod -R a-w ./Resources; } || true
  30. # ================================
  31. # Run image
  32. # ================================
  33. FROM swift:5.3-focal-slim
  34. # Make sure all system packages are up to date.
  35. RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true && \
  36. apt-get -q update && apt-get -q dist-upgrade -y && rm -r /var/lib/apt/lists/*
  37. # Create a vapor user and group with /app as its home directory
  38. RUN useradd --user-group --create-home --system --skel /dev/null --home-dir /app vapor
  39. # Switch to the new home directory
  40. WORKDIR /app
  41. # Copy built executable and any staged resources from builder
  42. COPY --from=build --chown=vapor:vapor /staging /app
  43. # Ensure all further commands run as the vapor user
  44. USER vapor:vapor
  45. # Let Docker bind to port 8080
  46. EXPOSE 8080
  47. # Start the Vapor service when the image is run, default to listening on 8080 in production environment
  48. ENTRYPOINT ["./Run"]
  49. CMD ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"]