Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid config.yaml modification in standalone mode due to read only file system. #558

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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"]

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part of code is being repeated across entrypoint scripts. Please DRY.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your suggestion. What we can do is extract the logic into a single file and place it in the root directory. Then, we can modify the Makefile to copy this file into the appropriate build context directories (e.g., /debian, /redhat, and /debian-dev) before the Docker build process, and remove it afterward.

Please share your thoughts on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#!/bin/bash

check_config() {
    local key="$1"
    local expected_value="$2"
    local error_message="$3"

    if ! grep -q "${key}: ${expected_value}" "${PREFIX}/conf/config.yaml"; then
        echo "Error: ${PREFIX}/conf/config.yaml does not contain '${key}: ${expected_value}'. ${error_message}"
        echo "Please refer to the APISIX documentation for deployment modes: https://apisix.apache.org/docs/apisix/deployment-modes/"
        exit 1
    fi
}

check_config "role" "data_plane" "Deployment role must be set to 'data_plane' for standalone mode."
check_config "role_data_plane" "" "Role must be set to 'role_data_plane:' for standalone mode."
check_config "config_provider" "yaml" "Config provider must be set to 'yaml' for standalone mode."

This file can be placed into /utils and then sourced into all entrypoint files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

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
Loading