From 16297d670e851510dccf6a935bb19e215f3db37c Mon Sep 17 00:00:00 2001 From: Shubhendra Kushwaha Date: Mon, 22 Jul 2024 23:04:23 +0530 Subject: [PATCH 1/3] fix: update docker-entrypoint.sh to avoid modifying the config files in standalone mode. - Removed direct file modifications in read-only environments - Added checks for required fields in config.yaml for standalone mode - Ensure the script exits with an error if the required fields are missing --- debian-dev/docker-entrypoint.sh | 21 +++++++++++++++++---- debian/docker-entrypoint.sh | 22 ++++++++++++++++++---- redhat/docker-entrypoint.sh | 27 +++++++++++++++++++++++---- 3 files changed, 58 insertions(+), 12 deletions(-) diff --git a/debian-dev/docker-entrypoint.sh b/debian-dev/docker-entrypoint.sh index 56b2566f..15af65f1 100755 --- a/debian-dev/docker-entrypoint.sh +++ b/debian-dev/docker-entrypoint.sh @@ -31,11 +31,24 @@ deployment: config_provider: yaml _EOC_ else - # updating config.yaml for standalone mode - echo "$(sed 's/role: traditional/role: data_plane/g' ${PREFIX}/conf/config.yaml)" > ${PREFIX}/conf/config.yaml - echo "$(sed 's/role_traditional:/role_data_plane:/g' ${PREFIX}/conf/config.yaml)" > ${PREFIX}/conf/config.yaml - echo "$(sed 's/config_provider: etcd/config_provider: yaml/g' ${PREFIX}/conf/config.yaml)" > ${PREFIX}/conf/config.yaml + # Check if the deployment role is set to data_plane and config provider is set to yaml for standalone mode + if ! grep -q 'role: data_plane' "${PREFIX}/conf/config.yaml"; then + echo "Error: ${PREFIX}/conf/config.yaml does not contain 'role: data_plane'. Deployment role must be set to 'data_plane' for standalone mode." + echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" + exit 1 + fi + if ! grep -q 'role_data_plane:' "${PREFIX}/conf/config.yaml"; then + echo "Error: ${PREFIX}/conf/config.yaml does not contain 'role_data_plane:'." + echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" + exit 1 + fi + + if ! grep -q 'config_provider: yaml' "${PREFIX}/conf/config.yaml"; then + echo "Error: ${PREFIX}/conf/config.yaml does not contain 'config_provider: yaml'. Config provider must be set to 'yaml' for standalone mode." + echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" + exit 1 + fi fi if [ ! -f "${PREFIX}/conf/apisix.yaml" ]; then diff --git a/debian/docker-entrypoint.sh b/debian/docker-entrypoint.sh index 2d8a11e3..d4757bb6 100755 --- a/debian/docker-entrypoint.sh +++ b/debian/docker-entrypoint.sh @@ -31,10 +31,24 @@ deployment: config_provider: yaml _EOC_ else - # updating config.yaml for standalone mode - echo "$(sed 's/role: traditional/role: data_plane/g' ${PREFIX}/conf/config.yaml)" > ${PREFIX}/conf/config.yaml - echo "$(sed 's/role_traditional:/role_data_plane:/g' ${PREFIX}/conf/config.yaml)" > ${PREFIX}/conf/config.yaml - echo "$(sed 's/config_provider: etcd/config_provider: yaml/g' ${PREFIX}/conf/config.yaml)" > ${PREFIX}/conf/config.yaml + # Check if the deployment role is set to data_plane and config provider is set to yaml for standalone mode + if ! grep -q 'role: data_plane' "${PREFIX}/conf/config.yaml"; then + echo "Error: ${PREFIX}/conf/config.yaml does not contain 'role: data_plane'. Deployment role must be set to 'data_plane' for standalone mode." + echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" + exit 1 + fi + + if ! grep -q 'role_data_plane:' "${PREFIX}/conf/config.yaml"; then + echo "Error: ${PREFIX}/conf/config.yaml does not contain 'role_data_plane:'." + echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" + exit 1 + fi + + if ! grep -q 'config_provider: yaml' "${PREFIX}/conf/config.yaml"; then + echo "Error: ${PREFIX}/conf/config.yaml does not contain 'config_provider: yaml'. Config provider must be set to 'yaml' for standalone mode." + echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" + exit 1 + fi fi if [ ! -f "${PREFIX}/conf/apisix.yaml" ]; then diff --git a/redhat/docker-entrypoint.sh b/redhat/docker-entrypoint.sh index 2d8a11e3..acefc881 100755 --- a/redhat/docker-entrypoint.sh +++ b/redhat/docker-entrypoint.sh @@ -31,10 +31,29 @@ deployment: config_provider: yaml _EOC_ else - # updating config.yaml for standalone mode - echo "$(sed 's/role: traditional/role: data_plane/g' ${PREFIX}/conf/config.yaml)" > ${PREFIX}/conf/config.yaml - echo "$(sed 's/role_traditional:/role_data_plane:/g' ${PREFIX}/conf/config.yaml)" > ${PREFIX}/conf/config.yaml - echo "$(sed 's/config_provider: etcd/config_provider: yaml/g' ${PREFIX}/conf/config.yaml)" > ${PREFIX}/conf/config.yaml + # Check if the deployment role is set to data_plane and config provider is set to yaml for standalone mode + if ! grep -q 'role: data_plane' "${PREFIX}/conf/config.yaml"; then + echo "Error: ${PREFIX}/conf/config.yaml does not contain 'role: data_plane'. Deployment role must be set to 'data_plane' for standalone mode." + echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" + exit 1 + fi + if ! grep -q 'role: data_plane' "${PREFIX}/conf/config.yaml"; then + echo "Error: ${PREFIX}/conf/config.yaml does not contain 'role: data_plane'. Deployment role must be set to 'data_plane' for standalone mode." + echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" + exit 1 + fi + + if ! grep -q 'role_data_plane:' "${PREFIX}/conf/config.yaml"; then + echo "Error: ${PREFIX}/conf/config.yaml does not contain 'role_data_plane:'." + echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" + exit 1 + fi + + if ! grep -q 'config_provider: yaml' "${PREFIX}/conf/config.yaml"; then + echo "Error: ${PREFIX}/conf/config.yaml does not contain 'config_provider: yaml'. Config provider must be set to 'yaml' for standalone mode." + echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" + exit 1 + fi fi if [ ! -f "${PREFIX}/conf/apisix.yaml" ]; then From b6efaac950d1c00de3dcba952065c430e81dcb70 Mon Sep 17 00:00:00 2001 From: Shubhendra Kushwaha Date: Mon, 22 Jul 2024 23:12:06 +0530 Subject: [PATCH 2/3] chore: add config file for standalone mode in examples --- example/apisix_conf/config-standalone.yaml | 25 ++++++++++++++++++++++ example/docker-compose-standalone.yml | 1 + 2 files changed, 26 insertions(+) create mode 100644 example/apisix_conf/config-standalone.yaml diff --git a/example/apisix_conf/config-standalone.yaml b/example/apisix_conf/config-standalone.yaml new file mode 100644 index 00000000..e8a963f6 --- /dev/null +++ b/example/apisix_conf/config-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. +# + +apisix: + node_listen: 9080 # APISIX listening port + enable_ipv6: false + +deployment: + role: data_plane + role_data_plane: + config_provider: yaml diff --git a/example/docker-compose-standalone.yml b/example/docker-compose-standalone.yml index 039873f9..01303cff 100644 --- a/example/docker-compose-standalone.yml +++ b/example/docker-compose-standalone.yml @@ -23,6 +23,7 @@ services: restart: always volumes: - ./apisix_conf/apisix-standalone.yaml:/usr/local/apisix/conf/apisix.yaml:ro + - ./apisix_conf/config-standalone.yaml:/usr/local/apisix/conf/config.yaml:ro environment: - APISIX_STAND_ALONE=true ports: From 541f68b8ba1c09b8e66c4b8d3fcb70ced7bf2066 Mon Sep 17 00:00:00 2001 From: Shubhendra Kushwaha Date: Wed, 14 Aug 2024 16:12:30 +0530 Subject: [PATCH 3/3] ci: Extract config file check logic to a separate script --- Makefile | 14 ++++++++++++++ debian-dev/Dockerfile | 1 + debian-dev/Dockerfile.local | 1 + debian-dev/docker-entrypoint.sh | 18 +----------------- debian/Dockerfile | 1 + debian/docker-entrypoint.sh | 18 +----------------- redhat/Dockerfile | 1 + redhat/docker-entrypoint.sh | 23 +---------------------- utils/check_standalone_config.sh | 17 +++++++++++++++++ 9 files changed, 38 insertions(+), 56 deletions(-) create mode 100644 utils/check_standalone_config.sh diff --git a/Makefile b/Makefile index 0fd06a73..9fd5874e 100644 --- a/Makefile +++ b/Makefile @@ -75,14 +75,18 @@ endef .PHONY: build-on-redhat build-on-redhat: @$(call func_echo_status, "$@ -> [ Start ]") + cp ./utils/check_standalone_config.sh redhat/check_standalone_config.sh $(ENV_DOCKER) build -t $(ENV_APISIX_IMAGE_TAG_NAME)-redhat -f ./redhat/Dockerfile redhat + rm -f redhat/check_standalone_config.sh @$(call func_echo_success_status, "$@ -> [ Done ]") ### build-on-debian-dev : Build apache/apisix:xx-debian-dev image .PHONY: build-on-debian-dev build-on-debian-dev: @$(call func_echo_status, "$@ -> [ Start ]") + cp ./utils/check_standalone_config.sh debian-dev/check_standalone_config.sh $(ENV_DOCKER) build -t $(ENV_APISIX_IMAGE_TAG_NAME)-debian-dev -f ./debian-dev/Dockerfile debian-dev + rm -f debian-dev/check_standalone_config.sh @$(call func_echo_success_status, "$@ -> [ Done ]") ### build-on-debian-local-dev : Build apache/apisix:xx-debian-dev image @@ -103,7 +107,9 @@ endif .PHONY: build-on-debian build-on-debian: @$(call func_echo_status, "$@ -> [ Start ]") + cp ./utils/check_standalone_config.sh debian/check_standalone_config.sh $(ENV_DOCKER) build -t $(ENV_APISIX_IMAGE_TAG_NAME)-debian -f ./debian/Dockerfile debian + rm -f debian/check_standalone_config.sh @$(call func_echo_success_status, "$@ -> [ Done ]") @@ -111,10 +117,12 @@ build-on-debian: .PHONY: push-multiarch-dev-on-debian push-multiarch-dev-on-debian: @$(call func_echo_status, "$@ -> [ Start ]") + cp ./utils/check_standalone_config.sh debian-dev/check_standalone_config.sh $(ENV_DOCKER) buildx build --network=host --push \ -t $(IMAGE_NAME):dev \ --platform linux/amd64,linux/arm64 \ -f ./debian-dev/Dockerfile debian-dev + rm -f debian-dev/check_standalone_config.sh @$(call func_echo_success_status, "$@ -> [ Done ]") @@ -122,10 +130,12 @@ push-multiarch-dev-on-debian: .PHONY: push-multiarch-on-debian push-multiarch-on-debian: @$(call func_echo_status, "$@ -> [ Start ]") + cp ./utils/check_standalone_config.sh debian/check_standalone_config.sh $(ENV_DOCKER) buildx build --network=host --push \ -t $(ENV_APISIX_IMAGE_TAG_NAME)-debian \ --platform linux/amd64,linux/arm64 \ -f ./debian/Dockerfile debian + rm -f debian/check_standalone_config.sh @$(call func_echo_success_status, "$@ -> [ Done ]") @@ -133,10 +143,12 @@ push-multiarch-on-debian: .PHONY: push-multiarch-on-redhat push-multiarch-on-redhat: @$(call func_echo_status, "$@ -> [ Start ]") + cp ./utils/check_standalone_config.sh redhat/check_standalone_config.sh $(ENV_DOCKER) buildx build --network=host --push \ -t $(ENV_APISIX_IMAGE_TAG_NAME)-redhat \ --platform linux/amd64,linux/arm64 \ -f ./redhat/Dockerfile redhat + rm -f redhat/check_standalone_config.sh @$(call func_echo_success_status, "$@ -> [ Done ]") ### push-multiarch-on-latest : Push apache/apisix:latest image @@ -147,10 +159,12 @@ push-multiarch-on-redhat: push-multiarch-on-latest: @$(call func_echo_status, "$@ -> [ Start ]") @if [ "$(shell echo "$(APISIX_VERSION) $(MAX_APISIX_VERSION)" | tr " " "\n" | sort -rV | head -n 1)" == "$(APISIX_VERSION)" ]; then \ + cp ./utils/check_standalone_config.sh debian/check_standalone_config.sh; \ $(ENV_DOCKER) buildx build --network=host --push \ -t $(IMAGE_NAME):latest \ --platform linux/amd64,linux/arm64 \ -f ./debian/Dockerfile debian; \ + rm -f debian/check_standalone_config.sh; \ fi @$(call func_echo_success_status, "$@ -> [ Done ]") diff --git a/debian-dev/Dockerfile b/debian-dev/Dockerfile index 5cd9c3f5..b72ab025 100644 --- a/debian-dev/Dockerfile +++ b/debian-dev/Dockerfile @@ -64,6 +64,7 @@ ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/ EXPOSE 9080 9443 COPY ./docker-entrypoint.sh /docker-entrypoint.sh +COPY ./utils/check_standalone_config.sh /check_standalone_config.sh ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/debian-dev/Dockerfile.local b/debian-dev/Dockerfile.local index c9209463..caef2f2b 100644 --- a/debian-dev/Dockerfile.local +++ b/debian-dev/Dockerfile.local @@ -66,6 +66,7 @@ RUN ln -sf /dev/stdout /usr/local/apisix/logs/access.log \ EXPOSE 9080 9443 COPY ${ENTRYPOINT_PATH} /docker-entrypoint.sh +COPY ../utils/check_standalone_config.sh /check_standalone_config.sh ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/debian-dev/docker-entrypoint.sh b/debian-dev/docker-entrypoint.sh index 15af65f1..b130a976 100755 --- a/debian-dev/docker-entrypoint.sh +++ b/debian-dev/docker-entrypoint.sh @@ -32,23 +32,7 @@ deployment: _EOC_ else # Check if the deployment role is set to data_plane and config provider is set to yaml for standalone mode - if ! grep -q 'role: data_plane' "${PREFIX}/conf/config.yaml"; then - echo "Error: ${PREFIX}/conf/config.yaml does not contain 'role: data_plane'. Deployment role must be set to 'data_plane' for standalone mode." - echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" - exit 1 - fi - - if ! grep -q 'role_data_plane:' "${PREFIX}/conf/config.yaml"; then - echo "Error: ${PREFIX}/conf/config.yaml does not contain 'role_data_plane:'." - echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" - exit 1 - fi - - if ! grep -q 'config_provider: yaml' "${PREFIX}/conf/config.yaml"; then - echo "Error: ${PREFIX}/conf/config.yaml does not contain 'config_provider: yaml'. Config provider must be set to 'yaml' for standalone mode." - echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" - exit 1 - fi + source /check_standalone_config.sh fi if [ ! -f "${PREFIX}/conf/apisix.yaml" ]; then diff --git a/debian/Dockerfile b/debian/Dockerfile index c380951e..c6fc9d12 100644 --- a/debian/Dockerfile +++ b/debian/Dockerfile @@ -64,6 +64,7 @@ RUN ln -sf /dev/stdout /usr/local/apisix/logs/access.log \ EXPOSE 9080 9443 COPY ./docker-entrypoint.sh /docker-entrypoint.sh +COPY ./check_standalone_config.sh /check_standalone_config.sh ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/debian/docker-entrypoint.sh b/debian/docker-entrypoint.sh index d4757bb6..b3663f08 100755 --- a/debian/docker-entrypoint.sh +++ b/debian/docker-entrypoint.sh @@ -32,23 +32,7 @@ deployment: _EOC_ else # Check if the deployment role is set to data_plane and config provider is set to yaml for standalone mode - if ! grep -q 'role: data_plane' "${PREFIX}/conf/config.yaml"; then - echo "Error: ${PREFIX}/conf/config.yaml does not contain 'role: data_plane'. Deployment role must be set to 'data_plane' for standalone mode." - echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" - exit 1 - fi - - if ! grep -q 'role_data_plane:' "${PREFIX}/conf/config.yaml"; then - echo "Error: ${PREFIX}/conf/config.yaml does not contain 'role_data_plane:'." - echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" - exit 1 - fi - - if ! grep -q 'config_provider: yaml' "${PREFIX}/conf/config.yaml"; then - echo "Error: ${PREFIX}/conf/config.yaml does not contain 'config_provider: yaml'. Config provider must be set to 'yaml' for standalone mode." - echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" - exit 1 - fi + source /check_standalone_config.sh fi if [ ! -f "${PREFIX}/conf/apisix.yaml" ]; then diff --git a/redhat/Dockerfile b/redhat/Dockerfile index ca65c2e1..74170f44 100644 --- a/redhat/Dockerfile +++ b/redhat/Dockerfile @@ -43,6 +43,7 @@ RUN ln -sf /dev/stdout /usr/local/apisix/logs/access.log \ EXPOSE 9080 9443 COPY ./docker-entrypoint.sh /docker-entrypoint.sh +COPY ./check_standalone_config.sh /check_standalone_config.sh ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/redhat/docker-entrypoint.sh b/redhat/docker-entrypoint.sh index acefc881..b3663f08 100755 --- a/redhat/docker-entrypoint.sh +++ b/redhat/docker-entrypoint.sh @@ -32,28 +32,7 @@ deployment: _EOC_ else # Check if the deployment role is set to data_plane and config provider is set to yaml for standalone mode - if ! grep -q 'role: data_plane' "${PREFIX}/conf/config.yaml"; then - echo "Error: ${PREFIX}/conf/config.yaml does not contain 'role: data_plane'. Deployment role must be set to 'data_plane' for standalone mode." - echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" - exit 1 - fi - if ! grep -q 'role: data_plane' "${PREFIX}/conf/config.yaml"; then - echo "Error: ${PREFIX}/conf/config.yaml does not contain 'role: data_plane'. Deployment role must be set to 'data_plane' for standalone mode." - echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" - exit 1 - fi - - if ! grep -q 'role_data_plane:' "${PREFIX}/conf/config.yaml"; then - echo "Error: ${PREFIX}/conf/config.yaml does not contain 'role_data_plane:'." - echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" - exit 1 - fi - - if ! grep -q 'config_provider: yaml' "${PREFIX}/conf/config.yaml"; then - echo "Error: ${PREFIX}/conf/config.yaml does not contain 'config_provider: yaml'. Config provider must be set to 'yaml' for standalone mode." - echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" - exit 1 - fi + source /check_standalone_config.sh fi if [ ! -f "${PREFIX}/conf/apisix.yaml" ]; then diff --git a/utils/check_standalone_config.sh b/utils/check_standalone_config.sh new file mode 100644 index 00000000..385a3664 --- /dev/null +++ b/utils/check_standalone_config.sh @@ -0,0 +1,17 @@ +if ! grep -q 'role: data_plane' "${PREFIX}/conf/config.yaml"; then + echo "Error: ${PREFIX}/conf/config.yaml does not contain 'role: data_plane'. Deployment role must be set to 'data_plane' for standalone mode." + echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" + exit 1 +fi + +if ! grep -q 'role_data_plane:' "${PREFIX}/conf/config.yaml"; then + echo "Error: ${PREFIX}/conf/config.yaml does not contain 'role_data_plane:'." + echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" + exit 1 +fi + +if ! grep -q 'config_provider: yaml' "${PREFIX}/conf/config.yaml"; then + echo "Error: ${PREFIX}/conf/config.yaml does not contain 'config_provider: yaml'. Config provider must be set to 'yaml' for standalone mode." + echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/" + exit 1 +fi