Dockerfile 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. ARG ENABLE_PROXY=false
  2. ARG ETCD_VERSION=v3.4.14
  3. ARG APISIX_VERSION=master
  4. ARG APISIX_DASHBOARD_VERSION=master
  5. # Build Apache APISIX
  6. FROM openresty/openresty:1.19.3.1-alpine-fat AS production-stage
  7. ARG APISIX_VERSION
  8. ARG ENABLE_PROXY
  9. LABEL apisix_version="${APISIX_VERSION}"
  10. RUN set -x \
  11. && (test "${ENABLE_PROXY}" != "true" || /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories) \
  12. && apk add --no-cache --virtual .builddeps \
  13. automake \
  14. autoconf \
  15. libtool \
  16. pkgconfig \
  17. cmake \
  18. git \
  19. pcre \
  20. pcre-dev \
  21. openldap-dev \
  22. && mkdir ~/.luarocks \
  23. && luarocks config variables.OPENSSL_LIBDIR /usr/local/openresty/openssl/lib \
  24. && luarocks config variables.OPENSSL_INCDIR /usr/local/openresty/openssl/include \
  25. && luarocks install https://github.com/apache/apisix/raw/master/rockspec/apisix-${APISIX_VERSION}-0.rockspec --tree=/usr/local/apisix/deps \
  26. && cp -v /usr/local/apisix/deps/lib/luarocks/rocks-5.1/apisix/${APISIX_VERSION}-0/bin/apisix /usr/bin/ \
  27. && (if [ "$APISIX_VERSION" = "master" ] || [ "$APISIX_VERSION" \> "2.2" ]; 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;) \
  28. && mv /usr/local/apisix/deps/share/lua/5.1/apisix /usr/local/apisix \
  29. && apk del .builddeps build-base make unzip
  30. # Build etcd
  31. FROM alpine:3.13 AS etcd-stage
  32. ARG ETCD_VERSION
  33. LABEL etcd_version="${ETCD_VERSION}"
  34. WORKDIR /tmp
  35. RUN wget https://github.com/etcd-io/etcd/releases/download/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-amd64.tar.gz \
  36. && tar -zxvf etcd-${ETCD_VERSION}-linux-amd64.tar.gz \
  37. && ln -s etcd-${ETCD_VERSION}-linux-amd64 etcd
  38. # Build APISIX Dashboard - 1. download source code from github
  39. FROM alpine:latest as pre-build
  40. ARG APISIX_DASHBOARD_VERSION
  41. RUN set -x \
  42. && wget https://github.com/apache/apisix-dashboard/archive/${APISIX_DASHBOARD_VERSION}.tar.gz -O /tmp/apisix-dashboard.tar.gz \
  43. && mkdir /usr/local/apisix-dashboard \
  44. && tar -xvf /tmp/apisix-dashboard.tar.gz -C /usr/local/apisix-dashboard --strip 1
  45. # Build APISIX Dashboard - 2. build manager-api from source code
  46. FROM golang:1.14 as api-builder
  47. ARG APISIX_DASHBOARD_VERSION
  48. ARG ENABLE_PROXY
  49. WORKDIR /usr/local/apisix-dashboard
  50. COPY --from=pre-build /usr/local/apisix-dashboard .
  51. RUN if [ "$ENABLE_PROXY" = "true" ] ; then go env -w GOPROXY=https://goproxy.io,direct ; fi \
  52. && go env -w GO111MODULE=on \
  53. && CGO_ENABLED=0 ./api/build.sh
  54. # Build APISIX Dashboard - 3. build dashboard web-UI from source code
  55. FROM node:14-alpine as fe-builder
  56. ARG ENABLE_PROXY
  57. WORKDIR /usr/local/apisix-dashboard
  58. COPY --from=pre-build /usr/local/apisix-dashboard .
  59. WORKDIR /usr/local/apisix-dashboard/web
  60. RUN if [ "$ENABLE_PROXY" = "true" ] ; then yarn config set registry https://registry.npm.taobao.org/ ; fi \
  61. && yarn install \
  62. && yarn build
  63. # Finally combine all the resources into one image
  64. FROM alpine:3.13 AS last-stage
  65. ARG ENABLE_PROXY
  66. # add runtime for Apache APISIX
  67. RUN set -x \
  68. && (test "${ENABLE_PROXY}" != "true" || /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories) \
  69. && apk add --no-cache bash libstdc++ curl
  70. WORKDIR /usr/local/apisix
  71. COPY --from=production-stage /usr/local/openresty/ /usr/local/openresty/
  72. COPY --from=production-stage /usr/local/apisix/ /usr/local/apisix/
  73. COPY --from=production-stage /usr/bin/apisix /usr/bin/apisix
  74. COPY --from=etcd-stage /tmp/etcd/etcd /usr/bin/etcd
  75. COPY --from=etcd-stage /tmp/etcd/etcdctl /usr/bin/etcdctl
  76. ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin
  77. # dashboard
  78. RUN if [ "$ENABLE_PROXY" = "true" ] ; then sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories ; fi \
  79. && apk add lua5.1
  80. WORKDIR /usr/local/apisix-dashboard
  81. COPY --from=api-builder /usr/local/apisix-dashboard/output/ ./
  82. COPY --from=fe-builder /usr/local/apisix-dashboard/output/ ./
  83. RUN mkdir logs
  84. EXPOSE 9080 9443 2379 2380 9000
  85. CMD ["sh", "-c", "(nohup etcd >/tmp/etcd.log 2>&1 &) && sleep 10 && (/usr/local/apisix-dashboard/manager-api &) && cd /usr/local/apisix && /usr/bin/apisix init && /usr/bin/apisix init_etcd && /usr/local/openresty/bin/openresty -p /usr/local/apisix -g 'daemon off;'"]
  86. STOPSIGNAL SIGQUIT