Dockerfile 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. ARG ENABLE_PROXY=false
  2. ARG APISIX_VERSION=master
  3. ARG ETCD_VERSION=v3.4.14
  4. # Build Apache APISIX
  5. FROM api7/apisix-base:1.19.3.2.2 AS production-stage
  6. ARG APISIX_VERSION
  7. LABEL apisix_version="${APISIX_VERSION}"
  8. ARG ENABLE_PROXY
  9. RUN set -x \
  10. && (test "${ENABLE_PROXY}" != "true" || /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories) \
  11. && apk add --no-cache --virtual .builddeps \
  12. automake \
  13. autoconf \
  14. libtool \
  15. pkgconfig \
  16. cmake \
  17. git \
  18. pcre \
  19. pcre-dev \
  20. openldap-dev \
  21. && luarocks install https://github.com/apache/apisix/raw/master/rockspec/apisix-${APISIX_VERSION}-0.rockspec --tree=/usr/local/apisix/deps \
  22. && cp -v /usr/local/apisix/deps/lib/luarocks/rocks-5.1/apisix/${APISIX_VERSION}-0/bin/apisix /usr/bin/ \
  23. && (function ver_lt { [ "$1" = "$2" ] && return 1 || [ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]; }; if [ "$APISIX_VERSION" = "master" ] || ver_lt 2.2.0 $APISIX_VERSION; then echo 'use shell ';else bin='#! /usr/local/openresty/luajit/bin/luajit\npackage.path = "/usr/local/apisix/?.lua;" .. package.path'; sed -i "1s@.*@$bin@" /usr/bin/apisix ; fi;) \
  24. && mv /usr/local/apisix/deps/share/lua/5.1/apisix /usr/local/apisix \
  25. && apk del .builddeps build-base make unzip
  26. # Build etcd
  27. FROM alpine:3.13 AS etcd-stage
  28. ARG ETCD_VERSION
  29. LABEL etcd_version="${ETCD_VERSION}"
  30. WORKDIR /tmp
  31. RUN wget https://github.com/etcd-io/etcd/releases/download/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-amd64.tar.gz \
  32. && tar -zxvf etcd-${ETCD_VERSION}-linux-amd64.tar.gz \
  33. && ln -s etcd-${ETCD_VERSION}-linux-amd64 etcd
  34. # Finally combine all the resources into one image
  35. FROM alpine:3.13 AS last-stage
  36. ARG ENABLE_PROXY
  37. # add runtime for Apache APISIX
  38. RUN set -x \
  39. && (test "${ENABLE_PROXY}" != "true" || /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories) \
  40. && apk add --no-cache bash libstdc++ curl openldap-dev
  41. WORKDIR /usr/local/apisix
  42. COPY --from=production-stage /usr/local/openresty/ /usr/local/openresty/
  43. COPY --from=production-stage /usr/local/apisix/ /usr/local/apisix/
  44. COPY --from=production-stage /usr/bin/apisix /usr/bin/apisix
  45. COPY --from=etcd-stage /tmp/etcd/etcd /usr/bin/etcd
  46. COPY --from=etcd-stage /tmp/etcd/etcdctl /usr/bin/etcdctl
  47. ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin
  48. EXPOSE 9080 9443 2379 2380
  49. CMD ["sh", "-c", "(nohup etcd >/tmp/etcd.log 2>&1 &) && sleep 10 && /usr/bin/apisix init && /usr/bin/apisix init_etcd && /usr/local/openresty/bin/openresty -p /usr/local/apisix -g 'daemon off;'"]
  50. STOPSIGNAL SIGQUIT