Skip to content

Commit f1630d2

Browse files
bzp2010SkyeYoung
andauthored
feat: support devcontainer (#11765)
Co-authored-by: SkyeYoung <[email protected]>
1 parent 9d2d9cf commit f1630d2

File tree

8 files changed

+213
-0
lines changed

8 files changed

+213
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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:24.04
19+
20+
RUN apt update && export DEBIAN_FRONTEND=noninteractive \
21+
&& apt install -y sudo git make gcc tini
22+
23+
COPY Makefile .requirements apisix-master-0.rockspec ./
24+
COPY utils/install-dependencies.sh utils/linux-install-luarocks.sh utils/
25+
26+
RUN make install-runtime
27+
28+
RUN cpanm --notest Test::Nginx IPC::Run > build.log 2>&1 || (cat build.log && exit 1)
29+
30+
ARG ETCD_VER=v3.5.17
31+
ARG BUILDARCH
32+
RUN curl -L https://github.com/etcd-io/etcd/releases/download/${ETCD_VER}/etcd-${ETCD_VER}-linux-${BUILDARCH}.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-${BUILDARCH}.tar.gz \
33+
&& mkdir -p /tmp/etcd-download-test \
34+
&& tar xzvf /tmp/etcd-${ETCD_VER}-linux-${BUILDARCH}.tar.gz -C /tmp/etcd-download-test --strip-components=1 \
35+
&& mv /tmp/etcd-download-test/etcdctl /usr/bin \
36+
&& rm -rf /tmp/*
37+
38+
ENTRYPOINT [ "tini", "--" ]

.devcontainer/devcontainer.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "APISIX",
3+
"dockerComposeFile": ["docker-compose.yml"],
4+
"service": "apisix",
5+
"workspaceFolder": "/workspace",
6+
"privileged": true,
7+
"postCreateCommand": "bash -c 'cd /workspace && rm -rf test-nginx && git config --global --add safe.directory /workspace && git submodule update --init --recursive && git clone https://github.com/openresty/test-nginx.git --depth 1 --single-branch -b master && make deps'",
8+
"customizations": {
9+
"vscode": {
10+
"extensions": ["ms-vscode.makefile-tools", "ms-azuretools.vscode-docker", "sumneko.lua"]
11+
}
12+
},
13+
"forwardPorts": [9080, 9180, 2379]
14+
}

.devcontainer/docker-compose.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
services:
19+
apisix:
20+
build:
21+
context: ..
22+
dockerfile: .devcontainer/Dockerfile
23+
command: sleep infinity
24+
volumes:
25+
- ..:/workspace:cached
26+
network_mode: service:etcd
27+
etcd:
28+
image: bitnami/etcd:3.5
29+
volumes:
30+
- etcd_data:/bitnami/etcd
31+
environment:
32+
ALLOW_NONE_AUTHENTICATION: "yes"
33+
ETCD_ADVERTISE_CLIENT_URLS: "http://127.0.0.1:2379"
34+
ETCD_LISTEN_CLIENT_URLS: "http://0.0.0.0:2379"
35+
36+
volumes:
37+
etcd_data:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ t/lib/dubbo*/**/target/
6464
*.iml
6565
\.*
6666
!.github/
67+
!.devcontainer/
6768
!.gitmodules
6869
!.markdownlint.yml
6970
!.licenserc.yaml
19.5 KB
Loading
5.89 KB
Loading
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
id: build-apisix-dev-environment-devcontainers
3+
title: Build development environment with Dev Containers
4+
description: This paper introduces how to quickly start the APISIX API Gateway development environment using Dev Containers.
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+
Previously, building and developing APISIX on Linux or macOS required developers to install its runtime environment and toolchain themselves, and developers might not be familiar with them.
27+
28+
As it needs to support multiple operating systems and CPU ISAs, the process has inherent complexities in how to find and install dependencies and toolchains.
29+
30+
:::note
31+
32+
The tutorial can be used as an alternative to a [bare-metal environment](building-apisix.md) or a [macOS container development environment](build-apisix-dev-environment-on-mac.md).
33+
34+
It only requires that you have an environment running Docker or a similar alternative (the docker/docker compose command is required), and no other dependent components need to be installed on your host machine.
35+
36+
:::
37+
38+
## Supported systems and CPU ISA
39+
40+
- Linux
41+
- AMD64
42+
- ARM64
43+
- Windows (with WSL2 supported)
44+
- AMD64
45+
- macOS
46+
- ARM64
47+
- AMD64
48+
49+
## Quick Setup of Apache APISIX Development Environment
50+
51+
### Implementation Idea
52+
53+
We use Dev Containers to build development environment, and when we open an APISIX project using the IDE, we have access to the container-driven runtime environment.
54+
55+
There the etcd is ready and we can start APISIX directly.
56+
57+
### Steps
58+
59+
:::note
60+
61+
The following uses Visual Studio Code, which has built-in integration with Dev Containers.
62+
63+
In theory you could also use any other editor or IDE that integrates with Dev Containers.
64+
65+
:::
66+
67+
First, clone the APISIX source code, open project in Visual Studio Code.
68+
69+
```shell
70+
git clone https://github.com/apache/apisix.git
71+
cd apisix
72+
code . # VSCode needs to be in the PATH environment variable, you can also open the project directory manually in the UI.
73+
```
74+
75+
Next, switch to Dev Containers. Open the VSCode Command Palette, and execute `Dev Containers: Reopen in Container`.
76+
77+
![VSCode Command open in container](../../assets/images/build-devcontainers-vscode-command.png)
78+
79+
VSCode will open the Dev Containers project in a new window, where it will build the runtime and install the toolchain according to the Dockerfile before starting the connection and finally installing the APISIX dependencies.
80+
81+
:::note
82+
83+
This process requires a reliable network connection, and it will access Docker Hub, GitHub, and some other sites. You will need to ensure the network connection yourself, otherwise the container build may fail.
84+
85+
:::
86+
87+
Wait some minutes, depending on the internet connection or computer performance, it may take from a few minutes to tens of minutes, you can click on the Progress Bar in the bottom right corner to view a live log where you will be able to check unusual stuck.
88+
89+
If you encounter any problems, you can search or ask questions in [GitHub Issues](https://github.com/apache/apisix/issues) or [GitHub Discussions](https://github.com/apache/apisix/discussions), and community members will respond as promptly as possible.
90+
91+
![VSCode dev containers building progress bar](../../assets/images/build-devcontainers-vscode-progressbar.png)
92+
93+
When the process in the terminal is complete, the development environment is ready, and even etcd is ready.
94+
95+
Start APISIX with the following command:
96+
97+
```shell
98+
make run
99+
```
100+
101+
Now you can start writing code and test cases, and testing tools are available:
102+
103+
```shell
104+
export TEST_NGINX_BINARY=openresty
105+
106+
# run all tests
107+
make test
108+
109+
# or run a specify test case file
110+
FLUSH_ETCD=1 prove -Itest-nginx/lib -I. -r t/admin/api.t
111+
```
112+
113+
## FAQ
114+
115+
### Where's the code? When I delete the container, are the changes lost?
116+
117+
It will be on your host, which is where you cloned the APISIX source code, and the container uses the volume to mount the code into the container. Containers contain only the runtime environment, not the source code, so no changes will be lost whether you close or delete the container.
118+
119+
And, the `git` is already installed in the container, so you can commit a change directly there.

docs/en/latest/config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@
263263
"type": "category",
264264
"label": "Development",
265265
"items": [
266+
{
267+
"type": "doc",
268+
"id": "build-apisix-dev-environment-devcontainers"
269+
},
266270
{
267271
"type": "doc",
268272
"id": "building-apisix"

0 commit comments

Comments
 (0)