Dockerfile 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. pcre \
  36. pcre-dev \
  37. openldap-dev \
  38. && mkdir ~/.luarocks \
  39. && luarocks config variables.OPENSSL_LIBDIR /usr/local/openresty/openssl/lib \
  40. && luarocks config variables.OPENSSL_INCDIR /usr/local/openresty/openssl/include \
  41. && git config --global url.https://github.com/.insteadOf git://github.com/ \
  42. && luarocks install https://github.com/apache/apisix/raw/master/rockspec/apisix-${APISIX_VERSION}-0.rockspec --tree=/usr/local/apisix/deps \
  43. && cp -v /usr/local/apisix/deps/lib/luarocks/rocks-5.1/apisix/${APISIX_VERSION}-0/bin/apisix /usr/bin/ \
  44. && (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;) \
  45. && mv /usr/local/apisix/deps/share/lua/5.1/apisix /usr/local/apisix \
  46. && apk del .builddeps build-base make unzip
  47. # Build etcd
  48. FROM alpine:3.13 AS etcd-stage
  49. ARG ETCD_VERSION
  50. LABEL etcd_version="${ETCD_VERSION}"
  51. WORKDIR /tmp
  52. RUN wget https://github.com/etcd-io/etcd/releases/download/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-amd64.tar.gz \
  53. && tar -zxvf etcd-${ETCD_VERSION}-linux-amd64.tar.gz \
  54. && ln -s etcd-${ETCD_VERSION}-linux-amd64 etcd
  55. # Build APISIX Dashboard - 1. download source code from github
  56. FROM alpine:latest as pre-build
  57. ARG APISIX_DASHBOARD_VERSION
  58. RUN set -x \
  59. && wget https://github.com/apache/apisix-dashboard/archive/${APISIX_DASHBOARD_VERSION}.tar.gz -O /tmp/apisix-dashboard.tar.gz \
  60. && mkdir /usr/local/apisix-dashboard \
  61. && tar -xvf /tmp/apisix-dashboard.tar.gz -C /usr/local/apisix-dashboard --strip 1
  62. # Build APISIX Dashboard - 2. build manager-api from source code
  63. FROM golang:1.17 as api-builder
  64. ARG APISIX_DASHBOARD_VERSION
  65. ARG ENABLE_PROXY
  66. WORKDIR /usr/local/apisix-dashboard
  67. COPY --from=pre-build /usr/local/apisix-dashboard .
  68. RUN if [ "$ENABLE_PROXY" = "true" ] ; then go env -w GOPROXY=https://goproxy.io,direct ; fi \
  69. && go env -w GO111MODULE=on \
  70. && CGO_ENABLED=0 ./api/build.sh
  71. # Build APISIX Dashboard - 3. build dashboard web-UI from source code
  72. FROM node:14-alpine as fe-builder
  73. ARG ENABLE_PROXY
  74. WORKDIR /usr/local/apisix-dashboard
  75. COPY --from=pre-build /usr/local/apisix-dashboard .
  76. WORKDIR /usr/local/apisix-dashboard/web
  77. RUN if [ "$ENABLE_PROXY" = "true" ] ; then yarn config set registry https://registry.npm.taobao.org/ ; fi \
  78. && yarn install \
  79. && yarn build
  80. # Finally combine all the resources into one image
  81. FROM alpine:3.13 AS last-stage
  82. ARG ENABLE_PROXY
  83. # add runtime for Apache APISIX
  84. RUN set -x \
  85. && (test "${ENABLE_PROXY}" != "true" || /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories) \
  86. && apk add --no-cache bash libstdc++ curl
  87. WORKDIR /usr/local/apisix
  88. COPY --from=production-stage /usr/local/openresty/ /usr/local/openresty/
  89. COPY --from=production-stage /usr/local/apisix/ /usr/local/apisix/
  90. COPY --from=production-stage /usr/bin/apisix /usr/bin/apisix
  91. COPY --from=etcd-stage /tmp/etcd/etcd /usr/bin/etcd
  92. COPY --from=etcd-stage /tmp/etcd/etcdctl /usr/bin/etcdctl
  93. ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin
  94. # dashboard
  95. RUN if [ "$ENABLE_PROXY" = "true" ] ; then sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories ; fi \
  96. && apk add lua5.1
  97. WORKDIR /usr/local/apisix-dashboard
  98. COPY --from=api-builder /usr/local/apisix-dashboard/output/ ./
  99. COPY --from=fe-builder /usr/local/apisix-dashboard/output/ ./
  100. RUN mkdir logs
  101. EXPOSE 9080 9443 2379 2380 9000
  102. 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;'"]
  103. STOPSIGNAL SIGQUIT