Dockerfile 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 ETCD_VERSION=v3.4.14
  19. ARG APISIX_VERSION=master
  20. ARG APISIX_DASHBOARD_VERSION=master
  21. # Build Apache APISIX
  22. FROM openresty/openresty:1.19.3.1-alpine-fat AS production-stage
  23. ARG APISIX_VERSION
  24. ARG ENABLE_PROXY
  25. LABEL apisix_version="${APISIX_VERSION}"
  26. RUN set -x \
  27. && (test "${ENABLE_PROXY}" != "true" || /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories) \
  28. && apk add --no-cache --virtual .builddeps \
  29. automake \
  30. autoconf \
  31. libtool \
  32. pkgconfig \
  33. cmake \
  34. git \
  35. openldap-dev \
  36. && mkdir ~/.luarocks \
  37. && luarocks config variables.OPENSSL_LIBDIR /usr/local/openresty/openssl/lib \
  38. && luarocks config variables.OPENSSL_INCDIR /usr/local/openresty/openssl/include \
  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. && (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;) \
  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. # Build APISIX Dashboard - 1. download source code from github
  54. FROM alpine:latest as pre-build
  55. ARG APISIX_DASHBOARD_VERSION
  56. RUN set -x \
  57. && wget https://github.com/apache/apisix-dashboard/archive/${APISIX_DASHBOARD_VERSION}.tar.gz -O /tmp/apisix-dashboard.tar.gz \
  58. && mkdir /usr/local/apisix-dashboard \
  59. && tar -xvf /tmp/apisix-dashboard.tar.gz -C /usr/local/apisix-dashboard --strip 1
  60. # Build APISIX Dashboard - 2. build manager-api from source code
  61. FROM golang:1.17 as api-builder
  62. ARG APISIX_DASHBOARD_VERSION
  63. ARG ENABLE_PROXY
  64. WORKDIR /usr/local/apisix-dashboard
  65. COPY --from=pre-build /usr/local/apisix-dashboard .
  66. RUN if [ "$ENABLE_PROXY" = "true" ] ; then go env -w GOPROXY=https://goproxy.io,direct ; fi \
  67. && go env -w GO111MODULE=on \
  68. && CGO_ENABLED=0 ./api/build.sh
  69. # Build APISIX Dashboard - 3. build dashboard web-UI from source code
  70. FROM node:14-alpine as fe-builder
  71. ARG ENABLE_PROXY
  72. WORKDIR /usr/local/apisix-dashboard
  73. COPY --from=pre-build /usr/local/apisix-dashboard .
  74. WORKDIR /usr/local/apisix-dashboard/web
  75. RUN if [ "$ENABLE_PROXY" = "true" ] ; then yarn config set registry https://registry.npmmirror.com/ ; fi \
  76. && yarn install \
  77. && yarn build
  78. # Finally combine all the resources into one image
  79. FROM alpine:3.13 AS last-stage
  80. ARG ENABLE_PROXY
  81. # add runtime for Apache APISIX
  82. RUN set -x \
  83. && (test "${ENABLE_PROXY}" != "true" || /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories) \
  84. && apk add --no-cache bash libstdc++ curl
  85. WORKDIR /usr/local/apisix
  86. COPY --from=production-stage /usr/local/openresty/ /usr/local/openresty/
  87. COPY --from=production-stage /usr/local/apisix/ /usr/local/apisix/
  88. COPY --from=production-stage /usr/bin/apisix /usr/bin/apisix
  89. COPY --from=etcd-stage /tmp/etcd/etcd /usr/bin/etcd
  90. COPY --from=etcd-stage /tmp/etcd/etcdctl /usr/bin/etcdctl
  91. ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin
  92. # dashboard
  93. RUN if [ "$ENABLE_PROXY" = "true" ] ; then sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories ; fi \
  94. && apk add lua5.1
  95. WORKDIR /usr/local/apisix-dashboard
  96. COPY --from=api-builder /usr/local/apisix-dashboard/output/ ./
  97. COPY --from=fe-builder /usr/local/apisix-dashboard/output/ ./
  98. RUN mkdir logs
  99. EXPOSE 9080 9443 2379 2380 9000
  100. 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;'"]
  101. STOPSIGNAL SIGQUIT