From 328fc9de1591d175af7a622eb474c03603e7ed6a Mon Sep 17 00:00:00 2001 From: Ashish Tiwari Date: Mon, 11 Sep 2023 09:37:30 +0530 Subject: [PATCH] fix: allow config.yaml to be updated when already present for standalone mode (#494) Signed-off-by: Ashish Tiwari --- ...apisix-docker-example-test-standalone.yaml | 69 +++++++++++++++++++ centos/Dockerfile | 2 +- centos/docker-entrypoint.sh | 12 ++-- debian-dev/docker-entrypoint.sh | 12 ++-- debian/Dockerfile | 2 +- debian/docker-entrypoint.sh | 12 ++-- example/apisix_conf/apisix-standalone.yaml | 25 +++++++ example/docker-compose-standalone.yml | 54 +++++++++++++++ redhat/Dockerfile | 2 +- redhat/docker-entrypoint.sh | 12 ++-- 10 files changed, 179 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/apisix-docker-example-test-standalone.yaml create mode 100644 example/apisix_conf/apisix-standalone.yaml create mode 100644 example/docker-compose-standalone.yml diff --git a/.github/workflows/apisix-docker-example-test-standalone.yaml b/.github/workflows/apisix-docker-example-test-standalone.yaml new file mode 100644 index 00000000..78b0ea7c --- /dev/null +++ b/.github/workflows/apisix-docker-example-test-standalone.yaml @@ -0,0 +1,69 @@ +name: Docker compose CI for example with standalone mode + +on: + schedule: + - cron: "0 1 * * *" + push: + branches: [master] + paths-ignore: + - 'docs/**' + - '**/*.md' + pull_request: + branches: + - master + - 'release/apisix-2.15.**' + +env: + APISIX_VERSION: "3.5.0" + +jobs: + prepare: + runs-on: ubuntu-latest + + steps: + - name: Set apisix version + id: apisix + run: | + branch=${{ github.base_ref }} + apisix_version=$( (echo ${branch} | grep -Po '\d*\.\d*\.\d*') || echo ${APISIX_VERSION} ) + echo "version=${apisix_version}" >> $GITHUB_OUTPUT + + outputs: + apisix-version: ${{ steps.apisix.outputs.version }} + + build: + runs-on: ubuntu-latest + needs: prepare + env: + APISIX_VERSION: ${{ needs.prepare.outputs.apisix-version }} + + strategy: + fail-fast: false + matrix: + platform: + - centos + - debian + - redhat + + steps: + - uses: actions/checkout@v2 + + - name: Build image + run: | + make build-on-${{ matrix.platform }} + + - name: use docker-compose + env: + APISIX_IMAGE_TAG: ${{ format('{0}-{1}', env.APISIX_VERSION, matrix.platform) }} + APISIX_STAND_ALONE: true + run: docker-compose -p docker-apisix -f example/docker-compose-standalone.yml up -d + + - name: Test APISIX + run: | + sleep 50 #startup time maybe a little longer as the yq binary is downloaded for use at runtime + + 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/centos/Dockerfile b/centos/Dockerfile index 72966862..3d5c616f 100644 --- a/centos/Dockerfile +++ b/centos/Dockerfile @@ -21,7 +21,7 @@ ARG APISIX_VERSION=3.5.0 LABEL apisix_version="${APISIX_VERSION}" RUN yum install -y https://repos.apiseven.com/packages/centos/apache-apisix-repo-1.0-1.noarch.rpm \ - && yum install -y apisix-${APISIX_VERSION} \ + && yum install -y apisix-${APISIX_VERSION} wget \ && yum clean all \ && sed -i 's/PASS_MAX_DAYS\t99999/PASS_MAX_DAYS\t60/g' /etc/login.defs diff --git a/centos/docker-entrypoint.sh b/centos/docker-entrypoint.sh index 085c5e55..d3deef62 100755 --- a/centos/docker-entrypoint.sh +++ b/centos/docker-entrypoint.sh @@ -22,21 +22,23 @@ PREFIX=${APISIX_PREFIX:=/usr/local/apisix} if [[ "$1" == "docker-start" ]]; then if [ "$APISIX_STAND_ALONE" = "true" ]; then + # If the file is not present then initialise the content otherwise update relevant keys for standalone mode if [ ! -f "${PREFIX}/conf/config.yaml" ]; then cat > ${PREFIX}/conf/config.yaml << _EOC_ deployment: role: data_plane role_data_plane: config_provider: yaml -_EOC_ - fi - - if [ ! -f "${PREFIX}/conf/apisix.yaml" ]; then - cat > ${PREFIX}/conf/apisix.yaml << _EOC_ routes: - #END _EOC_ + else + wget -qO /usr/local/apisix/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 \ + && chmod a+x /usr/local/apisix/yq + /usr/local/apisix/yq -i '.deployment.role = "data_plane"' ${PREFIX}/conf/config.yaml + /usr/local/apisix/yq -i '.deployment.role_data_plane.config_provider = "yaml"' ${PREFIX}/conf/config.yaml + rm /usr/local/apisix/yq fi /usr/bin/apisix init else diff --git a/debian-dev/docker-entrypoint.sh b/debian-dev/docker-entrypoint.sh index d58b26a3..a451a1c5 100755 --- a/debian-dev/docker-entrypoint.sh +++ b/debian-dev/docker-entrypoint.sh @@ -22,21 +22,23 @@ PREFIX=${APISIX_PREFIX:=/usr/local/apisix} if [[ "$1" == "docker-start" ]]; then if [ "$APISIX_STAND_ALONE" = "true" ]; then + # If the file is not present then initialise the content otherwise update relevant keys for standalone mode if [ ! -f "${PREFIX}/conf/config.yaml" ]; then cat > ${PREFIX}/conf/config.yaml << _EOC_ deployment: role: data_plane role_data_plane: config_provider: yaml -_EOC_ - fi - - if [ ! -f "${PREFIX}/conf/apisix.yaml" ]; then - cat > ${PREFIX}/conf/apisix.yaml << _EOC_ routes: - #END _EOC_ + else + wget -qO /usr/local/apisix/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 \ + && chmod a+x /usr/local/apisix/yq + /usr/local/apisix/yq -i '.deployment.role = "data_plane"' ${PREFIX}/conf/config.yaml + /usr/local/apisix/yq -i '.deployment.role_data_plane.config_provider = "yaml"' ${PREFIX}/conf/config.yaml + rm /usr/local/apisix/yq fi /usr/bin/apisix init else diff --git a/debian/Dockerfile b/debian/Dockerfile index 2d990728..67b7c061 100644 --- a/debian/Dockerfile +++ b/debian/Dockerfile @@ -22,7 +22,7 @@ ARG APISIX_VERSION=3.5.0 RUN set -ex; \ arch=$(dpkg --print-architecture); \ apt update; \ - apt-get -y install --no-install-recommends wget gnupg ca-certificates curl; \ + apt-get -y install --no-install-recommends wget gnupg ca-certificates curl;\ codename=`grep -Po 'VERSION="[0-9]+ \(\K[^)]+' /etc/os-release`; \ wget -O - https://openresty.org/package/pubkey.gpg | apt-key add -; \ case "${arch}" in \ diff --git a/debian/docker-entrypoint.sh b/debian/docker-entrypoint.sh index 085c5e55..d3deef62 100755 --- a/debian/docker-entrypoint.sh +++ b/debian/docker-entrypoint.sh @@ -22,21 +22,23 @@ PREFIX=${APISIX_PREFIX:=/usr/local/apisix} if [[ "$1" == "docker-start" ]]; then if [ "$APISIX_STAND_ALONE" = "true" ]; then + # If the file is not present then initialise the content otherwise update relevant keys for standalone mode if [ ! -f "${PREFIX}/conf/config.yaml" ]; then cat > ${PREFIX}/conf/config.yaml << _EOC_ deployment: role: data_plane role_data_plane: config_provider: yaml -_EOC_ - fi - - if [ ! -f "${PREFIX}/conf/apisix.yaml" ]; then - cat > ${PREFIX}/conf/apisix.yaml << _EOC_ routes: - #END _EOC_ + else + wget -qO /usr/local/apisix/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 \ + && chmod a+x /usr/local/apisix/yq + /usr/local/apisix/yq -i '.deployment.role = "data_plane"' ${PREFIX}/conf/config.yaml + /usr/local/apisix/yq -i '.deployment.role_data_plane.config_provider = "yaml"' ${PREFIX}/conf/config.yaml + rm /usr/local/apisix/yq fi /usr/bin/apisix init else diff --git a/example/apisix_conf/apisix-standalone.yaml b/example/apisix_conf/apisix-standalone.yaml new file mode 100644 index 00000000..b0e4da3c --- /dev/null +++ b/example/apisix_conf/apisix-standalone.yaml @@ -0,0 +1,25 @@ +# +# 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. +# + +routes: + - + uri: /get + upstream: + nodes: + "web1:80": 1 + type: roundrobin +#END diff --git a/example/docker-compose-standalone.yml b/example/docker-compose-standalone.yml new file mode 100644 index 00000000..5f9dd596 --- /dev/null +++ b/example/docker-compose-standalone.yml @@ -0,0 +1,54 @@ +# +# 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. +# + +version: "3" + +services: + apisix: + image: apache/apisix:${APISIX_IMAGE_TAG:-3.5.0-debian} + restart: always + volumes: + - ./apisix_conf/apisix-standalone.yaml:/usr/local/apisix/conf/apisix.yaml:ro + environment: + - APISIX_STAND_ALONE=true + ports: + - "9180:9180/tcp" + - "9080:9080/tcp" + - "9091:9091/tcp" + - "9443:9443/tcp" + - "9092:9092/tcp" + networks: + apisix: + + web1: + image: nginx:1.19.0-alpine + restart: always + volumes: + - ./upstream/web1.conf:/etc/nginx/nginx.conf + ports: + - "9081:80/tcp" + environment: + - NGINX_PORT=80 + networks: + apisix: + + +networks: + apisix: + driver: bridge + + diff --git a/redhat/Dockerfile b/redhat/Dockerfile index 3ed3f6a6..a8b5c79d 100644 --- a/redhat/Dockerfile +++ b/redhat/Dockerfile @@ -23,7 +23,7 @@ COPY ./yum.repos.d/apache-apisix.repo /etc/yum.repos.d/apache-apisix.repo COPY ./yum.repos.d/openresty.repo /etc/yum.repos.d/openresty.repo RUN yum update -y \ - && yum install -y apisix-${APISIX_VERSION} \ + && yum install -y apisix-${APISIX_VERSION} wget\ && yum clean all \ && sed -i 's/PASS_MAX_DAYS\t99999/PASS_MAX_DAYS\t60/g' /etc/login.defs diff --git a/redhat/docker-entrypoint.sh b/redhat/docker-entrypoint.sh index 085c5e55..d3deef62 100755 --- a/redhat/docker-entrypoint.sh +++ b/redhat/docker-entrypoint.sh @@ -22,21 +22,23 @@ PREFIX=${APISIX_PREFIX:=/usr/local/apisix} if [[ "$1" == "docker-start" ]]; then if [ "$APISIX_STAND_ALONE" = "true" ]; then + # If the file is not present then initialise the content otherwise update relevant keys for standalone mode if [ ! -f "${PREFIX}/conf/config.yaml" ]; then cat > ${PREFIX}/conf/config.yaml << _EOC_ deployment: role: data_plane role_data_plane: config_provider: yaml -_EOC_ - fi - - if [ ! -f "${PREFIX}/conf/apisix.yaml" ]; then - cat > ${PREFIX}/conf/apisix.yaml << _EOC_ routes: - #END _EOC_ + else + wget -qO /usr/local/apisix/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 \ + && chmod a+x /usr/local/apisix/yq + /usr/local/apisix/yq -i '.deployment.role = "data_plane"' ${PREFIX}/conf/config.yaml + /usr/local/apisix/yq -i '.deployment.role_data_plane.config_provider = "yaml"' ${PREFIX}/conf/config.yaml + rm /usr/local/apisix/yq fi /usr/bin/apisix init else