Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deploy with Docker #657

Merged
merged 18 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/node_modules
**/output
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ignore this directory?output is looks like the build result.
If it is just a test result or other files unnecessary, we can rename it more meaningful.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this folder here is because when building and using the current folder's sources codes, this folder will be copied to the image unexpectedly, we should remove this because we are using codes from release, this issue will neverr occur. Good catch!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just removed this.

21 changes: 21 additions & 0 deletions .github/workflows/test-docker.yml
Original file line number Diff line number Diff line change
@@ -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
77 changes: 77 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#
# 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 \
juzhiyuan marked this conversation as resolved.
Show resolved Hide resolved
&& 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 \
&& go build -o ../output/manager-api .
juzhiyuan marked this conversation as resolved.
Show resolved Hide resolved

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

RUN apk add lua5.1

WORKDIR /usr/local/apisix-dashboard

COPY --from=api-builder /usr/local/apisix-dashboard/output/ ./
COPY --from=fe-builder /usr/local/apisix-dashboard/output/ ./

EXPOSE 8080

CMD [ "/bin/ash", "-c", "manager-api" ]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
当前支持如下方式部署:

- [手动部署](./docs/deploy.zh-CN.md)
- [使用 Docker 部署](./docs/deploy-with-docker.zh-CN.md)

## 开发

Expand Down
42 changes: 42 additions & 0 deletions docs/deploy-with-docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!--
#
# 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.
#
-->

# Deploy with Docker

1. Build image

```sh
# NOTE: $tag should be set manually
$ docker build -t apisix-dashboard:{$tag} .
```

2. Run container

```sh
$ docker run -d -p 80:8080 --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
```
42 changes: 42 additions & 0 deletions docs/deploy-with-docker.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!--
#
# 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.
#
-->

# 使用 Docker 部署

1. 构建镜像

```sh
# 注意:需手动指定 $tag
$ docker build -t apisix-dashboard:{$tag} .
juzhiyuan marked this conversation as resolved.
Show resolved Hide resolved
```

2. 启动容器

```sh
$ docker run -d -p 80:8080 --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
```