diff --git a/.github/workflows/deploy-with-docker.yml b/.github/workflows/deploy-with-docker.yml new file mode 100644 index 0000000000..256ebc3ee8 --- /dev/null +++ b/.github/workflows/deploy-with-docker.yml @@ -0,0 +1,50 @@ +name: Test and 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 + + 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 Docker Image + run: | + 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 + 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 + run: | + docker-compose up -d + sleep 5 + docker logs docker-deploy_managerapi_1 + + - name: Run Test + run: api/test/shell/docker_deploy_test.sh + + - name: Deploy + run: | + docker tag dashboard:ci apisixacr.azurecr.cn/dashboard:${{ github.sha }} + docker push 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 diff --git a/api/test/docker-deploy/docker-compose.yaml b/api/test/docker-deploy/docker-compose.yaml new file mode 100644 index 0000000000..a8fba53a46 --- /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:/usr/local/apisix-dashboard/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 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 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..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. 启动容器 @@ -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