Skip to content

Commit abc86a5

Browse files
authored
docs: add docs for building apisix development environment in Docker (#10899)
1 parent d68c243 commit abc86a5

6 files changed

+228
-0
lines changed
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
id: build-apisix-dev-environment-on-mac
3+
title: Build development environment on Mac
4+
description: This paper introduces how to use Docker to quickly build the development environment of API gateway Apache APISIX on Mac.
5+
---
6+
7+
<!--
8+
#
9+
# Licensed to the Apache Software Foundation (ASF) under one or more
10+
# contributor license agreements. See the NOTICE file distributed with
11+
# this work for additional information regarding copyright ownership.
12+
# The ASF licenses this file to You under the Apache License, Version 2.0
13+
# (the "License"); you may not use this file except in compliance with
14+
# the License. You may obtain a copy of the License at
15+
#
16+
# http://www.apache.org/licenses/LICENSE-2.0
17+
#
18+
# Unless required by applicable law or agreed to in writing, software
19+
# distributed under the License is distributed on an "AS IS" BASIS,
20+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21+
# See the License for the specific language governing permissions and
22+
# limitations under the License.
23+
#
24+
-->
25+
26+
If you want to quickly build and develop APISIX on your Mac platform, you can refer to this tutorial.
27+
28+
:::note
29+
30+
This tutorial is suitable for situations where you need to quickly start development on the Mac platform, if you want to go further and have a better development experience, the better choice is the Linux-based virtual machine, or directly use this kind of system as your development environment.
31+
32+
You can see the specific supported systems [here](install-dependencies.md#install).
33+
34+
:::
35+
36+
## Quick Setup of Apache APISIX Development Environment
37+
38+
### Implementation Idea
39+
40+
We use Docker to build the test environment of Apache APISIX. When the container starts, we can mount the source code of Apache APISIX into the container, and then we can build and run test cases in the container.
41+
42+
### Implementation Steps
43+
44+
First, clone the APISIX source code, build an image that can run test cases, and compile the Apache APISIX.
45+
46+
```shell
47+
git clone https://github.com/apache/apisix.git
48+
cd apisix
49+
docker build -t apisix-dev-env -f example/build-dev-image.dockerfile .
50+
```
51+
52+
Next, start Etcd:
53+
54+
```shell
55+
docker run -d --name etcd-apisix --net=host pachyderm/etcd:v3.5.2
56+
```
57+
58+
Mount the APISIX directory and start the development environment container:
59+
60+
```shell
61+
docker run -d --name apisix-dev-env --net=host -v $(pwd):/apisix:rw apisix-dev-env:latest
62+
```
63+
64+
Finally, enter the container, build the Apache APISIX runtime, and configure the test environment:
65+
66+
```shell
67+
docker exec -it apisix-dev-env make deps
68+
docker exec -it apisix-dev-env ln -s /usr/bin/openresty /usr/bin/nginx
69+
```
70+
71+
### Run and Stop APISIX
72+
73+
```shell
74+
docker exec -it apisix-dev-env make run
75+
docker exec -it apisix-dev-env make stop
76+
```
77+
78+
:::note
79+
80+
If you encounter an error message like `nginx: [emerg] bind() to unix:/apisix/logs/worker_events.sock failed (95: Operation not supported)` while running `make run`, please use this solution.
81+
82+
Change the `File Sharing` settings of your Docker-Desktop:
83+
84+
![Docker-Desktop File Sharing Setting](../../assets/images/update-docker-desktop-file-sharing.png)
85+
86+
Changing to either `gRPC FUSE` or `osxfs` can resolve this issue.
87+
88+
:::
89+
90+
### Run Specific Test Cases
91+
92+
```shell
93+
docker exec -it apisix-dev-env prove t/admin/routes.t
94+
```

docs/en/latest/config.json

+4
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@
243243
"type": "doc",
244244
"id": "building-apisix"
245245
},
246+
{
247+
"type": "doc",
248+
"id": "build-apisix-dev-environment-on-mac"
249+
},
246250
{
247251
"type": "doc",
248252
"id": "support-fips-in-apisix"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
id: build-apisix-dev-environment-on-mac
3+
title: 在 Mac 上构建开发环境
4+
description: 本文介绍了如何用 Docker 的方式在 Mac 上快速构建 API 网关 Apache APISIX 的开发环境。
5+
---
6+
7+
<!--
8+
#
9+
# Licensed to the Apache Software Foundation (ASF) under one or more
10+
# contributor license agreements. See the NOTICE file distributed with
11+
# this work for additional information regarding copyright ownership.
12+
# The ASF licenses this file to You under the Apache License, Version 2.0
13+
# (the "License"); you may not use this file except in compliance with
14+
# the License. You may obtain a copy of the License at
15+
#
16+
# http://www.apache.org/licenses/LICENSE-2.0
17+
#
18+
# Unless required by applicable law or agreed to in writing, software
19+
# distributed under the License is distributed on an "AS IS" BASIS,
20+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21+
# See the License for the specific language governing permissions and
22+
# limitations under the License.
23+
#
24+
-->
25+
26+
如果你希望快速的在你的 Mac 平台上构建和开发 APISIX,你可以参考本教程。
27+
28+
:::note
29+
30+
本教程适合需要在 Mac 平台快速开始入门阶段开发的情况,如果你想要更进一步,有更好的开发体验,更好的选择是 Linux-based 虚拟机,或是直接使用这类系统作为你的开发环境。
31+
32+
你可以在[这里](install-dependencies.md#安装)看到具体支持的系统。
33+
34+
:::
35+
36+
## 快速构建 Apache APISIX 开发环境
37+
38+
### 实现思路
39+
40+
我们通过 Docker 来构建 Apache APISIX 的测试环境,在容器启动时将 Apache APISIX 的源代码挂载到容器内,就可以做到在容器内构建以及运行测试用例。
41+
42+
### 实现步骤
43+
44+
首先,我们需要拉取 APISIX 源码,并构建一个可以运行测试用例以及编译运行 Apache APISIX 的镜像:
45+
46+
```shell
47+
git clone https://github.com/apache/apisix.git
48+
cd apisix
49+
docker build -t apisix-dev-env -f example/build-dev-image.dockerfile .
50+
```
51+
52+
然后,我们要启动 Etcd:
53+
54+
```shell
55+
docker run -d --name etcd-apisix --net=host pachyderm/etcd:v3.5.2
56+
```
57+
58+
挂载 APISIX 目录并启动开发环境容器:
59+
60+
```shell
61+
docker run -d --name apisix-dev-env --net=host -v $(pwd):/apisix:rw apisix-dev-env:latest
62+
```
63+
64+
最后,构建 Apache APISIX 运行时并配置测试环境:
65+
66+
```shell
67+
docker exec -it apisix-dev-env make deps
68+
docker exec -it apisix-dev-env ln -s /usr/bin/openresty /usr/bin/nginx
69+
```
70+
71+
### 启动和停止 APISIX
72+
73+
```shell
74+
docker exec -it apisix-dev-env make run
75+
docker exec -it apisix-dev-env make stop
76+
```
77+
78+
:::note
79+
80+
如果你在运行 `make run` 时收到类似 `nginx: [emerg] bind() to unix:/apisix/logs/worker_events.sock failed (95: Operation not supported)` 的错误消息,请使用此解决方案。
81+
82+
更改你的 Docker-Desktop 的 `File Sharing` 设置:
83+
84+
![Docker-Desktop File Sharing 设置](../../assets/images/update-docker-desktop-file-sharing.png)
85+
86+
修改为 `gRPC FUSE``osxfs` 都可以解决此问题。
87+
88+
:::
89+
90+
### 运行指定测试用例
91+
92+
```shell
93+
docker exec -it apisix-dev-env prove t/admin/routes.t
94+
```

docs/zh/latest/config.json

+4
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@
227227
"type": "doc",
228228
"id": "building-apisix"
229229
},
230+
{
231+
"type": "doc",
232+
"id": "build-apisix-dev-environment-on-mac"
233+
},
230234
{
231235
"type": "doc",
232236
"id": "support-fips-in-apisix"

example/build-dev-image.dockerfile

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
FROM ubuntu:20.04
19+
20+
# Install Test::Nginx
21+
RUN apt update
22+
RUN apt install -y cpanminus make
23+
RUN cpanm --notest Test::Nginx
24+
25+
# Install development utils
26+
RUN apt install -y sudo git gawk curl nano vim inetutils-ping
27+
28+
WORKDIR /apisix
29+
30+
ENV PERL5LIB=.:$PERL5LIB
31+
32+
ENTRYPOINT ["tail", "-f", "/dev/null"]

0 commit comments

Comments
 (0)