Dockerfile 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. ##### BUILDER #####
  2. FROM golang:1.13-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 schematic-service cmd/service.go
  20. ## Task: set permissions
  21. RUN chmod 0755 /src/schematic-service
  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/schematic-service /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/schematic-service"]
  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="schematic-service" \
  59. org.opencontainers.image.description="schematic-service" \
  60. org.opencontainers.image.version="${IMG_VERSION}" \
  61. org.opencontainers.image.source="http://bitbucket.easy.de/scm/dm/service-gomicro-go.git" \
  62. org.opencontainers.image.vendor="MCS" \
  63. org.opencontainers.image.authors="MCS" \
  64. maintainer="MCS" \
  65. NAME="schematic-service"