Skip to content

Commit

Permalink
fix: allow config.yaml to be updated when already present for standal…
Browse files Browse the repository at this point in the history
…one mode (#494) (#497)

Signed-off-by: Ashish Tiwari <[email protected]>
  • Loading branch information
Revolyssup authored Sep 11, 2023
1 parent bc7c398 commit c68d009
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 23 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/apisix-docker-example-test-standalone.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Docker compose CI for example with standalone mode

on:
schedule:
- cron: "0 1 * * *"
push:
branches: [master]
paths-ignore:
- 'docs/**'
- '**/*.md'
pull_request:
branches:
- master
- 'release/apisix-2.15.**'

env:
APISIX_VERSION: "3.5.0"

jobs:
prepare:
runs-on: ubuntu-latest

steps:
- name: Set apisix version
id: apisix
run: |
branch=${{ github.base_ref }}
apisix_version=$( (echo ${branch} | grep -Po '\d*\.\d*\.\d*') || echo ${APISIX_VERSION} )
echo "version=${apisix_version}" >> $GITHUB_OUTPUT
outputs:
apisix-version: ${{ steps.apisix.outputs.version }}

build:
runs-on: ubuntu-latest
needs: prepare
env:
APISIX_VERSION: ${{ needs.prepare.outputs.apisix-version }}

strategy:
fail-fast: false
matrix:
platform:
- centos
- debian
- redhat

steps:
- uses: actions/checkout@v2

- name: Build image
run: |
make build-on-${{ matrix.platform }}
- name: use docker-compose
env:
APISIX_IMAGE_TAG: ${{ format('{0}-{1}', env.APISIX_VERSION, matrix.platform) }}
APISIX_STAND_ALONE: true
run: docker-compose -p docker-apisix -f example/docker-compose-standalone.yml up -d

- name: Test APISIX
run: |
sleep 50 #startup time maybe a little longer as the yq binary is downloaded for use at runtime
result_code=`curl -I -m 10 -o /dev/null -s -w %{http_code} http://127.0.0.1:9080/get`
if [[ $result_code -ne 200 ]];then
printf "result_code: %s\n" "$result_code"
exit 125
fi
2 changes: 1 addition & 1 deletion centos/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ARG APISIX_VERSION=3.5.0
LABEL apisix_version="${APISIX_VERSION}"

RUN yum install -y https://repos.apiseven.com/packages/centos/apache-apisix-repo-1.0-1.noarch.rpm \
&& yum install -y apisix-${APISIX_VERSION} \
&& yum install -y apisix-${APISIX_VERSION} wget \
&& yum clean all \
&& sed -i 's/PASS_MAX_DAYS\t99999/PASS_MAX_DAYS\t60/g' /etc/login.defs

Expand Down
12 changes: 7 additions & 5 deletions centos/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@ PREFIX=${APISIX_PREFIX:=/usr/local/apisix}

if [[ "$1" == "docker-start" ]]; then
if [ "$APISIX_STAND_ALONE" = "true" ]; then
# If the file is not present then initialise the content otherwise update relevant keys for standalone mode
if [ ! -f "${PREFIX}/conf/config.yaml" ]; then
cat > ${PREFIX}/conf/config.yaml << _EOC_
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
_EOC_
fi

if [ ! -f "${PREFIX}/conf/apisix.yaml" ]; then
cat > ${PREFIX}/conf/apisix.yaml << _EOC_
routes:
-
#END
_EOC_
else
wget -qO /usr/local/apisix/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 \
&& chmod a+x /usr/local/apisix/yq
/usr/local/apisix/yq -i '.deployment.role = "data_plane"' ${PREFIX}/conf/config.yaml
/usr/local/apisix/yq -i '.deployment.role_data_plane.config_provider = "yaml"' ${PREFIX}/conf/config.yaml
rm /usr/local/apisix/yq
fi
/usr/bin/apisix init
else
Expand Down
12 changes: 7 additions & 5 deletions debian-dev/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@ PREFIX=${APISIX_PREFIX:=/usr/local/apisix}

if [[ "$1" == "docker-start" ]]; then
if [ "$APISIX_STAND_ALONE" = "true" ]; then
# If the file is not present then initialise the content otherwise update relevant keys for standalone mode
if [ ! -f "${PREFIX}/conf/config.yaml" ]; then
cat > ${PREFIX}/conf/config.yaml << _EOC_
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
_EOC_
fi

if [ ! -f "${PREFIX}/conf/apisix.yaml" ]; then
cat > ${PREFIX}/conf/apisix.yaml << _EOC_
routes:
-
#END
_EOC_
else
wget -qO /usr/local/apisix/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 \
&& chmod a+x /usr/local/apisix/yq
/usr/local/apisix/yq -i '.deployment.role = "data_plane"' ${PREFIX}/conf/config.yaml
/usr/local/apisix/yq -i '.deployment.role_data_plane.config_provider = "yaml"' ${PREFIX}/conf/config.yaml
rm /usr/local/apisix/yq
fi
/usr/bin/apisix init
else
Expand Down
2 changes: 1 addition & 1 deletion debian/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ARG APISIX_VERSION=3.5.0
RUN set -ex; \
arch=$(dpkg --print-architecture); \
apt update; \
apt-get -y install --no-install-recommends wget gnupg ca-certificates curl; \
apt-get -y install --no-install-recommends wget gnupg ca-certificates curl;\
codename=`grep -Po 'VERSION="[0-9]+ \(\K[^)]+' /etc/os-release`; \
wget -O - https://openresty.org/package/pubkey.gpg | apt-key add -; \
case "${arch}" in \
Expand Down
12 changes: 7 additions & 5 deletions debian/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@ PREFIX=${APISIX_PREFIX:=/usr/local/apisix}

if [[ "$1" == "docker-start" ]]; then
if [ "$APISIX_STAND_ALONE" = "true" ]; then
# If the file is not present then initialise the content otherwise update relevant keys for standalone mode
if [ ! -f "${PREFIX}/conf/config.yaml" ]; then
cat > ${PREFIX}/conf/config.yaml << _EOC_
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
_EOC_
fi

if [ ! -f "${PREFIX}/conf/apisix.yaml" ]; then
cat > ${PREFIX}/conf/apisix.yaml << _EOC_
routes:
-
#END
_EOC_
else
wget -qO /usr/local/apisix/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 \
&& chmod a+x /usr/local/apisix/yq
/usr/local/apisix/yq -i '.deployment.role = "data_plane"' ${PREFIX}/conf/config.yaml
/usr/local/apisix/yq -i '.deployment.role_data_plane.config_provider = "yaml"' ${PREFIX}/conf/config.yaml
rm /usr/local/apisix/yq
fi
/usr/bin/apisix init
else
Expand Down
25 changes: 25 additions & 0 deletions example/apisix_conf/apisix-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.
#

routes:
-
uri: /get
upstream:
nodes:
"web1:80": 1
type: roundrobin
#END
54 changes: 54 additions & 0 deletions example/docker-compose-standalone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#
# 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.
#

version: "3"

services:
apisix:
image: apache/apisix:${APISIX_IMAGE_TAG:-3.5.0-debian}
restart: always
volumes:
- ./apisix_conf/apisix-standalone.yaml:/usr/local/apisix/conf/apisix.yaml:ro
environment:
- APISIX_STAND_ALONE=true
ports:
- "9180:9180/tcp"
- "9080:9080/tcp"
- "9091:9091/tcp"
- "9443:9443/tcp"
- "9092:9092/tcp"
networks:
apisix:

web1:
image: nginx:1.19.0-alpine
restart: always
volumes:
- ./upstream/web1.conf:/etc/nginx/nginx.conf
ports:
- "9081:80/tcp"
environment:
- NGINX_PORT=80
networks:
apisix:


networks:
apisix:
driver: bridge


2 changes: 1 addition & 1 deletion redhat/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ COPY ./yum.repos.d/apache-apisix.repo /etc/yum.repos.d/apache-apisix.repo
COPY ./yum.repos.d/openresty.repo /etc/yum.repos.d/openresty.repo

RUN yum update -y \
&& yum install -y apisix-${APISIX_VERSION} \
&& yum install -y apisix-${APISIX_VERSION} wget\
&& yum clean all \
&& sed -i 's/PASS_MAX_DAYS\t99999/PASS_MAX_DAYS\t60/g' /etc/login.defs

Expand Down
12 changes: 7 additions & 5 deletions redhat/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@ PREFIX=${APISIX_PREFIX:=/usr/local/apisix}

if [[ "$1" == "docker-start" ]]; then
if [ "$APISIX_STAND_ALONE" = "true" ]; then
# If the file is not present then initialise the content otherwise update relevant keys for standalone mode
if [ ! -f "${PREFIX}/conf/config.yaml" ]; then
cat > ${PREFIX}/conf/config.yaml << _EOC_
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
_EOC_
fi

if [ ! -f "${PREFIX}/conf/apisix.yaml" ]; then
cat > ${PREFIX}/conf/apisix.yaml << _EOC_
routes:
-
#END
_EOC_
else
wget -qO /usr/local/apisix/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 \
&& chmod a+x /usr/local/apisix/yq
/usr/local/apisix/yq -i '.deployment.role = "data_plane"' ${PREFIX}/conf/config.yaml
/usr/local/apisix/yq -i '.deployment.role_data_plane.config_provider = "yaml"' ${PREFIX}/conf/config.yaml
rm /usr/local/apisix/yq
fi
/usr/bin/apisix init
else
Expand Down

0 comments on commit c68d009

Please sign in to comment.