Skip to content

Commit

Permalink
feat: deploy with docker (#701)
Browse files Browse the repository at this point in the history
* feat: added deploy with docker CD

* feat: docker deploy test

* fix: CI

* fix: path of `config.yaml`

* fix: CI fail

* docs: update doc for docker deploy

* fix: typo

* fix: add EOF && trigger  CD

Co-authored-by: nic-chen <johz@163.com>
Co-authored-by: kv <gxthrj@163.com>
  • Loading branch information
3 people authored Nov 10, 2020
1 parent ff33d97 commit 4cde6a3
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 23 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/deploy-with-docker.yml
Original file line number Diff line number Diff line change
@@ -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 }}
21 changes: 0 additions & 21 deletions .github/workflows/test-docker.yml

This file was deleted.

66 changes: 66 additions & 0 deletions api/test/docker-deploy/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions api/test/shell/docker_deploy_test.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions docs/deploy-with-docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
8 changes: 7 additions & 1 deletion docs/deploy-with-docker.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. 启动容器

Expand All @@ -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
```
1 change: 0 additions & 1 deletion docs/examples/docker-conf-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ conf:
listen:
host: 0.0.0.0
port: 8080
dag_lib_path: ''
etcd:
endpoints:
- 127.0.0.1:2379
Expand Down

0 comments on commit 4cde6a3

Please sign in to comment.