Dockerfile 5.5 KB

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