From 92b7b930a15be6a3e1a61ad6de07b85cb0cb4883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=90=9A=E8=87=B4=E8=BF=9C?= Date: Tue, 3 Nov 2020 11:21:37 +0800 Subject: [PATCH] feat: deploy with Docker (#657) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: added Docker * feat: added License header * feat: added line in docs * Update test-docker.yml * feat(doc): update docs * feat: added extra line * feat: added Go Proxy in Dockerfile * feat: update Dockerfile * chore: update docs * fix: copy correct files * feat: improve Dockerfile * Revert "feat: improve Dockerfile" This reverts commit c68a4c4e479147e65efae4611ba162bd2c465928. * fix run fail * feat: update docs * fix: compatible with Golang conf * Squashed commit of the following: commit 94450bf6ad52cdcac8d527c7e7fbf9e8fa1c4ab3 Author: litesun <7sunmiao@gmail.com> Date: Tue Nov 3 10:19:04 2020 +0800 fix: promethus incorrect value when update route (#666) commit de8bdbf6ff867a05dffbd05151b1ba07603f46d2 Author: nic-chen <33000667+nic-chen@users.noreply.github.com> Date: Tue Nov 3 07:50:29 2020 +0800 CI: collect golang unit test code coverage (#654) commit 722c0fdeddbc34723f730e36a4cff004889f7093 Author: litesun <7sunmiao@gmail.com> Date: Tue Nov 3 00:03:06 2020 +0800 feat: added e2e test for Login page (#619) * feat: added Front-end e2e test YAML file * feat: added login e2e test * feat: update Login.e2e.js * Update Login.e2e.js * feat: added e2e readme * feat: added licence * feat: added start-server-and-test package * feat: update login test case * Update frontend-e2e-test.yml * feat: added logout test case * Update frontend-e2e-test.yml * feat: added login failed with empty input * feat: update CI * feat: update text * feat: added public.js * feat: change logout timeout * feat: Added e2e test documentation link to development.md * Update develop.md * Update develop.zh-CN.md * Update README.md Co-authored-by: 琚致远 commit 915ce8300b8138eb986737e6df1201fff63d3b57 Author: nic-chen <33000667+nic-chen@users.noreply.github.com> Date: Mon Nov 2 21:13:34 2020 +0800 test: add e2e test for field hosts in `route` api (#612) * feat: ETCD cluster and APISIX cluster for CI * feat: add test cases * feat: add upstream service in docker compose * fix: comment * test: add test cases * fix: code format * test: add ci * fix ci * fix ci * fix ci * fix: remove consumer test * test: sleep for sync * test: e2e as an independent subproject * fix CI error * test: run docker * fix: remove json schema generate script in docker build * fix: check host and hosts config together * fix ci * test: add test cases for `host` in route * remove useless code * fix: using relative path to read conf (#617) * fix: using relative path * fix path * fix path * fix conf path * fix ci error * fix etcd ip * fix: code format * run backend e2e test ci on v2 branch * fix: code format * fix: code format * fix: CI error * test: remove deploy CI again * remove useless codes * fix: go fmt * test: don't use `go fmt` * fix: code format * fix: var name * fix lint * fix CI error * debug * fix: docker container name * fix CI error * fix CI error * test: add more test cases * fix CI error * chore: remove useless code * fix: go fmt * fix: refactor test code * fix: check body * fix small issue * fix: update docker compose * fix CI * test * test * test: build image first * test: revert subnet ip in docker compose * fix by review * fix: docker compose * test: add test cases * fix: remove useless code * fix: code format * test: code format commit 94d024544df0caff6aef69f6ca9792954a285304 Author: 琚致远 Date: Mon Nov 2 13:17:42 2020 +0800 chore: improve issue template and vscode (#660) * Revert "Squashed commit of the following:" This reverts commit 93d38eef07058f5c65ac1eb83aac9d04ec12d24d. * feat: remove output from ignore files Co-authored-by: nic-chen --- .dockerignore | 1 + .github/workflows/test-docker.yml | 21 +++++++ Dockerfile | 86 ++++++++++++++++++++++++++ README.md | 1 + README.zh-CN.md | 1 + docs/deploy-with-docker.md | 52 ++++++++++++++++ docs/deploy-with-docker.zh-CN.md | 52 ++++++++++++++++ docs/examples/docker-conf-example.json | 31 ++++++++++ 8 files changed, 245 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/test-docker.yml create mode 100644 Dockerfile create mode 100644 docs/deploy-with-docker.md create mode 100644 docs/deploy-with-docker.zh-CN.md create mode 100644 docs/examples/docker-conf-example.json diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..cf7098890e --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +**/node_modules diff --git a/.github/workflows/test-docker.yml b/.github/workflows/test-docker.yml new file mode 100644 index 0000000000..49bfcd2b25 --- /dev/null +++ b/.github/workflows/test-docker.yml @@ -0,0 +1,21 @@ +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/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..30f0249889 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,86 @@ +# +# 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. +# +FROM alpine:latest as pre-build + +ARG APISIX_DASHBOARD_VERSION=v2.0 + +RUN set -x \ + && wget https://github.com/apache/apisix-dashboard/archive/${APISIX_DASHBOARD_VERSION}.tar.gz -O /tmp/apisix-dashboard.tar.gz \ + && mkdir /usr/local/apisix-dashboard \ + && tar -xvf /tmp/apisix-dashboard.tar.gz -C /usr/local/apisix-dashboard --strip 1 + +FROM golang:1.14 as api-builder + +ARG ENABLE_PROXY=false + +WORKDIR /usr/local/apisix-dashboard + +COPY --from=pre-build /usr/local/apisix-dashboard . + +WORKDIR /usr/local/apisix-dashboard/api + +RUN mkdir -p ../output/conf \ + && cp ./conf/*.json ../output/conf + +RUN wget https://github.com/api7/dag-to-lua/archive/v1.1.tar.gz -O /tmp/v1.1.tar.gz \ + && mkdir /tmp/dag-to-lua \ + && tar -xvf /tmp/v1.1.tar.gz -C /tmp/dag-to-lua --strip 1 \ + && mkdir -p ../output/dag-to-lua \ + && mv /tmp/dag-to-lua/lib/* ../output/dag-to-lua/ + +RUN if [ "$ENABLE_PROXY" = "true" ] ; then go env -w GOPROXY=https://goproxy.io,direct ; fi + +RUN go env -w GO111MODULE=on \ + && CGO_ENABLED=0 go build -o ../output/manager-api . + +FROM node:14-alpine as fe-builder + +ARG ENABLE_PROXY=false + +WORKDIR /usr/local/apisix-dashboard + +COPY --from=pre-build /usr/local/apisix-dashboard . + +WORKDIR /usr/local/apisix-dashboard/frontend + +RUN if [ "$ENABLE_PROXY" = "true" ] ; then yarn config set registry https://registry.npm.taobao.org/ ; fi + +RUN yarn install + +RUN yarn build + +FROM alpine:latest as prod + +ARG ENABLE_PROXY=false + +RUN if [ "$ENABLE_PROXY" = "true" ] ; then sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories ; fi + +RUN apk add lua5.1 + +WORKDIR /usr/local/apisix-dashboard + +COPY --from=api-builder /usr/local/apisix-dashboard/output/ ./ + +# NOTE: Just to compatible with /api/conf/conf.go WebDir +RUN mkdir -p ./output +COPY --from=fe-builder /usr/local/apisix-dashboard/output/ ./output + +ENV APISIX_CONF_PATH /usr/local/apisix-dashboard/conf + +EXPOSE 8080 + +CMD [ "/usr/local/apisix-dashboard/manager-api" ] diff --git a/README.md b/README.md index 28afe6b67c..a095d06bff 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ Please refer to [User Guide](./docs/USER_GUIDE.md) ## Deployment - [Deploy Manually](./docs/deploy.md) +- [Deploy with Docker](./docs/deploy-with-docker.md) ## Development diff --git a/README.zh-CN.md b/README.zh-CN.md index bf1dd936ce..67a0cfd507 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -30,6 +30,7 @@ 当前支持如下方式部署: - [手动部署](./docs/deploy.zh-CN.md) +- [使用 Docker 部署](./docs/deploy-with-docker.zh-CN.md) ## 开发 diff --git a/docs/deploy-with-docker.md b/docs/deploy-with-docker.md new file mode 100644 index 0000000000..14e67f73bf --- /dev/null +++ b/docs/deploy-with-docker.md @@ -0,0 +1,52 @@ + + +# Deploy with Docker + +1. Build image + +```sh +# NOTE: $tag should be set manually +$ docker build -t apisix-dashboard:{$tag} . +``` + +2. Prepare the configuration file + +Before starting the container, the configuration file `conf.json` needs to be prepared inside the **host** to override the default configuration file inside the container. Please refer to [example configuration file](./examples/docker-conf-example.json). + +Example configuration notes: + +- `conf.listen.host` To listen for IP within the container, it must be `0.0.0.0`, so the host can access the container's network. +- `conf.listen.port` The default is `8080` for the container listening port. If you need to change it, please change the [Dockerfile](../Dockerfile) too. +- `conf.etcd.endpoints` For the list of ETCD hosts, multiple nodes are connected with **English commas**. Make sure the container has access to these hosts. e.g. Example configuration `conf.etcd.endpoints` for `host.docker.internal` is intended to allow the container to access the network on the host. + +3. Run container + +```sh +$ docker run -d -p 80:8080 -v /path/to/conf.json:/usr/local/apisix-dashboard/conf/conf.json --name apisix-dashboard apisix-dashboard:{$tag} +``` + +## Note + +1. After building the image, if you want to modify the configuration file, you can use the `docker -v /local-path-to-conf-file:/conf/conf.json` parameter to specify the configuration file required for `manager-api` to be loaded dynamically when the container is started. +2. For users in China, we could use the `ENABLE_PROXY` flag to speed up dependencies downloading. + +```sh +$ docker build -t apisix-dashboard:{$tag} . --build-arg ENABLE_PROXY=true +``` diff --git a/docs/deploy-with-docker.zh-CN.md b/docs/deploy-with-docker.zh-CN.md new file mode 100644 index 0000000000..51430cadc2 --- /dev/null +++ b/docs/deploy-with-docker.zh-CN.md @@ -0,0 +1,52 @@ + + +# 使用 Docker 部署 + +1. 构建镜像 + +```sh +# 注意:需手动指定 $tag +$ docker build -t apisix-dashboard:{$tag} . +``` + +2. 准备配置文件 + +在启动容器前,需要在**宿主主机**内准备配置文件 `conf.json`,以便覆盖容器内部默认的配置文件。请参考[示例配置文件](./examples/docker-conf-example.json)。 + +示例配置说明: + +- `conf.listen.host` 为容器内监听 IP,必须为 `0.0.0.0`,这样宿主才能访问容器内网络。 +- `conf.listen.port` 为容器内监听端口,默认为 `8080`。如需修改,请同步修改 [Dockerfile](../Dockerfile)。 +- `conf.etcd.endpoints` 为 ETCD 主机列表,多个节点以**英文逗号**连接,请确保容器可以访问到这些主机,例如:示例配置中 `conf.etcd.endpoints` 为 `host.docker.internal` 旨在允许容器访问宿主主机上的网络。 + +3. 启动容器 + +```sh +$ docker run -d -p 80:8080 -v /path/to/conf.json:/usr/local/apisix-dashboard/conf/conf.json --name apisix-dashboard apisix-dashboard:{$tag} +``` + +## 注意 + +1. 构建镜像后,如需修改配置文件,可通过使用 `docker -v /local-path-to-conf-file:/conf/conf.json` 参数指定 `manager-api` 所需要的配置文件,以便启动容器时动态加载配置文件。 +2. 中国用户可使用 `ENABLE_PROXY` 指令以加速所需依赖的下载。 + +```sh +$ docker build -t apisix-dashboard:{$tag} . --build-arg ENABLE_PROXY=true +``` diff --git a/docs/examples/docker-conf-example.json b/docs/examples/docker-conf-example.json new file mode 100644 index 0000000000..b10b56e259 --- /dev/null +++ b/docs/examples/docker-conf-example.json @@ -0,0 +1,31 @@ +{ + "conf": { + "syslog": { + "host": "127.0.0.1" + }, + "listen": { + "host": "0.0.0.0", + "port": 8080 + }, + "dag-lib-path": "", + "etcd": { + "endpoints": "host.docker.internal:2379" + } + }, + "authentication": { + "session": { + "secret": "secret", + "expireTime": 3600 + }, + "user": [ + { + "username": "admin", + "password": "admin" + }, + { + "username": "user", + "password": "user" + } + ] + } +}