Skip to content

Commit

Permalink
fix: avoid config.yaml modification in standalone mode due to read on…
Browse files Browse the repository at this point in the history
…ly file system. (#558)
  • Loading branch information
TheShubhendra authored Dec 11, 2024
1 parent 2a3fcab commit 3ec5547
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 13 deletions.
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -103,40 +107,48 @@ 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 ]")


### push-on-alpine : Push apache/apisix:dev image
.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 ]")


### push-multiarch-on-debian : Push apache/apisix:xx-debian image
.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 ]")


### push-multiarch-on-redhat : Push apache/apisix:xx-redhat image
.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
Expand All @@ -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 ]")

Expand Down
1 change: 1 addition & 0 deletions debian-dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,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"]

Expand Down
1 change: 1 addition & 0 deletions debian-dev/Dockerfile.local
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
7 changes: 2 additions & 5 deletions debian-dev/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions debian/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
6 changes: 2 additions & 4 deletions debian/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions example/apisix_conf/config-standalone.yaml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions example/docker-compose-standalone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions redhat/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
6 changes: 2 additions & 4 deletions redhat/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions utils/check_standalone_config.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3ec5547

Please sign in to comment.