From 5e092c6aae548c138d43492a6c192078b163cdb7 Mon Sep 17 00:00:00 2001 From: juzhiyuan Date: Thu, 5 Nov 2020 18:27:44 +0800 Subject: [PATCH 1/8] feat: added deploy with docker CD --- .github/workflows/deploy-with-docker.yml | 40 ++++++++++++++++++++++++ .github/workflows/test-docker.yml | 21 ------------- 2 files changed, 40 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/deploy-with-docker.yml delete mode 100644 .github/workflows/test-docker.yml diff --git a/.github/workflows/deploy-with-docker.yml b/.github/workflows/deploy-with-docker.yml new file mode 100644 index 0000000000..8b8ffdd0aa --- /dev/null +++ b/.github/workflows/deploy-with-docker.yml @@ -0,0 +1,40 @@ +name: Deploy with Docker + +on: + push: + branches: + - master + - v2.0 + pull_request: + branches: + - master + # NOTE: Just to trigger CD in this PR, will be removed before being merged + - v2.0 + +jobs: + build: + runs-on: ubuntu-latest + + services: + etcd: + image: bitnami/etcd:3.3.13-r80 + ports: + - 2379:2379 + - 2380:2380 + env: + ALLOW_NONE_AUTHENTICATION: yes + + steps: + - uses: actions/checkout@v2 + + - uses: Azure/docker-login@v1 + with: + login-server: apisixacr.azurecr.cn + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Build then Deploy + run: | + docker build -t apisixacr.azurecr.cn/dashboard:${{ github.sha }} . + docker push apisixacr.azurecr.cn/dashboard:${{ github.sha }} + docker run -d -p 80:8080 -v ${pwd}/docs/examples/docker-conf-example.json:/usr/local/apisix-dashboard/conf/conf.json apisixacr.azurecr.cn/dashboard:${{ github.sha }} diff --git a/.github/workflows/test-docker.yml b/.github/workflows/test-docker.yml deleted file mode 100644 index 49bfcd2b25..0000000000 --- a/.github/workflows/test-docker.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Deploy with Docker - -on: - push: - branches: - - master - - v2.0 - pull_request: - branches: - - master - - v2.0 - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Run with Docker - run: | - docker build -t apisix-dashboard:dev . - docker run -d -p 8081:8080 apisix-dashboard:dev From 6eb27bc314f09ec6fd74b205b6359c9e1bedd2dc Mon Sep 17 00:00:00 2001 From: nic-chen Date: Fri, 6 Nov 2020 20:03:19 +0800 Subject: [PATCH 2/8] feat: docker deploy test --- .github/workflows/deploy-with-docker.yml | 31 ++++++++-- api/test/docker-deploy/docker-compose.yaml | 66 ++++++++++++++++++++++ 2 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 api/test/docker-deploy/docker-compose.yaml diff --git a/.github/workflows/deploy-with-docker.yml b/.github/workflows/deploy-with-docker.yml index 8b8ffdd0aa..9b9815f2e3 100644 --- a/.github/workflows/deploy-with-docker.yml +++ b/.github/workflows/deploy-with-docker.yml @@ -1,4 +1,4 @@ -name: Deploy with Docker +name: Test and Deploy with Docker on: push: @@ -33,8 +33,31 @@ jobs: username: ${{ secrets.REGISTRY_USERNAME }} password: ${{ secrets.REGISTRY_PASSWORD }} - - name: Build then Deploy + - name: Build Docker Image run: | - docker build -t apisixacr.azurecr.cn/dashboard:${{ github.sha }} . + docker build -t dashboard:ci . + + - name: Modify ETCD IP + run: | + sed -i 's/127.0.0.1:2379/172.16.238.10:2379/' api/conf/conf.yaml + + - name: Run Docker Compose + working-directory: ./api/test/docker-deploy + run: | + docker-compose up -d + sleep 5 + docker logs docker-deploy_managerapi_1 + + - name: Run Test + run: | + curl http://127.0.0.1:8088/apisix/admin/user/login -X POST -i -d '{"username":"admin", "password": "admin"}' + code=$(curl -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:8088/apisix/admin/user/login -X POST -i -d '{"username":"admin", "password": "admin"}') + if [ ! $code -eq 200 ]; then + echo "failed: failed to custom port" + exit 1 + fi + + - name: Deploy + run: | + docker tag dashboard:ci apisixacr.azurecr.cn/dashboard:${{ github.sha }} docker push apisixacr.azurecr.cn/dashboard:${{ github.sha }} - docker run -d -p 80:8080 -v ${pwd}/docs/examples/docker-conf-example.json:/usr/local/apisix-dashboard/conf/conf.json apisixacr.azurecr.cn/dashboard:${{ github.sha }} diff --git a/api/test/docker-deploy/docker-compose.yaml b/api/test/docker-deploy/docker-compose.yaml new file mode 100644 index 0000000000..5af7197c8b --- /dev/null +++ b/api/test/docker-deploy/docker-compose.yaml @@ -0,0 +1,66 @@ +# +# 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.6" + +services: + etcd: + image: quay.io/coreos/etcd:v3.4.0 + ports: + - "2379:2379" + expose: + - 2379 + - 2380 + networks: + apisix_dashboard_e2e: + ipv4_address: 172.16.238.10 + environment: + - ETCDCTL_API=3 + command: + - /usr/local/bin/etcd + - --data-dir=/etcd-data + - --name + - node1 + - --initial-advertise-peer-urls + - http://172.16.238.10:2380 + - --listen-peer-urls + - http://0.0.0.0:2380 + - --advertise-client-urls + - http://172.16.238.10:2379 + - --listen-client-urls + - http://0.0.0.0:2379 + + managerapi: + image: dashboard:ci + restart: always + volumes: + - ../../conf/conf.yaml:/go/manager-api/conf/conf.yaml:ro + depends_on: + - etcd + ports: + - '8080:8080/tcp' + networks: + apisix_dashboard_e2e: + ipv4_address: 172.16.238.40 + +networks: + apisix_dashboard_e2e: + driver: bridge + ipam: + driver: default + config: + - + subnet: 172.16.238.0/24 From 28c788dc74d192a1e53414109e2a82d5594c17e5 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Fri, 6 Nov 2020 22:36:43 +0800 Subject: [PATCH 3/8] fix: CI --- .github/workflows/deploy-with-docker.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/deploy-with-docker.yml b/.github/workflows/deploy-with-docker.yml index 9b9815f2e3..ab836e2058 100644 --- a/.github/workflows/deploy-with-docker.yml +++ b/.github/workflows/deploy-with-docker.yml @@ -15,15 +15,6 @@ jobs: build: runs-on: ubuntu-latest - services: - etcd: - image: bitnami/etcd:3.3.13-r80 - ports: - - 2379:2379 - - 2380:2380 - env: - ALLOW_NONE_AUTHENTICATION: yes - steps: - uses: actions/checkout@v2 @@ -40,6 +31,7 @@ jobs: - name: Modify ETCD IP run: | sed -i 's/127.0.0.1:2379/172.16.238.10:2379/' api/conf/conf.yaml + sed -i 's/host: 127.0.0.1/host: 0.0.0.0/' api/conf/conf.yaml - name: Run Docker Compose working-directory: ./api/test/docker-deploy From 26991811297fcaec2695ff664dccd769fbe3196a Mon Sep 17 00:00:00 2001 From: nic-chen Date: Sat, 7 Nov 2020 09:08:19 +0800 Subject: [PATCH 4/8] fix: path of `config.yaml` --- api/test/docker-deploy/docker-compose.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/test/docker-deploy/docker-compose.yaml b/api/test/docker-deploy/docker-compose.yaml index 5af7197c8b..a8fba53a46 100644 --- a/api/test/docker-deploy/docker-compose.yaml +++ b/api/test/docker-deploy/docker-compose.yaml @@ -47,7 +47,7 @@ services: image: dashboard:ci restart: always volumes: - - ../../conf/conf.yaml:/go/manager-api/conf/conf.yaml:ro + - ../../conf/conf.yaml:/usr/local/apisix-dashboard/conf/conf.yaml:ro depends_on: - etcd ports: From e1c5671991e332f18b5d9816c5bd7134b9d35892 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Sat, 7 Nov 2020 20:46:25 +0800 Subject: [PATCH 5/8] fix: CI fail --- .github/workflows/deploy-with-docker.yml | 8 +---- api/test/shell/docker_deploy_test.sh | 43 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 7 deletions(-) create mode 100755 api/test/shell/docker_deploy_test.sh diff --git a/.github/workflows/deploy-with-docker.yml b/.github/workflows/deploy-with-docker.yml index ab836e2058..1f75f77985 100644 --- a/.github/workflows/deploy-with-docker.yml +++ b/.github/workflows/deploy-with-docker.yml @@ -41,13 +41,7 @@ jobs: docker logs docker-deploy_managerapi_1 - name: Run Test - run: | - curl http://127.0.0.1:8088/apisix/admin/user/login -X POST -i -d '{"username":"admin", "password": "admin"}' - code=$(curl -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:8088/apisix/admin/user/login -X POST -i -d '{"username":"admin", "password": "admin"}') - if [ ! $code -eq 200 ]; then - echo "failed: failed to custom port" - exit 1 - fi + run: api/test/shell/docker_deploy_test.sh - name: Deploy run: | diff --git a/api/test/shell/docker_deploy_test.sh b/api/test/shell/docker_deploy_test.sh new file mode 100755 index 0000000000..eb39633019 --- /dev/null +++ b/api/test/shell/docker_deploy_test.sh @@ -0,0 +1,43 @@ +#!/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. +# + +set -ex + +# web page +curl http://127.0.0.1:8080 +code=$(curl -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:8080) +if [ ! $code -eq 200 ]; then + echo "failed: failed to custom port" + exit 1 +fi + +# login +resp=$(curl http://127.0.0.1:8080/apisix/admin/user/login -X POST -d '{"username":"admin", "password": "admin"}') +token=$(echo "${resp}" | sed 's/{/\n/g' | sed 's/,/\n/g' | grep "token" | sed 's/:/\n/g' | sed '1d' | sed 's/}//g' | sed 's/"//g') +if [ -z "${token}" ]; then + echo "login failed" +fi + +# plugin orchestration +echo $token +code=$(curl -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:8080/apisix/admin/routes/1 -X PUT -i -H "Authorization: $token" -d '{"id":"1","uri":"/index.html","upstream":{"type":"roundrobin","nodes":[{"host":"www.test.com","port":80,"weight":1}]},"script":{"rule":{"root":"451106f8-560c-43a4-acf2-2a6ed0ea57b8","451106f8-560c-43a4-acf2-2a6ed0ea57b8":[["code==403","b93d622c-92ef-48b4-b6bb-57e1ce893ee3"],["","988ef5c2-c896-4606-a666-3d4cbe24a731"]]},"conf":{"451106f8-560c-43a4-acf2-2a6ed0ea57b8":{"name":"uri-blocker","conf":{"block_rules":["root.exe","root.m+"],"rejected_code":403}},"988ef5c2-c896-4606-a666-3d4cbe24a731":{"name":"kafka-logger","conf":{"batch_max_size":1000,"broker_list":{},"buffer_duration":60,"inactive_timeout":5,"include_req_body":false,"kafka_topic":"1","key":"2","max_retry_count":0,"name":"kafkalogger","retry_delay":1,"timeout":3}},"b93d622c-92ef-48b4-b6bb-57e1ce893ee3":{"name":"fault-injection","conf":{"abort":{"body":"200","http_status":300},"delay":{"duration":500}}}},"chart":{}}}') +if [ ! $code -eq 200 ]; then + echo "failed to create route" + exit 1 +fi From 225c41bee740dd2d6f25a08d93af14ef26bbd0ff Mon Sep 17 00:00:00 2001 From: nic-chen Date: Sun, 8 Nov 2020 01:08:55 +0800 Subject: [PATCH 6/8] docs: update doc for docker deploy --- docs/deploy-with-docker.md | 6 ++++++ docs/deploy-with-docker.zh-CN.md | 8 +++++++- docs/examples/docker-conf-example.yaml | 1 - 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/deploy-with-docker.md b/docs/deploy-with-docker.md index 7f9a268ea5..9b6f245b81 100644 --- a/docs/deploy-with-docker.md +++ b/docs/deploy-with-docker.md @@ -50,3 +50,9 @@ $ docker run -d -p 80:8080 -v /path/to/conf.yaml:/usr/local/apisix-dashboard/con ```sh $ docker build -t apisix-dashboard:{$tag} . --build-arg ENABLE_PROXY=true ``` + +3. If it's not the first time to build, it is recommended not to use cache. + +```sh +$ docker build -t apisix-dashboard:{$tag} . --build-arg ENABLE_PROXY=true --no-cache=true +``` diff --git a/docs/deploy-with-docker.zh-CN.md b/docs/deploy-with-docker.zh-CN.md index 51950c7926..a43d858ce8 100644 --- a/docs/deploy-with-docker.zh-CN.md +++ b/docs/deploy-with-docker.zh-CN.md @@ -34,7 +34,7 @@ $ docker build -t apisix-dashboard:{$tag} . - `conf.listen.host` 为容器内监听 IP,必须为 `0.0.0.0`,这样宿主才能访问容器内网络。 - `conf.listen.port` 为容器内监听端口,默认为 `8080`。如需修改,请同步修改 [Dockerfile](../Dockerfile)。 -- `conf.etcd.endpoints` 为 ETCD 主机列表,多个节点以**英文逗号**连接,请确保容器可以访问到这些主机,例如:示例配置中 `conf.etcd.endpoints` 为 `host.docker.internal` 旨在允许容器访问宿主主机上的网络。 +- `conf.etcd.endpoints` 为 ETCD 主机列表,支持多多个节点,请确保容器可以访问到这些主机,例如:示例配置中 `conf.etcd.endpoints` 为 `host.docker.internal` 旨在允许容器访问宿主主机上的网络。 3. 启动容器 @@ -50,3 +50,9 @@ $ docker run -d -p 80:8080 -v /path/to/conf.yaml:/usr/local/apisix-dashboard/con ```sh $ docker build -t apisix-dashboard:{$tag} . --build-arg ENABLE_PROXY=true ``` + +3. 如果不是第一次构建,建议不要使用缓存。 + +```sh +$ docker build -t apisix-dashboard:{$tag} . --build-arg ENABLE_PROXY=true --no-cache=true +``` diff --git a/docs/examples/docker-conf-example.yaml b/docs/examples/docker-conf-example.yaml index c366f75fd6..88b513cad5 100644 --- a/docs/examples/docker-conf-example.yaml +++ b/docs/examples/docker-conf-example.yaml @@ -23,7 +23,6 @@ conf: listen: host: 0.0.0.0 port: 8080 - dag_lib_path: '' etcd: endpoints: - 127.0.0.1:2379 From 30ee6f5e3efab9afe332463884b0f0412d462125 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Sun, 8 Nov 2020 14:02:57 +0800 Subject: [PATCH 7/8] fix: typo --- docs/deploy-with-docker.zh-CN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/deploy-with-docker.zh-CN.md b/docs/deploy-with-docker.zh-CN.md index a43d858ce8..6a1fef25fa 100644 --- a/docs/deploy-with-docker.zh-CN.md +++ b/docs/deploy-with-docker.zh-CN.md @@ -34,7 +34,7 @@ $ docker build -t apisix-dashboard:{$tag} . - `conf.listen.host` 为容器内监听 IP,必须为 `0.0.0.0`,这样宿主才能访问容器内网络。 - `conf.listen.port` 为容器内监听端口,默认为 `8080`。如需修改,请同步修改 [Dockerfile](../Dockerfile)。 -- `conf.etcd.endpoints` 为 ETCD 主机列表,支持多多个节点,请确保容器可以访问到这些主机,例如:示例配置中 `conf.etcd.endpoints` 为 `host.docker.internal` 旨在允许容器访问宿主主机上的网络。 +- `conf.etcd.endpoints` 为 ETCD 主机列表,支持多个节点,请确保容器可以访问到这些主机,例如:示例配置中 `conf.etcd.endpoints` 为 `host.docker.internal` 旨在允许容器访问宿主主机上的网络。 3. 启动容器 From d41778c2095e7d80ddf1c85f28a062502db35287 Mon Sep 17 00:00:00 2001 From: kv Date: Mon, 9 Nov 2020 18:26:18 +0800 Subject: [PATCH 8/8] fix: add EOF && trigger CD --- .github/workflows/deploy-with-docker.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy-with-docker.yml b/.github/workflows/deploy-with-docker.yml index 1f75f77985..256ebc3ee8 100644 --- a/.github/workflows/deploy-with-docker.yml +++ b/.github/workflows/deploy-with-docker.yml @@ -47,3 +47,4 @@ jobs: run: | docker tag dashboard:ci apisixacr.azurecr.cn/dashboard:${{ github.sha }} docker push apisixacr.azurecr.cn/dashboard:${{ github.sha }} +