Skip to content

Commit 1031be6

Browse files
authored
Add .github/copilot-instructions.md for AI-assisted development (#183)
1 parent 0ad2a61 commit 1031be6

1 file changed

Lines changed: 95 additions & 0 deletions

File tree

.github/copilot-instructions.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Copilot Instructions for sonic-restapi
2+
3+
## Project Overview
4+
5+
sonic-restapi provides a RESTful API server for SONiC switches, exposing HTTPS endpoints for dynamic network configuration. The server (`go-server-server`) allows external systems to configure switch features like VxLAN tunnels, routes, and ARP entries programmatically.
6+
7+
## Architecture
8+
9+
```
10+
sonic-restapi/
11+
├── go-server-server/ # Go REST API server implementation
12+
├── arp_responder/ # ARP responder module
13+
├── arpthrift/ # ARP Thrift interface
14+
├── arpthrifttest/ # ARP Thrift tests
15+
├── Makefile # Build system
16+
├── Dockerfile # Production Docker image
17+
├── Dockerfile.build # Build environment Docker image
18+
├── Dockerfile.test # Test Docker image
19+
├── Dockerfile.*.prod # Platform-specific production images
20+
├── build.sh # Build script
21+
├── CreateMockPort.sh # Test helper script
22+
├── azurepipeline.yml # CI pipeline
23+
└── README.md
24+
```
25+
26+
### Key Concepts
27+
- **HTTPS REST API**: Exposes configuration endpoints over HTTPS
28+
- **Redis backend**: Reads from and writes to SONiC Redis databases
29+
- **Docker deployment**: Runs as a Docker container on SONiC switches
30+
- **go-server-server**: The main Go binary implementing REST endpoints
31+
32+
## Language & Style
33+
34+
- **Primary languages**: Go (server), Python (tests), Shell (scripts)
35+
- **Go conventions**: Standard Go formatting (`gofmt`), idiomatic error handling
36+
- **Indentation**: Go: tabs (gofmt default), Python: 4 spaces
37+
- **API design**: RESTful conventions — proper HTTP methods, status codes, JSON payloads
38+
- **Naming**: Go exported names in `PascalCase`, unexported in `camelCase`
39+
40+
## Build Instructions
41+
42+
```bash
43+
# Build using Docker
44+
./build.sh
45+
46+
# This generates two Docker images:
47+
# - rest-api-image: Production deployment
48+
# - rest-api-image-test_local: Local testing with embedded Redis
49+
50+
# The production image is also saved as rest-api-image.gz
51+
```
52+
53+
## Testing
54+
55+
```bash
56+
# Run container locally with embedded Redis
57+
docker run -d --rm -p8090:8090 -p6379:6379 \
58+
--name rest-api --cap-add NET_ADMIN --privileged \
59+
-t rest-api-image-test_local:latest
60+
61+
# Run tests
62+
cd test
63+
pytest -v
64+
65+
# Check logs
66+
docker exec -it rest-api bash
67+
cat /tmp/rest-api.err.log
68+
```
69+
70+
### Deploying on a Switch
71+
```bash
72+
# Copy rest-api-image.gz to the switch
73+
docker load < rest-api-image.gz
74+
docker run -d -p=8090:8090/tcp \
75+
-v /var/run/redis/redis.sock:/var/run/redis/redis.sock \
76+
--name rest-api --cap-add NET_ADMIN --privileged \
77+
-t rest-api-image:latest
78+
```
79+
80+
## PR Guidelines
81+
82+
- **Signed-off-by**: Required on all commits
83+
- **CLA**: Sign Linux Foundation EasyCLA
84+
- **Testing**: Include API tests for new endpoints
85+
- **Security**: HTTPS endpoints must maintain proper authentication and authorization
86+
- **CI**: Azure pipeline checks must pass
87+
88+
## Gotchas
89+
90+
- **TLS certificates**: HTTPS requires proper certificate configuration
91+
- **Redis socket**: Production deployment mounts the SONiC Redis Unix socket
92+
- **Network namespace**: Container needs `NET_ADMIN` capability
93+
- **API versioning**: Maintain backward compatibility for existing API consumers
94+
- **Concurrent access**: Handle concurrent Redis operations safely
95+
- **Error responses**: Return proper HTTP status codes and error messages

0 commit comments

Comments
 (0)