Dockerfile 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # 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, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. ARG ENABLE_PROXY=false
  18. ARG APISIX_VERSION=2.14.1
  19. ARG ETCD_VERSION=v3.4.14
  20. # Build Apache APISIX
  21. FROM api7/apisix-base:1.19.9.1.6 AS production-stage
  22. ARG APISIX_VERSION
  23. LABEL apisix_version="${APISIX_VERSION}"
  24. ARG ENABLE_PROXY
  25. RUN set -x \
  26. && (test "${ENABLE_PROXY}" != "true" || /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories) \
  27. && apk add --no-cache --virtual .builddeps \
  28. build-base \
  29. automake \
  30. autoconf \
  31. libtool \
  32. pkgconfig \
  33. cmake \
  34. unzip \
  35. curl \
  36. openssl \
  37. git \
  38. openldap-dev \
  39. && git config --global url.https://github.com/.insteadOf git://github.com/ \
  40. && luarocks install https://github.com/apache/apisix/raw/master/rockspec/apisix-${APISIX_VERSION}-0.rockspec --tree=/usr/local/apisix/deps PCRE_DIR=/usr/local/openresty/pcre \
  41. && cp -v /usr/local/apisix/deps/lib/luarocks/rocks-5.1/apisix/${APISIX_VERSION}-0/bin/apisix /usr/bin/ \
  42. && (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;) \
  43. && mv /usr/local/apisix/deps/share/lua/5.1/apisix /usr/local/apisix \
  44. && apk del .builddeps build-base make unzip
  45. # Build etcd
  46. FROM alpine:3.13 AS etcd-stage
  47. ARG ETCD_VERSION
  48. LABEL etcd_version="${ETCD_VERSION}"
  49. WORKDIR /tmp
  50. RUN wget https://github.com/etcd-io/etcd/releases/download/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-amd64.tar.gz \
  51. && tar -zxvf etcd-${ETCD_VERSION}-linux-amd64.tar.gz \
  52. && ln -s etcd-${ETCD_VERSION}-linux-amd64 etcd
  53. # Finally combine all the resources into one image
  54. FROM alpine:3.13 AS last-stage
  55. ARG ENABLE_PROXY
  56. # add runtime for Apache APISIX
  57. RUN set -x \
  58. && (test "${ENABLE_PROXY}" != "true" || /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories) \
  59. && apk add --no-cache bash libstdc++ curl openldap-dev
  60. WORKDIR /usr/local/apisix
  61. COPY --from=production-stage /usr/local/openresty/ /usr/local/openresty/
  62. COPY --from=production-stage /usr/local/apisix/ /usr/local/apisix/
  63. COPY --from=production-stage /usr/bin/apisix /usr/bin/apisix
  64. COPY --from=etcd-stage /tmp/etcd/etcd /usr/bin/etcd
  65. COPY --from=etcd-stage /tmp/etcd/etcdctl /usr/bin/etcdctl
  66. ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin
  67. EXPOSE 9080 9443 2379 2380
  68. 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;'"]
  69. STOPSIGNAL SIGQUIT