| # |
| # Licensed to the Apache Software Foundation (ASF) under one or more |
| # contributor license agreements. See the NOTICE file distributed with |
| # this work for additional information regarding copyright ownership. |
| # The ASF licenses this file to You under the Apache License, Version 2.0 |
| # (the "License"); you may not use this file except in compliance with |
| # the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| # |
| |
| ARG ENABLE_PROXY=false |
| ARG APISIX_VERSION=2.15.0 |
| ARG ETCD_VERSION=v3.4.14 |
| |
| # Build Apache APISIX |
| FROM api7/apisix-base:1.21.4.1.1 AS production-stage |
| |
| ARG APISIX_VERSION |
| LABEL apisix_version="${APISIX_VERSION}" |
| |
| ARG ENABLE_PROXY |
| |
| RUN set -x \ |
| && (test "${ENABLE_PROXY}" != "true" || /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories) \ |
| && apk add --no-cache --virtual .builddeps \ |
| build-base \ |
| automake \ |
| autoconf \ |
| libtool \ |
| pkgconfig \ |
| cmake \ |
| unzip \ |
| curl \ |
| openssl \ |
| git \ |
| openldap-dev \ |
| && git config --global url.https://github.com/.insteadOf git://github.com/ \ |
| && 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 \ |
| && cp -v /usr/local/apisix/deps/lib/luarocks/rocks-5.1/apisix/${APISIX_VERSION}-0/bin/apisix /usr/bin/ \ |
| && (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;) \ |
| && mv /usr/local/apisix/deps/share/lua/5.1/apisix /usr/local/apisix \ |
| && apk del .builddeps build-base make unzip |
| |
| # Build etcd |
| FROM alpine:3.13 AS etcd-stage |
| |
| ARG ETCD_VERSION |
| LABEL etcd_version="${ETCD_VERSION}" |
| |
| WORKDIR /tmp |
| |
| RUN wget https://github.com/etcd-io/etcd/releases/download/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-amd64.tar.gz \ |
| && tar -zxvf etcd-${ETCD_VERSION}-linux-amd64.tar.gz \ |
| && ln -s etcd-${ETCD_VERSION}-linux-amd64 etcd |
| |
| # Finally combine all the resources into one image |
| FROM alpine:3.13 AS last-stage |
| |
| ARG ENABLE_PROXY |
| # add runtime for Apache APISIX |
| RUN set -x \ |
| && (test "${ENABLE_PROXY}" != "true" || /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories) \ |
| && apk add --no-cache bash libstdc++ curl openldap-dev |
| |
| WORKDIR /usr/local/apisix |
| |
| COPY --from=production-stage /usr/local/openresty/ /usr/local/openresty/ |
| COPY --from=production-stage /usr/local/apisix/ /usr/local/apisix/ |
| COPY --from=production-stage /usr/bin/apisix /usr/bin/apisix |
| |
| COPY --from=etcd-stage /tmp/etcd/etcd /usr/bin/etcd |
| COPY --from=etcd-stage /tmp/etcd/etcdctl /usr/bin/etcdctl |
| |
| ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin |
| |
| EXPOSE 9080 9443 2379 2380 |
| |
| 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;'"] |
| |
| STOPSIGNAL SIGQUIT |