Dockerfile 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #########################################
  2. # Build stage
  3. #########################################
  4. FROM golang:1.21 AS builder
  5. # Repository location
  6. ARG REPOSITORY=github.com/ncarlier
  7. # Artifact name
  8. ARG ARTIFACT=webhookd
  9. # Copy sources into the container
  10. ADD . /go/src/$REPOSITORY/$ARTIFACT
  11. # Set working directory
  12. WORKDIR /go/src/$REPOSITORY/$ARTIFACT
  13. # Build the binary
  14. RUN make
  15. #########################################
  16. # Distribution stage
  17. #########################################
  18. FROM alpine:latest AS slim
  19. # Repository location
  20. ARG REPOSITORY=github.com/ncarlier
  21. # Artifact name
  22. ARG ARTIFACT=webhookd
  23. # User
  24. ARG USER=webhookd
  25. ARG UID=1000
  26. # Create non-root user
  27. RUN adduser \
  28. --disabled-password \
  29. --gecos "" \
  30. --home "$(pwd)" \
  31. --no-create-home \
  32. --uid "$UID" \
  33. "$USER"
  34. # Install deps
  35. RUN apk add --no-cache bash gcompat
  36. # Install binary
  37. COPY --from=builder /go/src/$REPOSITORY/$ARTIFACT/release/$ARTIFACT /usr/local/bin/$ARTIFACT
  38. VOLUME [ "/scripts" ]
  39. EXPOSE 8080
  40. USER $USER
  41. CMD [ "webhookd" ]
  42. #########################################
  43. # Distribution stage with some tooling
  44. #########################################
  45. FROM alpinelinux/docker-cli:latest AS distrib
  46. # Repository location
  47. ARG REPOSITORY=github.com/ncarlier
  48. # Artifact name
  49. ARG ARTIFACT=webhookd
  50. # User
  51. ARG USER=webhookd
  52. ARG UID=1000
  53. # Create non-root user
  54. RUN adduser \
  55. --disabled-password \
  56. --gecos "" \
  57. --home "$(pwd)" \
  58. --no-create-home \
  59. --uid "$UID" \
  60. "$USER"
  61. # Install deps
  62. RUN apk add --no-cache bash gcompat git openssl openssh-client curl jq docker-cli-compose aha
  63. # Install binary and entrypoint
  64. COPY --from=builder /go/src/$REPOSITORY/$ARTIFACT/release/$ARTIFACT /usr/local/bin/$ARTIFACT
  65. COPY docker-entrypoint.sh /
  66. # Define entrypoint
  67. ENTRYPOINT ["/docker-entrypoint.sh"]
  68. VOLUME [ "/scripts" ]
  69. EXPOSE 8080
  70. USER $USER
  71. CMD [ "webhookd" ]