Skip to content
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
63 changes: 63 additions & 0 deletions .github/workflows/docker-standalone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Docker Standalone Test

on:
push:
branches: [master, 'release/**']
paths:
- 'apisix/cli/ops.lua'
- 'docker/debian-dev/**'
- 't/cli/test_standalone_docker.sh'
- 'Makefile'
- '.github/workflows/docker-standalone.yml'
pull_request:
branches: [master, 'release/**']
paths:
- 'apisix/cli/ops.lua'
- 'docker/debian-dev/**'
- 't/cli/test_standalone_docker.sh'
- 'Makefile'
- '.github/workflows/docker-standalone.yml'

concurrency:
group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && github.run_number || github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
docker-test:
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- name: Check out code
uses: actions/checkout@v5

- name: Build APISIX Dashboard
run: |
# install node.js and pnpm
sudo n lts
corepack enable pnpm

# prepare apisix-dashboard source code
source .requirements
git clone --revision=${APISIX_DASHBOARD_COMMIT} --depth 1 https://github.com/apache/apisix-dashboard.git
pushd apisix-dashboard

# compile
pnpm install --frozen-lockfile
pnpm run build
popd

# copy the dist files to the ui directory
mkdir ui
cp -r apisix-dashboard/dist/* ui/
rm -r apisix-dashboard

# build Docker image
make build-on-debian-dev

- name: Run Docker standalone test
run: |
./t/cli/test_standalone_docker.sh
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,6 @@ build-on-debian-dev:
--build-arg CODE_PATH=. \
--build-arg ENTRYPOINT_PATH=./docker/debian-dev/docker-entrypoint.sh \
--build-arg INSTALL_BROTLI=./docker/debian-dev/install-brotli.sh \
--build-arg CHECK_STANDALONE_CONFIG=./docker/utils/check_standalone_config.sh \
-f ./docker/debian-dev/Dockerfile .
@$(call func_echo_success_status, "$@ -> [ Done ]")

Expand Down
22 changes: 22 additions & 0 deletions apisix/cli/ops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,28 @@ local function init(env)
util.die(err, "\n")
end

-- validate standalone mode config
local standalone_env = getenv("APISIX_STAND_ALONE")
if standalone_env == "true" then
local role = yaml_conf.deployment.role
local config_provider

if role == "data_plane" then
config_provider = yaml_conf.deployment.role_data_plane.config_provider
elseif role == "traditional" then
config_provider = yaml_conf.deployment.role_traditional and
yaml_conf.deployment.role_traditional.config_provider
end

if config_provider ~= "yaml" and config_provider ~= "json" then
util.die("APISIX_STAND_ALONE is set to 'true' but config_provider is '"
.. tostring(config_provider) .. "'\n"
.. "For standalone mode, config_provider must be 'yaml' or 'json'\n"
.. "Current role: " .. tostring(role) .. "\n"
.. "See: https://apisix.apache.org/docs/apisix/deployment-modes/\n")
end
end

-- check the Admin API token
local checked_admin_key = false
local allow_admin = yaml_conf.deployment.admin and
Expand Down
2 changes: 2 additions & 0 deletions ci/linux_apisix_current_luarocks_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ script() {
ulimit -n -H

for f in ./t/cli/test_*.sh; do
# skip docker test - runs in separate container
[[ "$f" == "./t/cli/test_standalone_docker.sh" ]] && continue
PATH="$PATH" "$f"
done
}
Expand Down
4 changes: 1 addition & 3 deletions docker/debian-dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ FROM debian:bullseye-slim

ARG ENTRYPOINT_PATH=./docker-entrypoint.sh
ARG INSTALL_BROTLI=./install-brotli.sh
ARG CHECK_STANDALONE_CONFIG=./check_standalone_config.sh

# Install the runtime libyaml package
RUN apt-get -y update --fix-missing \
Expand Down Expand Up @@ -72,8 +71,7 @@ RUN ln -sf /dev/stdout /usr/local/apisix/logs/access.log \
EXPOSE 9080 9443

COPY ${ENTRYPOINT_PATH} /docker-entrypoint.sh
COPY ${CHECK_STANDALONE_CONFIG} /check_standalone_config.sh
RUN chmod +x /docker-entrypoint.sh /check_standalone_config.sh
RUN chmod +x /docker-entrypoint.sh

ENTRYPOINT ["/docker-entrypoint.sh"]

Expand Down
3 changes: 0 additions & 3 deletions docker/debian-dev/docker-entrypoint.sh
Copy link
Contributor

Choose a reason for hiding this comment

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

Image

you have changed the mode of this file, why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

might've changed it when i did local testing, will revert it back

Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ deployment:
role_data_plane:
config_provider: yaml
_EOC_
else
# 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
35 changes: 0 additions & 35 deletions docker/utils/check_standalone_config.sh

This file was deleted.

214 changes: 214 additions & 0 deletions t/cli/test_standalone_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
#!/usr/bin/env bash

#
# 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.
#

. ./t/cli/common.sh

standalone() {
clean_up
docker rm -f apisix-test-standalone 2>/dev/null || true
git checkout conf/apisix.yaml
}

DOCKER_IMAGE="${DOCKER_IMAGE:-apache/apisix:master-debian-dev}"
trap standalone EXIT

echo 'routes: []
#END' > conf/apisix.yaml

run_docker_test() {
local standalone_flag=$1
local config_mode=${2:-ro}

if [ "$standalone_flag" = "true" ]; then
docker run -d --name apisix-test-standalone \
-e APISIX_STAND_ALONE=true \
-v $(pwd)/conf/config.yaml:/usr/local/apisix/conf/config.yaml:${config_mode} \
-v $(pwd)/conf/apisix.yaml:/usr/local/apisix/conf/apisix.yaml:ro \
${DOCKER_IMAGE} > /dev/null 2>&1
else
docker run -d --name apisix-test-standalone \
-v $(pwd)/conf/config.yaml:/usr/local/apisix/conf/config.yaml:${config_mode} \
-v $(pwd)/conf/apisix.yaml:/usr/local/apisix/conf/apisix.yaml:ro \
${DOCKER_IMAGE} > /dev/null 2>&1
fi

sleep 5

if ! docker ps | grep -q apisix-test-standalone; then
echo "Container failed to start. Logs:"
docker logs apisix-test-standalone
docker rm -f apisix-test-standalone > /dev/null 2>&1
return 1
fi

docker rm -f apisix-test-standalone > /dev/null 2>&1
return 0
}

# normal YAML format
echo '
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
apisix:
node_listen: 9080
' > conf/config.yaml

if ! run_docker_test "true"; then
echo "failed: normal YAML format 'role: data_plane' was rejected"
exit 1
fi

echo "passed: normal YAML format accepted"

# double-quoted format
echo '
deployment:
role: "data_plane"
role_data_plane:
config_provider: yaml
apisix:
node_listen: 9080
' > conf/config.yaml

if ! run_docker_test "true"; then
echo "failed: double-quoted 'role: \"data_plane\"' was rejected"
exit 1
fi

echo "passed: double-quoted format accepted"

# single-quoted format
echo "
deployment:
role: 'data_plane'
role_data_plane:
config_provider: yaml
apisix:
node_listen: 9080
" > conf/config.yaml

if ! run_docker_test "true"; then
echo "failed: single quoted \"role: 'data_plane'\" was rejected"
exit 1
fi

echo "passed: single-quoted format accepted"

# flow syntax
echo '
deployment: {"role": "data_plane", "role_data_plane": {"config_provider": "yaml"}}
apisix:
node_listen: 9080
' > conf/config.yaml

if ! run_docker_test "true"; then
echo "failed: flow syntax 'role: {\"data_plane\"}' was rejected"
exit 1
fi

echo "passed: flow syntax format accepted"

# mixed quotes
echo "
deployment:
role: \"data_plane\"
role_data_plane:
config_provider: 'yaml'
apisix:
node_listen: 9080
" > conf/config.yaml

if ! run_docker_test "true"; then
echo "failed: mixed quotes format was rejected"
exit 1
fi

echo "passed: mixed quotes format accepted"

# etcd config_provider should fail in standalone mode
echo '
deployment:
role: data_plane
role_data_plane:
config_provider: etcd
etcd:
host:
- "http://127.0.0.1:2379"
apisix:
node_listen: 9080
' > conf/config.yaml

if run_docker_test "true"; then
echo "failed: 'config_provider: etcd' should be rejected in standalone mode"
exit 1
fi

echo "passed: 'config_provider: etcd' was correctly rejected in standalone mode"

# traditional role with yaml config_provider should work
echo '
deployment:
role: traditional
role_traditional:
config_provider: yaml
admin:
admin_key_required: false
apisix:
node_listen: 9080
enable_admin: true
' > conf/config.yaml

if ! run_docker_test "true" "rw"; then
echo "failed: traditional role with 'config_provider: yaml' was rejected"
exit 1
fi

echo "passed: traditional role with 'config_provider: yaml' accepted"

# check is APISIX_PROFILE is respected in standalone mode
echo '
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
apisix:
node_listen: 9080
' > conf/config-prod.yaml

docker run -d --name apisix-test-standalone \
-e APISIX_STAND_ALONE=true \
-e APISIX_PROFILE=prod \
-v $(pwd)/conf/config-prod.yaml:/usr/local/apisix/conf/config-prod.yaml:ro \
-v $(pwd)/conf/apisix.yaml:/usr/local/apisix/conf/apisix.yaml:ro \
${DOCKER_IMAGE} > /dev/null 2>&1

sleep 5

if ! docker ps | grep -q apisix-test-standalone; then
echo "failed: APISIX_PROFILE=prod in standalone mode was rejected"
docker logs apisix-test-standalone
docker rm -f apisix-test-standalone > /dev/null 2>&1
exit 1
fi

docker rm -f apisix-test-standalone > /dev/null 2>&1

echo "passed: APISIX_PROFILE=prod in standalone mode accepted"
Loading
Loading