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 56b2566f..b130a976 100755 --- a/debian-dev/docker-entrypoint.sh +++ b/debian-dev/docker-entrypoint.sh @@ -31,11 +31,8 @@ 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 + 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 2d8a11e3..b3663f08 100755 --- a/debian/docker-entrypoint.sh +++ b/debian/docker-entrypoint.sh @@ -31,10 +31,8 @@ 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 + source /check_standalone_config.sh fi if [ ! -f "${PREFIX}/conf/apisix.yaml" ]; then 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: 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 2d8a11e3..b3663f08 100755 --- a/redhat/docker-entrypoint.sh +++ b/redhat/docker-entrypoint.sh @@ -31,10 +31,8 @@ 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 + 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