This is an automated email from the ASF dual-hosted git repository.

traky pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-docker.git


The following commit(s) were added to refs/heads/master by this push:
     new 328fc9d  fix: allow config.yaml to be updated when already present for 
standalone mode (#494)
328fc9d is described below

commit 328fc9de1591d175af7a622eb474c03603e7ed6a
Author: Ashish Tiwari <[email protected]>
AuthorDate: Mon Sep 11 09:37:30 2023 +0530

    fix: allow config.yaml to be updated when already present for standalone 
mode (#494)
    
    Signed-off-by: Ashish Tiwari <[email protected]>
---
 .../apisix-docker-example-test-standalone.yaml     | 69 ++++++++++++++++++++++
 centos/Dockerfile                                  |  2 +-
 centos/docker-entrypoint.sh                        | 12 ++--
 debian-dev/docker-entrypoint.sh                    | 12 ++--
 debian/Dockerfile                                  |  2 +-
 debian/docker-entrypoint.sh                        | 12 ++--
 .../apisix_conf/apisix-standalone.yaml             | 35 ++---------
 .../docker-compose-standalone.yml                  | 62 ++++++++++---------
 redhat/Dockerfile                                  |  2 +-
 redhat/docker-entrypoint.sh                        | 12 ++--
 10 files changed, 138 insertions(+), 82 deletions(-)

diff --git a/.github/workflows/apisix-docker-example-test-standalone.yaml 
b/.github/workflows/apisix-docker-example-test-standalone.yaml
new file mode 100644
index 0000000..78b0ea7
--- /dev/null
+++ b/.github/workflows/apisix-docker-example-test-standalone.yaml
@@ -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
diff --git a/centos/Dockerfile b/centos/Dockerfile
index 7296686..3d5c616 100644
--- a/centos/Dockerfile
+++ b/centos/Dockerfile
@@ -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
 
diff --git a/centos/docker-entrypoint.sh b/centos/docker-entrypoint.sh
index 085c5e5..d3deef6 100755
--- a/centos/docker-entrypoint.sh
+++ b/centos/docker-entrypoint.sh
@@ -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
diff --git a/debian-dev/docker-entrypoint.sh b/debian-dev/docker-entrypoint.sh
index d58b26a..a451a1c 100755
--- a/debian-dev/docker-entrypoint.sh
+++ b/debian-dev/docker-entrypoint.sh
@@ -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
diff --git a/debian/Dockerfile b/debian/Dockerfile
index 2d99072..67b7c06 100644
--- a/debian/Dockerfile
+++ b/debian/Dockerfile
@@ -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 \
diff --git a/debian/docker-entrypoint.sh b/debian/docker-entrypoint.sh
index 085c5e5..d3deef6 100755
--- a/debian/docker-entrypoint.sh
+++ b/debian/docker-entrypoint.sh
@@ -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
diff --git a/redhat/docker-entrypoint.sh 
b/example/apisix_conf/apisix-standalone.yaml
old mode 100755
new mode 100644
similarity index 53%
copy from redhat/docker-entrypoint.sh
copy to example/apisix_conf/apisix-standalone.yaml
index 085c5e5..b0e4da3
--- a/redhat/docker-entrypoint.sh
+++ b/example/apisix_conf/apisix-standalone.yaml
@@ -1,4 +1,3 @@
-#!/usr/bin/env bash
 #
 # Licensed to the Apache Software Foundation (ASF) under one or more
 # contributor license agreements.  See the NOTICE file distributed with
@@ -16,35 +15,11 @@
 # limitations under the License.
 #
 
-set -eo pipefail
-
-PREFIX=${APISIX_PREFIX:=/usr/local/apisix}
-
-if [[ "$1" == "docker-start" ]]; then
-    if [ "$APISIX_STAND_ALONE" = "true" ]; then
-      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:
   -
+    uri: /get
+    upstream:
+        nodes:
+            "web1:80": 1
+        type: roundrobin
 #END
-_EOC_
-      fi
-        /usr/bin/apisix init
-    else
-        /usr/bin/apisix init
-        /usr/bin/apisix init_etcd
-    fi
-    
-    exec /usr/local/openresty/bin/openresty -p /usr/local/apisix -g 'daemon 
off;'
-fi
-
-exec "$@"
diff --git a/redhat/docker-entrypoint.sh b/example/docker-compose-standalone.yml
old mode 100755
new mode 100644
similarity index 52%
copy from redhat/docker-entrypoint.sh
copy to example/docker-compose-standalone.yml
index 085c5e5..5f9dd59
--- a/redhat/docker-entrypoint.sh
+++ b/example/docker-compose-standalone.yml
@@ -1,4 +1,3 @@
-#!/usr/bin/env bash
 #
 # Licensed to the Apache Software Foundation (ASF) under one or more
 # contributor license agreements.  See the NOTICE file distributed with
@@ -16,35 +15,40 @@
 # limitations under the License.
 #
 
-set -eo pipefail
+version: "3"
 
-PREFIX=${APISIX_PREFIX:=/usr/local/apisix}
+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:
 
-if [[ "$1" == "docker-start" ]]; then
-    if [ "$APISIX_STAND_ALONE" = "true" ]; then
-      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
+  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
 
-      if [ ! -f "${PREFIX}/conf/apisix.yaml" ]; then
-        cat > ${PREFIX}/conf/apisix.yaml << _EOC_
-routes:
-  -
-#END
-_EOC_
-      fi
-        /usr/bin/apisix init
-    else
-        /usr/bin/apisix init
-        /usr/bin/apisix init_etcd
-    fi
-    
-    exec /usr/local/openresty/bin/openresty -p /usr/local/apisix -g 'daemon 
off;'
-fi
 
-exec "$@"
diff --git a/redhat/Dockerfile b/redhat/Dockerfile
index 3ed3f6a..a8b5c79 100644
--- a/redhat/Dockerfile
+++ b/redhat/Dockerfile
@@ -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
 
diff --git a/redhat/docker-entrypoint.sh b/redhat/docker-entrypoint.sh
index 085c5e5..d3deef6 100755
--- a/redhat/docker-entrypoint.sh
+++ b/redhat/docker-entrypoint.sh
@@ -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

Reply via email to