Dockerfile 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. ARG ALPINE_VERSION="3.12"
  18. FROM alpine:${ALPINE_VERSION} AS builder
  19. SHELL ["/bin/ash", "-e", "-x", "-c", "-o", "pipefail"]
  20. ARG PGBOUNCER_VERSION
  21. ARG AIRFLOW_PGBOUNCER_VERSION
  22. ARG PGBOUNCER_SHA256="a0c13d10148f557e36ff7ed31793abb7a49e1f8b09aa2d4695d1c28fa101fee7"
  23. # Those are build deps only but still we want the latest versions of those
  24. # "Pin versions in apk add" https://github.com/hadolint/hadolint/wiki/DL3018
  25. # hadolint ignore=DL3018
  26. RUN apk --no-cache add make pkgconfig build-base libtool wget gcc g++ libevent-dev libressl-dev c-ares-dev ca-certificates
  27. # We are not using Dash so we can safely ignore the "Dash warning"
  28. # "In dash, something is not supported." https://github.com/koalaman/shellcheck/wiki/SC2169
  29. # hadolint ignore=SC2169,SC3060
  30. RUN wget --progress=dot:giga "https://github.com/pgbouncer/pgbouncer/releases/download/pgbouncer_${PGBOUNCER_VERSION//\./_}/pgbouncer-${PGBOUNCER_VERSION}.tar.gz" \
  31. && echo "${PGBOUNCER_SHA256} pgbouncer-${PGBOUNCER_VERSION}.tar.gz" | sha256sum -c - \
  32. && tar -xzvf pgbouncer-$PGBOUNCER_VERSION.tar.gz
  33. WORKDIR /pgbouncer-$PGBOUNCER_VERSION
  34. RUN ./configure --prefix=/usr --disable-debug && make && make install \
  35. && mkdir /etc/pgbouncer \
  36. && cp ./etc/pgbouncer.ini /etc/pgbouncer/ \
  37. && touch /etc/pgbouncer/userlist.txt \
  38. && sed -i -e "s|logfile = |#logfile = |" \
  39. -e "s|pidfile = |#pidfile = |" \
  40. -e "s|listen_addr = .*|listen_addr = 0.0.0.0|" \
  41. -e "s|auth_type = .*|auth_type = md5|" \
  42. /etc/pgbouncer/pgbouncer.ini
  43. FROM alpine:${ALPINE_VERSION}
  44. ARG PGBOUNCER_VERSION
  45. ARG AIRFLOW_PGBOUNCER_VERSION
  46. ARG COMMIT_SHA
  47. # We want to make sure this one includes latest security fixes.
  48. # "Pin versions in apk add" https://github.com/hadolint/hadolint/wiki/DL3018
  49. # hadolint ignore=DL3018
  50. RUN apk --no-cache add libevent libressl c-ares
  51. COPY --from=builder /etc/pgbouncer /etc/pgbouncer
  52. COPY --from=builder /usr/bin/pgbouncer /usr/bin/pgbouncer
  53. LABEL org.apache.airflow.component="pgbouncer" \
  54. org.apache.airflow.pgbouncer.version="${PGBOUNCER_VERSION}" \
  55. org.apache.airflow.airflow-pgbouncer.version="${AIRFLOW_PGBOUNCER_VERSION}" \
  56. org.apache.airflow.commit-sha="${COMMIT_SHA}" \
  57. maintainer="Apache Airflow Community <dev@airflow.apache.org>"
  58. # Healthcheck
  59. HEALTHCHECK --interval=10s --timeout=3s CMD stat /tmp/.s.PGSQL.*
  60. EXPOSE 6432
  61. # pgbouncer can't run as root, so let's drop to 'nobody'
  62. ENTRYPOINT ["/usr/bin/pgbouncer", "-u", "nobody", "/etc/pgbouncer/pgbouncer.ini" ]