Dockerfile 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. ##### BUILDER #####
  2. FROM golang:1.14-alpine3.11 as builder
  3. ## Task: Install build deps
  4. # hadolint ignore=DL3018
  5. RUN set -eux; \
  6. apk add --no-progress --quiet --no-cache --upgrade --virtual .build-deps \
  7. gcc \
  8. git \
  9. musl-dev
  10. ## Task: copy source files
  11. COPY . /src
  12. WORKDIR /src
  13. ## Task: fetch project deps
  14. RUN go mod download
  15. ## Task: build project
  16. ENV GOOS="linux"
  17. ENV GOARCH="amd64"
  18. ENV CGO_ENABLED="0"
  19. RUN go build -ldflags="-s -w" -o autorestsrv cmd/service.go
  20. ## Task: set permissions
  21. RUN chmod 0755 /src/autorestsrv
  22. ## Task: runtime dependencies
  23. # hadolint ignore=DL3018
  24. RUN set -eux; \
  25. apk add --no-progress --quiet --no-cache --upgrade --virtual .run-deps \
  26. tzdata
  27. # hadolint ignore=DL3018,SC2183,DL4006
  28. RUN set -eu +x; \
  29. apk add --no-progress --quiet --no-cache --upgrade ncurses; \
  30. apk update --quiet; \
  31. printf '%30s\n' | tr ' ' -; \
  32. echo "RUNTIME DEPENDENCIES"; \
  33. PKGNAME=$(apk info --depends .run-deps \
  34. | sed '/^$/d;/depends/d' \
  35. | sort -u ); \
  36. printf '%s\n' "${PKGNAME}" \
  37. | while IFS= read -r pkg; do \
  38. apk info --quiet --description --no-network "${pkg}" \
  39. | sed -n '/description/p' \
  40. | sed -r "s/($(echo "${pkg}" | sed -r 's/\+/\\+/g'))-(.*)\s.*/\1=\2/"; \
  41. done \
  42. | tee -a /usr/share/rundeps; \
  43. printf '%30s\n' | tr ' ' -
  44. ##### TARGET #####
  45. FROM alpine:3.11
  46. ARG RELEASE
  47. ENV IMG_VERSION="${RELEASE}"
  48. COPY --from=builder /src/autorestsrv /usr/local/bin/
  49. COPY --from=builder /src/configs/service.yaml /config/
  50. COPY --from=builder /usr/share/rundeps /usr/share/rundeps
  51. RUN set -eux; \
  52. xargs -a /usr/share/rundeps apk add --no-progress --quiet --no-cache --upgrade --virtual .run-deps
  53. ENTRYPOINT ["/usr/local/bin/autorestsrv"]
  54. CMD ["--config","/config/service.yaml"]
  55. EXPOSE 8080 8443
  56. HEALTHCHECK --interval=30s --timeout=5s --retries=3 --start-period=10s \
  57. CMD wget -q -T 5 --spider http://localhost:8080/health/health
  58. LABEL org.opencontainers.image.title="AutoRest-Service" \
  59. org.opencontainers.image.description="MCS AutoRest Service" \
  60. org.opencontainers.image.version="${IMG_VERSION}" \
  61. org.opencontainers.image.source="https://github.com/willie68/AutoRestIoT.git" \
  62. org.opencontainers.image.vendor="MCS (www.wk-music.de)" \
  63. org.opencontainers.image.authors="Willie@mcs" \
  64. maintainer="MCS" \
  65. NAME="AutoRest-Service"