feat: support docker image creation from local codebase (#476)
diff --git a/.github/workflows/apisix_dev_docker_local_test.yaml b/.github/workflows/apisix_dev_docker_local_test.yaml new file mode 100644 index 0000000..e8974c3 --- /dev/null +++ b/.github/workflows/apisix_dev_docker_local_test.yaml
@@ -0,0 +1,66 @@ +name: CI for docker image built from local source code + +on: + schedule: + - cron: "0 1 * * *" + push: + branches: [master] + paths-ignore: + - 'docs/**' + - '**/*.md' + pull_request: + branches: + - master + - 'release/apisix-2.15.**' + +env: + APISIX_IMAGE_TAG: "local" + +jobs: + + build: + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + platform: + - debian + + steps: + - uses: actions/checkout@v2 + + - name: Checkout APISIX code + run: | + git clone https://github.com/apache/apisix.git + + - name: Build image + run: | + cd apisix + tag="apache/apisix:$APISIX_IMAGE_TAG" + docker build -t $tag -f ../debian-dev/Dockerfile.local . + + - name: use docker-compose + run: docker-compose -p docker-apisix -f example/docker-compose.yml up -d + + - name: Test APISIX + run: | + sleep 30 + + curl http://127.0.0.1:9180/apisix/admin/routes/1 \ + -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + { + "uri": "/get", + "upstream": { + "type": "roundrobin", + "nodes": { + "web1:80": 1 + } + } + }' + + result_code=`curl -I -m 10 -o /dev/null -s -w %{http_code} http://127.0.0.1:9080/get` + if [[ $result_code -ne 200 ]];then + printf "result_code: %s\n" "$result_code" + exit 125 + fi
diff --git a/debian-dev/Dockerfile.local b/debian-dev/Dockerfile.local new file mode 100644 index 0000000..c861088 --- /dev/null +++ b/debian-dev/Dockerfile.local
@@ -0,0 +1,76 @@ +# +# 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. +# + +# Use this dockerfile to create a docker image of your apisix local/patched codebase + +FROM api7/apisix-base:dev AS build + +ARG ENABLE_PROXY=false + +ENV DEBIAN_FRONTEND noninteractive + +# replace the source path with the location of apisix related directories in your host machine +# refer: https://web.archive.org/web/20230604150902/https://www.jamestharpe.com/docker-include-files-outside-build-context/ + +COPY ./apisix /usr/local/apisix/apisix +COPY ./conf /usr/local/apisix/conf +COPY ./bin/apisix /usr/bin/apisix +COPY ./rockspec/apisix-master-0.rockspec /usr/local/apisix/rockspec/apisix-master-0.rockspec +COPY ./utils/linux-install-luarocks.sh /usr/local/apisix/linux-install-luarocks.sh + +WORKDIR /usr/local/apisix + +SHELL ["/bin/bash", "-c"] + +RUN set -x \ + && (test "${ENABLE_PROXY}" != "true" || /bin/sed -i 's,http://deb.debian.org,http://mirrors.aliyun.com,g' /etc/apt/sources.list) \ + && apt-get -y update --fix-missing \ + && apt-get install -y curl \ + gawk \ + git \ + libldap2-dev \ + liblua5.1-0-dev \ + lua5.1 \ + sudo \ + unzip \ + wget \ + make \ + libssl-dev \ + && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \ + && source "$HOME/.cargo/env" \ + # rust version 1.69.0 required to compile lua-resty-ldap + && rustup install 1.69.0 \ + && rustup default 1.69.0 \ + && bash ./linux-install-luarocks.sh \ + && luarocks config variables.OPENSSL_INCDIR /usr/include/ \ + && luarocks config variables.PCRE_DIR /usr/local/openresty/pcre \ + && luarocks install rockspec/apisix-master-0.rockspec --tree=/usr/local/apisix/deps --deps-only \ + && mkdir /usr/local/apisix/logs && touch /usr/local/apisix/logs/error.log && touch /usr/local/apisix/logs/access.log + +ENV PATH=$PATH:/usr/local/openresty-debug/luajit/bin:/usr/local/openresty-debug/nginx/sbin:/usr/local/openresty-debug/bin + +EXPOSE 9080 9443 + +RUN wget https://raw.githubusercontent.com/apache/apisix-docker/master/debian-dev/docker-entrypoint.sh + +RUN ["chmod", "+x", "./docker-entrypoint.sh"] + +ENTRYPOINT ["./docker-entrypoint.sh"] + +CMD ["docker-start"] + +STOPSIGNAL SIGQUIT