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" + } + ] + } +}