Copilot commented on code in PR #854: URL: https://github.com/apache/dubbo-go-pixiu/pull/854#discussion_r2649444313
########## .github/workflows/pixiu-admin-ci.yml: ########## @@ -0,0 +1,546 @@ +# 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. + +name: Pixiu-Admin CI + +on: + push: + branches: [ main, develop ] + paths: + - 'admin/**' + - 'docker-compose.yml' + - '.github/workflows/pixiu-admin-ci.yml' + pull_request: + branches: [ main, develop ] + paths: + - 'admin/**' + - 'docker-compose.yml' + - '.github/workflows/pixiu-admin-ci.yml' + +jobs: + # Build and test backend + backend-build: + name: Build Admin Backend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download dependencies + run: | + go mod download + go mod verify + + - name: Build admin binary + run: | + go build -v -o pixiu-admin ./cmd/admin/admin.go + + - name: Run Go tests + run: | + go test -v -race -coverprofile=coverage.out -covermode=atomic ./admin/... + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + files: ./coverage.out + flags: admin-backend + name: admin-backend-coverage + + # Build and test frontend + frontend-build: + name: Build Admin Frontend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Cache node modules + uses: actions/cache@v4 + with: + path: | + admin/web/node_modules + ~/.yarn + key: ${{ runner.os }}-yarn-${{ hashFiles('admin/web/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Install dependencies + run: | + cd admin/web + yarn install + + - name: Run linter + run: | + cd admin/web + yarn lint || true + + - name: Run unit tests + run: | + cd admin/web + yarn test:unit || true + + - name: Build frontend + run: | + cd admin/web + yarn build + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: frontend-dist + path: admin/web/dist/ + retention-days: 7 + + # Docker Compose deployment test + docker-compose-test: + name: Docker Compose Deployment Test + runs-on: ubuntu-latest + needs: [backend-build, frontend-build] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Check if docker-compose.yml exists + run: | + if [ ! -f docker-compose.yml ]; then + echo "⚠️ docker-compose.yml not found in root directory" + echo "Skipping docker-compose tests" + exit 0 + fi + + - name: Start services with docker-compose + run: | + # Start etcd and any other services defined in docker-compose + docker-compose up -d + + - name: Wait for etcd to be ready + run: | + echo "Waiting for etcd to be ready..." + timeout 60 bash -c 'until docker ps | grep etcd | grep -q "Up"; do sleep 2; done' + + # Test etcd health + sleep 10 + curl -sf http://localhost:2379/health || exit 1 + + - name: Show running containers + run: | + echo "=== Running Docker Containers ===" + docker ps + + - name: Show docker-compose services + if: always() + run: | + docker-compose ps || true + + - name: Show service logs on failure + if: failure() + run: | + echo "=== Docker Compose Logs ===" + docker-compose logs || true + + - name: Stop services + if: always() + run: | + docker-compose down -v + + # Integration tests with database + integration-tests: + name: Integration Tests + runs-on: ubuntu-latest + needs: [backend-build] + + services: + mysql: + image: mysql:8.0 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: pixiu + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + + etcd: + image: quay.io/coreos/etcd:v3.6.1 + env: + ALLOW_NONE_AUTHENTICATION: yes + ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379 + ETCD_ADVERTISE_CLIENT_URLS: http://localhost:2379 + ports: + - 2379:2379 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Initialize database + run: | + mysql -h 127.0.0.1 -u root -proot pixiu < admin/resources/sql/pixiu_demo.sql + + - name: Create test config + run: | + cat > /tmp/test-config.yaml <<EOF + server: + address: "127.0.0.1:8081" + etcd: + address: "127.0.0.1:2379" + path: "/pixiu/config/api" + mysql: + username: "root" + password: "root" + host: "127.0.0.1" + port: "3306" + dbname: "pixiu" + EOF + + - name: Run integration tests + run: | + go test -v -tags=integration ./admin/... || true + + - name: Test API operations + run: | + # Start admin server in background + go run ./cmd/admin/admin.go -c /tmp/test-config.yaml & + ADMIN_PID=$! + + # Wait for server to start + sleep 10 + + # Test resource creation + cat > /tmp/resource.yaml <<'EOFRESOURCE' + path: '/test' + type: restful + description: test resource + EOFRESOURCE + + curl -X POST http://localhost:8081/config/api/resource \ + -H "Content-Type: multipart/form-data" \ + -F "content=@/tmp/resource.yaml" + + # Test resource list + curl http://localhost:8081/config/api/resource/list + + # Cleanup + kill $ADMIN_PID || true + + # Manual deployment test (following README instructions) + manual-deployment-test: + name: Manual Deployment Test + runs-on: ubuntu-latest + needs: [backend-build] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Start etcd service + run: | + docker run -d -p 2379:2379 \ + --env ALLOW_NONE_AUTHENTICATION=yes \ + --env ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379 \ + --env ETCD_ADVERTISE_CLIENT_URLS=http://localhost:2379 \ + --name etcd \ + quay.io/coreos/etcd:v3.6.1 + + - name: Wait for etcd to be ready + run: | + echo "Waiting for etcd..." + timeout 60 bash -c 'until curl -sf http://localhost:2379/health 2>/dev/null; do sleep 2; done' + echo "✅ Etcd is ready" + + - name: Create test config file + run: | + mkdir -p /tmp/admin-test + cat > /tmp/admin-test/conf.yaml <<'EOF' + server: + address: "127.0.0.1:8081" + etcd: + address: "127.0.0.1:2379" + path: "/pixiu/config/api" + mysql: + username: "root" + password: "root" + host: "127.0.0.1" + port: "3306" + dbname: "pixiu" + zap: + level: "info" + format: "console" + prefix: "[PIXIU-ADMIN]" + director: "/tmp/logs" + linkName: "latest.log" + showLine: true + encodeLevel: "LowercaseColorLevelEncoder" + stacktraceKey: "stacktrace" + logInConsole: true + system: + env: "develop" + addr: 8081 + dbType: "mysql" + EOF + + - name: Build admin binary + run: | + go build -v -o /tmp/admin-test/pixiu-admin ./cmd/admin/admin.go + + - name: Start admin service in background + run: | + cd /tmp/admin-test + mkdir -p /tmp/logs + nohup ./pixiu-admin -c conf.yaml > /tmp/logs/admin.log 2>&1 & + echo $! > /tmp/admin.pid + echo "Admin PID: $(cat /tmp/admin.pid)" + + - name: Wait for admin service to be ready + run: | + echo "Waiting for admin service..." + for i in {1..30}; do + if curl -f http://localhost:8081/config/api/base 2>/dev/null; then + echo "✅ Admin service is ready" + exit 0 + fi + echo "Attempt $i/30 - waiting..." + sleep 2 + done + echo "❌ Admin service failed to start" + cat /tmp/logs/admin.log + exit 1 + + - name: Test admin API endpoints + run: | + echo "Testing base info endpoint..." + curl -f http://localhost:8081/config/api/base + + echo -e "\nTesting resource list endpoint..." + curl -f http://localhost:8081/config/api/resource/list + + echo -e "\nTesting cluster list endpoint..." + curl -f http://localhost:8081/config/api/cluster/list + + echo -e "\nTesting listener list endpoint..." + curl -f http://localhost:8081/config/api/listener/list + + - name: Build frontend + run: | + cd admin/web + yarn install + yarn build + + - name: Verify frontend build output + run: | + ls -la admin/web/dist/ + test -d admin/web/dist/ || exit 1 + + - name: Show logs on failure + if: failure() + run: | + echo "=== Admin Service Logs ===" + cat /tmp/logs/admin.log || echo "No logs found" + + echo -e "\n=== Etcd Status ===" + docker logs etcd || echo "No etcd logs" + + - name: Cleanup + if: always() + run: | + if [ -f /tmp/admin.pid ]; then + kill $(cat /tmp/admin.pid) || true + fi + docker stop etcd || true + docker rm etcd || true + + # Security and code quality checks + code-quality: + name: Code Quality & Security + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: latest + working-directory: . + args: --timeout=5m ./admin/... + + - name: Run gosec security scanner + run: | + go install github.com/securego/gosec/v2/cmd/gosec@latest + gosec -fmt=json -out=gosec-report.json ./admin/... || true + + - name: Upload security report + uses: actions/upload-artifact@v4 + if: always() + with: + name: gosec-report + path: gosec-report.json + + - name: Check for SQL injection vulnerabilities + run: | + grep -r "Query\|Exec" --include="*.go" admin/ | grep -v "Prepare" || true + Review Comment: This grep command for checking SQL injection vulnerabilities will always succeed (exit code 0) because of the `|| true` at the end. This makes the check ineffective as it won't fail the build even if potential SQL injection vulnerabilities are found. Additionally, this is a very basic check that may produce false positives. Consider using the gosec scanner results instead, which has more sophisticated SQL injection detection. ```suggestion # Use gosec report to detect SQL injection issues (rules G20x) if [ ! -f gosec-report.json ]; then echo "gosec-report.json not found. Ensure 'Run gosec security scanner' step completed successfully." exit 1 fi if grep -q '"rule_id":"G20' gosec-report.json; then echo "Potential SQL injection vulnerabilities detected by gosec (rules G20x)." # Show matching entries for easier debugging grep -n '"rule_id":"G20' gosec-report.json || true exit 1 else echo "No SQL injection vulnerabilities (G20x rules) detected by gosec." fi ``` ########## .github/workflows/pixiu-admin-ci.yml: ########## @@ -0,0 +1,546 @@ +# 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. + +name: Pixiu-Admin CI + +on: + push: + branches: [ main, develop ] + paths: + - 'admin/**' + - 'docker-compose.yml' + - '.github/workflows/pixiu-admin-ci.yml' + pull_request: + branches: [ main, develop ] + paths: + - 'admin/**' + - 'docker-compose.yml' + - '.github/workflows/pixiu-admin-ci.yml' + +jobs: + # Build and test backend + backend-build: + name: Build Admin Backend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download dependencies + run: | + go mod download + go mod verify + + - name: Build admin binary + run: | + go build -v -o pixiu-admin ./cmd/admin/admin.go + + - name: Run Go tests + run: | + go test -v -race -coverprofile=coverage.out -covermode=atomic ./admin/... + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + files: ./coverage.out + flags: admin-backend + name: admin-backend-coverage + + # Build and test frontend + frontend-build: + name: Build Admin Frontend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Cache node modules + uses: actions/cache@v4 + with: + path: | + admin/web/node_modules + ~/.yarn + key: ${{ runner.os }}-yarn-${{ hashFiles('admin/web/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Install dependencies + run: | + cd admin/web + yarn install + + - name: Run linter + run: | + cd admin/web + yarn lint || true + + - name: Run unit tests + run: | + cd admin/web + yarn test:unit || true + + - name: Build frontend + run: | + cd admin/web + yarn build + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: frontend-dist + path: admin/web/dist/ + retention-days: 7 + + # Docker Compose deployment test + docker-compose-test: + name: Docker Compose Deployment Test + runs-on: ubuntu-latest + needs: [backend-build, frontend-build] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Check if docker-compose.yml exists + run: | + if [ ! -f docker-compose.yml ]; then + echo "⚠️ docker-compose.yml not found in root directory" + echo "Skipping docker-compose tests" + exit 0 + fi + + - name: Start services with docker-compose + run: | + # Start etcd and any other services defined in docker-compose + docker-compose up -d + + - name: Wait for etcd to be ready + run: | + echo "Waiting for etcd to be ready..." + timeout 60 bash -c 'until docker ps | grep etcd | grep -q "Up"; do sleep 2; done' + + # Test etcd health + sleep 10 + curl -sf http://localhost:2379/health || exit 1 + + - name: Show running containers + run: | + echo "=== Running Docker Containers ===" + docker ps + + - name: Show docker-compose services + if: always() + run: | + docker-compose ps || true + + - name: Show service logs on failure + if: failure() + run: | + echo "=== Docker Compose Logs ===" + docker-compose logs || true + + - name: Stop services + if: always() + run: | + docker-compose down -v + + # Integration tests with database + integration-tests: + name: Integration Tests + runs-on: ubuntu-latest + needs: [backend-build] + + services: + mysql: + image: mysql:8.0 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: pixiu + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + + etcd: + image: quay.io/coreos/etcd:v3.6.1 + env: + ALLOW_NONE_AUTHENTICATION: yes + ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379 + ETCD_ADVERTISE_CLIENT_URLS: http://localhost:2379 + ports: + - 2379:2379 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Initialize database + run: | + mysql -h 127.0.0.1 -u root -proot pixiu < admin/resources/sql/pixiu_demo.sql + + - name: Create test config + run: | + cat > /tmp/test-config.yaml <<EOF + server: + address: "127.0.0.1:8081" + etcd: + address: "127.0.0.1:2379" + path: "/pixiu/config/api" + mysql: + username: "root" + password: "root" + host: "127.0.0.1" + port: "3306" + dbname: "pixiu" + EOF + + - name: Run integration tests + run: | + go test -v -tags=integration ./admin/... || true + + - name: Test API operations + run: | + # Start admin server in background + go run ./cmd/admin/admin.go -c /tmp/test-config.yaml & + ADMIN_PID=$! + + # Wait for server to start + sleep 10 + + # Test resource creation + cat > /tmp/resource.yaml <<'EOFRESOURCE' + path: '/test' + type: restful + description: test resource + EOFRESOURCE + + curl -X POST http://localhost:8081/config/api/resource \ + -H "Content-Type: multipart/form-data" \ + -F "content=@/tmp/resource.yaml" + + # Test resource list + curl http://localhost:8081/config/api/resource/list + + # Cleanup + kill $ADMIN_PID || true + + # Manual deployment test (following README instructions) + manual-deployment-test: + name: Manual Deployment Test + runs-on: ubuntu-latest + needs: [backend-build] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Start etcd service + run: | + docker run -d -p 2379:2379 \ + --env ALLOW_NONE_AUTHENTICATION=yes \ Review Comment: The etcd image uses environment variable `ALLOW_NONE_AUTHENTICATION` which doesn't exist for the CoreOS etcd image. This environment variable is used by the Bitnami etcd image, not the CoreOS one. For the CoreOS etcd image, authentication is not enabled by default. Consider removing this line or switching to the appropriate etcd image if authentication control is needed. ```suggestion ``` ########## .github/workflows/pixiu-admin-ci.yml: ########## @@ -0,0 +1,546 @@ +# 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. + +name: Pixiu-Admin CI + +on: + push: + branches: [ main, develop ] + paths: + - 'admin/**' + - 'docker-compose.yml' + - '.github/workflows/pixiu-admin-ci.yml' + pull_request: + branches: [ main, develop ] + paths: + - 'admin/**' + - 'docker-compose.yml' + - '.github/workflows/pixiu-admin-ci.yml' + +jobs: + # Build and test backend + backend-build: + name: Build Admin Backend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download dependencies + run: | + go mod download + go mod verify + + - name: Build admin binary + run: | + go build -v -o pixiu-admin ./cmd/admin/admin.go + + - name: Run Go tests + run: | + go test -v -race -coverprofile=coverage.out -covermode=atomic ./admin/... + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + files: ./coverage.out + flags: admin-backend + name: admin-backend-coverage + + # Build and test frontend + frontend-build: + name: Build Admin Frontend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Cache node modules + uses: actions/cache@v4 + with: + path: | + admin/web/node_modules + ~/.yarn + key: ${{ runner.os }}-yarn-${{ hashFiles('admin/web/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Install dependencies + run: | + cd admin/web + yarn install + + - name: Run linter + run: | + cd admin/web + yarn lint || true + + - name: Run unit tests + run: | + cd admin/web + yarn test:unit || true + + - name: Build frontend + run: | + cd admin/web + yarn build + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: frontend-dist + path: admin/web/dist/ + retention-days: 7 + + # Docker Compose deployment test + docker-compose-test: + name: Docker Compose Deployment Test + runs-on: ubuntu-latest + needs: [backend-build, frontend-build] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Check if docker-compose.yml exists + run: | + if [ ! -f docker-compose.yml ]; then + echo "⚠️ docker-compose.yml not found in root directory" + echo "Skipping docker-compose tests" + exit 0 + fi + + - name: Start services with docker-compose + run: | + # Start etcd and any other services defined in docker-compose + docker-compose up -d + + - name: Wait for etcd to be ready + run: | + echo "Waiting for etcd to be ready..." + timeout 60 bash -c 'until docker ps | grep etcd | grep -q "Up"; do sleep 2; done' + + # Test etcd health + sleep 10 + curl -sf http://localhost:2379/health || exit 1 + + - name: Show running containers + run: | + echo "=== Running Docker Containers ===" + docker ps + + - name: Show docker-compose services + if: always() + run: | + docker-compose ps || true + + - name: Show service logs on failure + if: failure() + run: | + echo "=== Docker Compose Logs ===" + docker-compose logs || true + + - name: Stop services + if: always() + run: | + docker-compose down -v + + # Integration tests with database + integration-tests: + name: Integration Tests + runs-on: ubuntu-latest + needs: [backend-build] + + services: + mysql: + image: mysql:8.0 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: pixiu + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + + etcd: + image: quay.io/coreos/etcd:v3.6.1 + env: + ALLOW_NONE_AUTHENTICATION: yes + ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379 + ETCD_ADVERTISE_CLIENT_URLS: http://localhost:2379 + ports: + - 2379:2379 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Initialize database + run: | + mysql -h 127.0.0.1 -u root -proot pixiu < admin/resources/sql/pixiu_demo.sql + + - name: Create test config + run: | + cat > /tmp/test-config.yaml <<EOF + server: + address: "127.0.0.1:8081" + etcd: + address: "127.0.0.1:2379" + path: "/pixiu/config/api" + mysql: + username: "root" + password: "root" + host: "127.0.0.1" + port: "3306" + dbname: "pixiu" + EOF + + - name: Run integration tests + run: | + go test -v -tags=integration ./admin/... || true + + - name: Test API operations + run: | + # Start admin server in background + go run ./cmd/admin/admin.go -c /tmp/test-config.yaml & + ADMIN_PID=$! + + # Wait for server to start + sleep 10 + + # Test resource creation + cat > /tmp/resource.yaml <<'EOFRESOURCE' + path: '/test' + type: restful + description: test resource + EOFRESOURCE + + curl -X POST http://localhost:8081/config/api/resource \ + -H "Content-Type: multipart/form-data" \ + -F "content=@/tmp/resource.yaml" + + # Test resource list + curl http://localhost:8081/config/api/resource/list + + # Cleanup + kill $ADMIN_PID || true + + # Manual deployment test (following README instructions) + manual-deployment-test: + name: Manual Deployment Test + runs-on: ubuntu-latest + needs: [backend-build] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Start etcd service + run: | + docker run -d -p 2379:2379 \ + --env ALLOW_NONE_AUTHENTICATION=yes \ + --env ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379 \ + --env ETCD_ADVERTISE_CLIENT_URLS=http://localhost:2379 \ + --name etcd \ + quay.io/coreos/etcd:v3.6.1 + + - name: Wait for etcd to be ready + run: | + echo "Waiting for etcd..." + timeout 60 bash -c 'until curl -sf http://localhost:2379/health 2>/dev/null; do sleep 2; done' + echo "✅ Etcd is ready" + + - name: Create test config file + run: | + mkdir -p /tmp/admin-test + cat > /tmp/admin-test/conf.yaml <<'EOF' + server: + address: "127.0.0.1:8081" + etcd: + address: "127.0.0.1:2379" + path: "/pixiu/config/api" + mysql: + username: "root" + password: "root" + host: "127.0.0.1" + port: "3306" + dbname: "pixiu" + zap: + level: "info" + format: "console" + prefix: "[PIXIU-ADMIN]" + director: "/tmp/logs" + linkName: "latest.log" + showLine: true + encodeLevel: "LowercaseColorLevelEncoder" + stacktraceKey: "stacktrace" + logInConsole: true + system: + env: "develop" + addr: 8081 + dbType: "mysql" + EOF + + - name: Build admin binary + run: | + go build -v -o /tmp/admin-test/pixiu-admin ./cmd/admin/admin.go + + - name: Start admin service in background + run: | + cd /tmp/admin-test + mkdir -p /tmp/logs + nohup ./pixiu-admin -c conf.yaml > /tmp/logs/admin.log 2>&1 & + echo $! > /tmp/admin.pid + echo "Admin PID: $(cat /tmp/admin.pid)" + + - name: Wait for admin service to be ready + run: | + echo "Waiting for admin service..." + for i in {1..30}; do + if curl -f http://localhost:8081/config/api/base 2>/dev/null; then + echo "✅ Admin service is ready" + exit 0 + fi + echo "Attempt $i/30 - waiting..." + sleep 2 + done + echo "❌ Admin service failed to start" + cat /tmp/logs/admin.log + exit 1 + + - name: Test admin API endpoints + run: | + echo "Testing base info endpoint..." + curl -f http://localhost:8081/config/api/base + + echo -e "\nTesting resource list endpoint..." + curl -f http://localhost:8081/config/api/resource/list + + echo -e "\nTesting cluster list endpoint..." + curl -f http://localhost:8081/config/api/cluster/list + + echo -e "\nTesting listener list endpoint..." + curl -f http://localhost:8081/config/api/listener/list + + - name: Build frontend + run: | + cd admin/web + yarn install + yarn build + + - name: Verify frontend build output + run: | + ls -la admin/web/dist/ + test -d admin/web/dist/ || exit 1 + + - name: Show logs on failure + if: failure() + run: | + echo "=== Admin Service Logs ===" + cat /tmp/logs/admin.log || echo "No logs found" + + echo -e "\n=== Etcd Status ===" + docker logs etcd || echo "No etcd logs" + + - name: Cleanup + if: always() + run: | + if [ -f /tmp/admin.pid ]; then + kill $(cat /tmp/admin.pid) || true + fi + docker stop etcd || true + docker rm etcd || true + + # Security and code quality checks + code-quality: + name: Code Quality & Security + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: latest + working-directory: . + args: --timeout=5m ./admin/... + + - name: Run gosec security scanner + run: | + go install github.com/securego/gosec/v2/cmd/gosec@latest + gosec -fmt=json -out=gosec-report.json ./admin/... || true + + - name: Upload security report + uses: actions/upload-artifact@v4 + if: always() + with: + name: gosec-report + path: gosec-report.json + + - name: Check for SQL injection vulnerabilities + run: | + grep -r "Query\|Exec" --include="*.go" admin/ | grep -v "Prepare" || true + + # Performance tests + performance-tests: + name: Performance Tests + runs-on: ubuntu-latest + needs: [manual-deployment-test] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Start etcd + run: | + docker run -d -p 2379:2379 \ + --env ALLOW_NONE_AUTHENTICATION=yes \ Review Comment: The etcd image uses environment variable `ALLOW_NONE_AUTHENTICATION` which doesn't exist for the CoreOS etcd image. This environment variable is specific to the Bitnami etcd image. For the CoreOS etcd image being used here, authentication is not enabled by default. Consider removing this line. ```suggestion ``` ########## .github/workflows/pixiu-admin-ci.yml: ########## @@ -0,0 +1,546 @@ +# 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. + +name: Pixiu-Admin CI + +on: + push: + branches: [ main, develop ] + paths: + - 'admin/**' + - 'docker-compose.yml' + - '.github/workflows/pixiu-admin-ci.yml' + pull_request: + branches: [ main, develop ] + paths: + - 'admin/**' + - 'docker-compose.yml' + - '.github/workflows/pixiu-admin-ci.yml' + +jobs: + # Build and test backend + backend-build: + name: Build Admin Backend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download dependencies + run: | + go mod download + go mod verify + + - name: Build admin binary + run: | + go build -v -o pixiu-admin ./cmd/admin/admin.go + + - name: Run Go tests + run: | + go test -v -race -coverprofile=coverage.out -covermode=atomic ./admin/... + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + files: ./coverage.out + flags: admin-backend + name: admin-backend-coverage + + # Build and test frontend + frontend-build: + name: Build Admin Frontend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Cache node modules + uses: actions/cache@v4 + with: + path: | + admin/web/node_modules + ~/.yarn + key: ${{ runner.os }}-yarn-${{ hashFiles('admin/web/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Install dependencies + run: | + cd admin/web + yarn install + + - name: Run linter + run: | + cd admin/web + yarn lint || true + + - name: Run unit tests + run: | + cd admin/web + yarn test:unit || true + + - name: Build frontend + run: | + cd admin/web + yarn build + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: frontend-dist + path: admin/web/dist/ + retention-days: 7 + + # Docker Compose deployment test + docker-compose-test: + name: Docker Compose Deployment Test + runs-on: ubuntu-latest + needs: [backend-build, frontend-build] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Check if docker-compose.yml exists + run: | + if [ ! -f docker-compose.yml ]; then + echo "⚠️ docker-compose.yml not found in root directory" + echo "Skipping docker-compose tests" + exit 0 + fi + + - name: Start services with docker-compose + run: | + # Start etcd and any other services defined in docker-compose + docker-compose up -d + + - name: Wait for etcd to be ready + run: | + echo "Waiting for etcd to be ready..." + timeout 60 bash -c 'until docker ps | grep etcd | grep -q "Up"; do sleep 2; done' + + # Test etcd health + sleep 10 + curl -sf http://localhost:2379/health || exit 1 + + - name: Show running containers + run: | + echo "=== Running Docker Containers ===" + docker ps + + - name: Show docker-compose services + if: always() + run: | + docker-compose ps || true + + - name: Show service logs on failure + if: failure() + run: | + echo "=== Docker Compose Logs ===" + docker-compose logs || true + + - name: Stop services + if: always() + run: | + docker-compose down -v + + # Integration tests with database + integration-tests: + name: Integration Tests + runs-on: ubuntu-latest + needs: [backend-build] + + services: + mysql: + image: mysql:8.0 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: pixiu + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + + etcd: + image: quay.io/coreos/etcd:v3.6.1 + env: + ALLOW_NONE_AUTHENTICATION: yes + ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379 + ETCD_ADVERTISE_CLIENT_URLS: http://localhost:2379 + ports: + - 2379:2379 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Initialize database + run: | Review Comment: The database initialization step assumes the SQL file exists at `admin/resources/sql/pixiu_demo.sql`, but there's no check to verify the file exists before attempting to import it. If the file doesn't exist or the path is incorrect, this step will fail with an unclear error. Consider adding a check to verify the file exists first, or add better error messaging. ```suggestion run: | if [ ! -f "admin/resources/sql/pixiu_demo.sql" ]; then echo "ERROR: Database initialization file 'admin/resources/sql/pixiu_demo.sql' not found." echo "Please ensure the file exists and the path is correct." echo "Current directory: $(pwd)" echo "Listing admin/resources/sql directory (if present):" ls -la admin/resources/sql || echo "Directory admin/resources/sql does not exist." exit 1 fi ``` ########## .github/workflows/pixiu-admin-ci.yml: ########## @@ -0,0 +1,546 @@ +# 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. + +name: Pixiu-Admin CI + +on: + push: + branches: [ main, develop ] + paths: + - 'admin/**' + - 'docker-compose.yml' + - '.github/workflows/pixiu-admin-ci.yml' + pull_request: + branches: [ main, develop ] + paths: + - 'admin/**' + - 'docker-compose.yml' + - '.github/workflows/pixiu-admin-ci.yml' + +jobs: + # Build and test backend + backend-build: + name: Build Admin Backend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download dependencies + run: | + go mod download + go mod verify + + - name: Build admin binary + run: | + go build -v -o pixiu-admin ./cmd/admin/admin.go + + - name: Run Go tests + run: | + go test -v -race -coverprofile=coverage.out -covermode=atomic ./admin/... + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + files: ./coverage.out + flags: admin-backend + name: admin-backend-coverage + + # Build and test frontend + frontend-build: + name: Build Admin Frontend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Cache node modules + uses: actions/cache@v4 + with: + path: | + admin/web/node_modules + ~/.yarn + key: ${{ runner.os }}-yarn-${{ hashFiles('admin/web/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Install dependencies + run: | + cd admin/web + yarn install + + - name: Run linter + run: | + cd admin/web + yarn lint || true Review Comment: The linter is set to always pass with `|| true`, which means lint failures will be silently ignored. This defeats the purpose of running a linter in CI. Consider removing `|| true` to enforce code quality standards, or at least log the failure while allowing the build to continue. ```suggestion yarn lint ``` ########## .github/workflows/pixiu-admin-ci.yml: ########## @@ -0,0 +1,546 @@ +# 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. + +name: Pixiu-Admin CI + +on: + push: + branches: [ main, develop ] + paths: + - 'admin/**' + - 'docker-compose.yml' + - '.github/workflows/pixiu-admin-ci.yml' + pull_request: + branches: [ main, develop ] + paths: + - 'admin/**' + - 'docker-compose.yml' + - '.github/workflows/pixiu-admin-ci.yml' + +jobs: + # Build and test backend + backend-build: + name: Build Admin Backend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download dependencies + run: | + go mod download + go mod verify + + - name: Build admin binary + run: | + go build -v -o pixiu-admin ./cmd/admin/admin.go + + - name: Run Go tests + run: | + go test -v -race -coverprofile=coverage.out -covermode=atomic ./admin/... + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + files: ./coverage.out + flags: admin-backend + name: admin-backend-coverage + + # Build and test frontend + frontend-build: + name: Build Admin Frontend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Cache node modules + uses: actions/cache@v4 + with: + path: | + admin/web/node_modules + ~/.yarn + key: ${{ runner.os }}-yarn-${{ hashFiles('admin/web/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Install dependencies + run: | + cd admin/web + yarn install + + - name: Run linter + run: | + cd admin/web + yarn lint || true + + - name: Run unit tests + run: | + cd admin/web + yarn test:unit || true Review Comment: The unit tests are set to always pass with `|| true`, which means test failures will be silently ignored. This undermines the value of running tests in CI. Consider removing `|| true` to ensure test failures cause the build to fail, or at minimum add a step to report test failures explicitly. ```suggestion yarn test:unit ``` ########## .github/workflows/pixiu-admin-ci.yml: ########## @@ -0,0 +1,546 @@ +# 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. + +name: Pixiu-Admin CI + +on: + push: + branches: [ main, develop ] + paths: + - 'admin/**' + - 'docker-compose.yml' + - '.github/workflows/pixiu-admin-ci.yml' + pull_request: + branches: [ main, develop ] + paths: + - 'admin/**' + - 'docker-compose.yml' + - '.github/workflows/pixiu-admin-ci.yml' + +jobs: + # Build and test backend + backend-build: + name: Build Admin Backend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download dependencies + run: | + go mod download + go mod verify + + - name: Build admin binary + run: | + go build -v -o pixiu-admin ./cmd/admin/admin.go + + - name: Run Go tests + run: | + go test -v -race -coverprofile=coverage.out -covermode=atomic ./admin/... + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + files: ./coverage.out + flags: admin-backend + name: admin-backend-coverage + + # Build and test frontend + frontend-build: + name: Build Admin Frontend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Cache node modules + uses: actions/cache@v4 + with: + path: | + admin/web/node_modules + ~/.yarn + key: ${{ runner.os }}-yarn-${{ hashFiles('admin/web/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Install dependencies + run: | + cd admin/web + yarn install + + - name: Run linter + run: | + cd admin/web + yarn lint || true + + - name: Run unit tests + run: | + cd admin/web + yarn test:unit || true + + - name: Build frontend + run: | + cd admin/web + yarn build + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: frontend-dist + path: admin/web/dist/ + retention-days: 7 + + # Docker Compose deployment test + docker-compose-test: + name: Docker Compose Deployment Test + runs-on: ubuntu-latest + needs: [backend-build, frontend-build] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Check if docker-compose.yml exists + run: | + if [ ! -f docker-compose.yml ]; then + echo "⚠️ docker-compose.yml not found in root directory" + echo "Skipping docker-compose tests" + exit 0 + fi + + - name: Start services with docker-compose + run: | + # Start etcd and any other services defined in docker-compose + docker-compose up -d + + - name: Wait for etcd to be ready + run: | + echo "Waiting for etcd to be ready..." + timeout 60 bash -c 'until docker ps | grep etcd | grep -q "Up"; do sleep 2; done' + + # Test etcd health + sleep 10 + curl -sf http://localhost:2379/health || exit 1 + + - name: Show running containers + run: | + echo "=== Running Docker Containers ===" + docker ps + + - name: Show docker-compose services + if: always() + run: | + docker-compose ps || true + + - name: Show service logs on failure + if: failure() + run: | + echo "=== Docker Compose Logs ===" + docker-compose logs || true + + - name: Stop services + if: always() + run: | + docker-compose down -v + + # Integration tests with database + integration-tests: + name: Integration Tests + runs-on: ubuntu-latest + needs: [backend-build] + + services: + mysql: + image: mysql:8.0 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: pixiu + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + + etcd: + image: quay.io/coreos/etcd:v3.6.1 + env: + ALLOW_NONE_AUTHENTICATION: yes + ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379 + ETCD_ADVERTISE_CLIENT_URLS: http://localhost:2379 + ports: + - 2379:2379 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Initialize database + run: | + mysql -h 127.0.0.1 -u root -proot pixiu < admin/resources/sql/pixiu_demo.sql + + - name: Create test config + run: | + cat > /tmp/test-config.yaml <<EOF + server: + address: "127.0.0.1:8081" + etcd: + address: "127.0.0.1:2379" + path: "/pixiu/config/api" + mysql: + username: "root" + password: "root" + host: "127.0.0.1" + port: "3306" + dbname: "pixiu" + EOF + + - name: Run integration tests + run: | + go test -v -tags=integration ./admin/... || true + + - name: Test API operations + run: | + # Start admin server in background + go run ./cmd/admin/admin.go -c /tmp/test-config.yaml & + ADMIN_PID=$! + + # Wait for server to start + sleep 10 + + # Test resource creation + cat > /tmp/resource.yaml <<'EOFRESOURCE' + path: '/test' + type: restful + description: test resource + EOFRESOURCE + + curl -X POST http://localhost:8081/config/api/resource \ + -H "Content-Type: multipart/form-data" \ + -F "content=@/tmp/resource.yaml" + + # Test resource list + curl http://localhost:8081/config/api/resource/list + + # Cleanup + kill $ADMIN_PID || true Review Comment: The API endpoint test is missing error handling. If the curl command fails, the build will exit with code 1 (from the last failed curl command), but there's no cleanup of the admin service that was started. Consider adding proper error handling and cleanup, or use a trap to ensure the admin service is killed on script exit. ########## .github/workflows/pixiu-admin-ci.yml: ########## @@ -0,0 +1,546 @@ +# 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. + +name: Pixiu-Admin CI + +on: + push: + branches: [ main, develop ] + paths: + - 'admin/**' + - 'docker-compose.yml' + - '.github/workflows/pixiu-admin-ci.yml' + pull_request: + branches: [ main, develop ] + paths: + - 'admin/**' + - 'docker-compose.yml' + - '.github/workflows/pixiu-admin-ci.yml' + +jobs: + # Build and test backend + backend-build: + name: Build Admin Backend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download dependencies + run: | + go mod download + go mod verify + + - name: Build admin binary + run: | + go build -v -o pixiu-admin ./cmd/admin/admin.go + + - name: Run Go tests + run: | + go test -v -race -coverprofile=coverage.out -covermode=atomic ./admin/... + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + files: ./coverage.out + flags: admin-backend + name: admin-backend-coverage + + # Build and test frontend + frontend-build: + name: Build Admin Frontend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Cache node modules + uses: actions/cache@v4 + with: + path: | + admin/web/node_modules + ~/.yarn + key: ${{ runner.os }}-yarn-${{ hashFiles('admin/web/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Install dependencies + run: | + cd admin/web + yarn install + + - name: Run linter + run: | + cd admin/web + yarn lint || true + + - name: Run unit tests + run: | + cd admin/web + yarn test:unit || true + + - name: Build frontend + run: | + cd admin/web + yarn build + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: frontend-dist + path: admin/web/dist/ + retention-days: 7 + + # Docker Compose deployment test + docker-compose-test: + name: Docker Compose Deployment Test + runs-on: ubuntu-latest + needs: [backend-build, frontend-build] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Check if docker-compose.yml exists + run: | + if [ ! -f docker-compose.yml ]; then + echo "⚠️ docker-compose.yml not found in root directory" + echo "Skipping docker-compose tests" + exit 0 + fi + + - name: Start services with docker-compose + run: | + # Start etcd and any other services defined in docker-compose + docker-compose up -d + + - name: Wait for etcd to be ready + run: | + echo "Waiting for etcd to be ready..." + timeout 60 bash -c 'until docker ps | grep etcd | grep -q "Up"; do sleep 2; done' + + # Test etcd health + sleep 10 + curl -sf http://localhost:2379/health || exit 1 + + - name: Show running containers + run: | + echo "=== Running Docker Containers ===" + docker ps + + - name: Show docker-compose services + if: always() + run: | + docker-compose ps || true + + - name: Show service logs on failure + if: failure() + run: | + echo "=== Docker Compose Logs ===" + docker-compose logs || true + + - name: Stop services + if: always() + run: | + docker-compose down -v + + # Integration tests with database + integration-tests: + name: Integration Tests + runs-on: ubuntu-latest + needs: [backend-build] + + services: + mysql: + image: mysql:8.0 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: pixiu + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + + etcd: + image: quay.io/coreos/etcd:v3.6.1 + env: + ALLOW_NONE_AUTHENTICATION: yes + ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379 + ETCD_ADVERTISE_CLIENT_URLS: http://localhost:2379 + ports: + - 2379:2379 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Initialize database + run: | + mysql -h 127.0.0.1 -u root -proot pixiu < admin/resources/sql/pixiu_demo.sql + + - name: Create test config + run: | + cat > /tmp/test-config.yaml <<EOF + server: + address: "127.0.0.1:8081" + etcd: + address: "127.0.0.1:2379" + path: "/pixiu/config/api" + mysql: + username: "root" + password: "root" + host: "127.0.0.1" + port: "3306" + dbname: "pixiu" + EOF + + - name: Run integration tests + run: | + go test -v -tags=integration ./admin/... || true Review Comment: Integration tests are set to always pass with `|| true`, which means test failures will be silently ignored. This defeats the purpose of running integration tests in CI. Remove `|| true` to ensure integration test failures are properly reported and cause the build to fail. ```suggestion go test -v -tags=integration ./admin/... ``` ########## .github/workflows/pixiu-admin-ci.yml: ########## @@ -0,0 +1,546 @@ +# 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. + +name: Pixiu-Admin CI + +on: + push: + branches: [ main, develop ] + paths: + - 'admin/**' + - 'docker-compose.yml' + - '.github/workflows/pixiu-admin-ci.yml' + pull_request: + branches: [ main, develop ] + paths: + - 'admin/**' + - 'docker-compose.yml' + - '.github/workflows/pixiu-admin-ci.yml' + +jobs: + # Build and test backend + backend-build: + name: Build Admin Backend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download dependencies + run: | + go mod download + go mod verify + + - name: Build admin binary + run: | + go build -v -o pixiu-admin ./cmd/admin/admin.go + + - name: Run Go tests + run: | + go test -v -race -coverprofile=coverage.out -covermode=atomic ./admin/... + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + files: ./coverage.out + flags: admin-backend + name: admin-backend-coverage + + # Build and test frontend + frontend-build: + name: Build Admin Frontend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Cache node modules + uses: actions/cache@v4 + with: + path: | + admin/web/node_modules + ~/.yarn + key: ${{ runner.os }}-yarn-${{ hashFiles('admin/web/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Install dependencies + run: | + cd admin/web + yarn install + + - name: Run linter + run: | + cd admin/web + yarn lint || true + + - name: Run unit tests + run: | + cd admin/web + yarn test:unit || true + + - name: Build frontend + run: | + cd admin/web + yarn build + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: frontend-dist + path: admin/web/dist/ + retention-days: 7 + + # Docker Compose deployment test + docker-compose-test: + name: Docker Compose Deployment Test + runs-on: ubuntu-latest + needs: [backend-build, frontend-build] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Check if docker-compose.yml exists + run: | + if [ ! -f docker-compose.yml ]; then + echo "⚠️ docker-compose.yml not found in root directory" + echo "Skipping docker-compose tests" + exit 0 + fi + + - name: Start services with docker-compose + run: | + # Start etcd and any other services defined in docker-compose + docker-compose up -d + + - name: Wait for etcd to be ready + run: | + echo "Waiting for etcd to be ready..." + timeout 60 bash -c 'until docker ps | grep etcd | grep -q "Up"; do sleep 2; done' + + # Test etcd health + sleep 10 + curl -sf http://localhost:2379/health || exit 1 + + - name: Show running containers + run: | + echo "=== Running Docker Containers ===" + docker ps + + - name: Show docker-compose services + if: always() + run: | + docker-compose ps || true + + - name: Show service logs on failure + if: failure() + run: | + echo "=== Docker Compose Logs ===" + docker-compose logs || true + + - name: Stop services + if: always() + run: | + docker-compose down -v + + # Integration tests with database + integration-tests: + name: Integration Tests + runs-on: ubuntu-latest + needs: [backend-build] + + services: + mysql: + image: mysql:8.0 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: pixiu + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + + etcd: + image: quay.io/coreos/etcd:v3.6.1 + env: + ALLOW_NONE_AUTHENTICATION: yes + ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379 + ETCD_ADVERTISE_CLIENT_URLS: http://localhost:2379 + ports: + - 2379:2379 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Initialize database + run: | + mysql -h 127.0.0.1 -u root -proot pixiu < admin/resources/sql/pixiu_demo.sql + + - name: Create test config + run: | + cat > /tmp/test-config.yaml <<EOF + server: + address: "127.0.0.1:8081" + etcd: + address: "127.0.0.1:2379" + path: "/pixiu/config/api" + mysql: + username: "root" + password: "root" + host: "127.0.0.1" + port: "3306" + dbname: "pixiu" + EOF + + - name: Run integration tests + run: | + go test -v -tags=integration ./admin/... || true + + - name: Test API operations + run: | + # Start admin server in background + go run ./cmd/admin/admin.go -c /tmp/test-config.yaml & + ADMIN_PID=$! + + # Wait for server to start + sleep 10 + + # Test resource creation + cat > /tmp/resource.yaml <<'EOFRESOURCE' + path: '/test' + type: restful + description: test resource + EOFRESOURCE + + curl -X POST http://localhost:8081/config/api/resource \ + -H "Content-Type: multipart/form-data" \ + -F "content=@/tmp/resource.yaml" + + # Test resource list + curl http://localhost:8081/config/api/resource/list + + # Cleanup + kill $ADMIN_PID || true + + # Manual deployment test (following README instructions) + manual-deployment-test: + name: Manual Deployment Test + runs-on: ubuntu-latest + needs: [backend-build] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Start etcd service + run: | + docker run -d -p 2379:2379 \ + --env ALLOW_NONE_AUTHENTICATION=yes \ + --env ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379 \ + --env ETCD_ADVERTISE_CLIENT_URLS=http://localhost:2379 \ + --name etcd \ + quay.io/coreos/etcd:v3.6.1 + + - name: Wait for etcd to be ready + run: | + echo "Waiting for etcd..." + timeout 60 bash -c 'until curl -sf http://localhost:2379/health 2>/dev/null; do sleep 2; done' + echo "✅ Etcd is ready" + + - name: Create test config file + run: | + mkdir -p /tmp/admin-test + cat > /tmp/admin-test/conf.yaml <<'EOF' + server: + address: "127.0.0.1:8081" + etcd: + address: "127.0.0.1:2379" + path: "/pixiu/config/api" + mysql: + username: "root" + password: "root" + host: "127.0.0.1" + port: "3306" + dbname: "pixiu" + zap: + level: "info" + format: "console" + prefix: "[PIXIU-ADMIN]" + director: "/tmp/logs" + linkName: "latest.log" + showLine: true + encodeLevel: "LowercaseColorLevelEncoder" + stacktraceKey: "stacktrace" + logInConsole: true + system: + env: "develop" + addr: 8081 + dbType: "mysql" + EOF + + - name: Build admin binary + run: | + go build -v -o /tmp/admin-test/pixiu-admin ./cmd/admin/admin.go + + - name: Start admin service in background + run: | + cd /tmp/admin-test + mkdir -p /tmp/logs + nohup ./pixiu-admin -c conf.yaml > /tmp/logs/admin.log 2>&1 & + echo $! > /tmp/admin.pid + echo "Admin PID: $(cat /tmp/admin.pid)" + + - name: Wait for admin service to be ready + run: | + echo "Waiting for admin service..." + for i in {1..30}; do + if curl -f http://localhost:8081/config/api/base 2>/dev/null; then + echo "✅ Admin service is ready" + exit 0 + fi + echo "Attempt $i/30 - waiting..." + sleep 2 + done + echo "❌ Admin service failed to start" + cat /tmp/logs/admin.log + exit 1 + + - name: Test admin API endpoints + run: | + echo "Testing base info endpoint..." + curl -f http://localhost:8081/config/api/base + + echo -e "\nTesting resource list endpoint..." + curl -f http://localhost:8081/config/api/resource/list + + echo -e "\nTesting cluster list endpoint..." + curl -f http://localhost:8081/config/api/cluster/list + + echo -e "\nTesting listener list endpoint..." + curl -f http://localhost:8081/config/api/listener/list + + - name: Build frontend + run: | + cd admin/web + yarn install + yarn build + + - name: Verify frontend build output + run: | + ls -la admin/web/dist/ + test -d admin/web/dist/ || exit 1 + + - name: Show logs on failure + if: failure() + run: | + echo "=== Admin Service Logs ===" + cat /tmp/logs/admin.log || echo "No logs found" + + echo -e "\n=== Etcd Status ===" + docker logs etcd || echo "No etcd logs" + + - name: Cleanup + if: always() + run: | + if [ -f /tmp/admin.pid ]; then + kill $(cat /tmp/admin.pid) || true + fi + docker stop etcd || true + docker rm etcd || true + + # Security and code quality checks + code-quality: + name: Code Quality & Security + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: latest + working-directory: . + args: --timeout=5m ./admin/... + + - name: Run gosec security scanner + run: | + go install github.com/securego/gosec/v2/cmd/gosec@latest + gosec -fmt=json -out=gosec-report.json ./admin/... || true Review Comment: The `gosec` security scanner is set to always pass with `|| true`, which means security vulnerabilities found will not fail the build. While this might be intentional to avoid blocking on initial setup, it significantly reduces the value of security scanning. Consider removing `|| true` to enforce security standards, or at minimum add a step to review and report the findings. ```suggestion gosec -fmt=json -out=gosec-report.json ./admin/... ``` ########## .github/workflows/pixiu-admin-ci.yml: ########## @@ -0,0 +1,546 @@ +# 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. + +name: Pixiu-Admin CI + +on: + push: + branches: [ main, develop ] + paths: + - 'admin/**' + - 'docker-compose.yml' + - '.github/workflows/pixiu-admin-ci.yml' + pull_request: + branches: [ main, develop ] + paths: + - 'admin/**' + - 'docker-compose.yml' + - '.github/workflows/pixiu-admin-ci.yml' + +jobs: + # Build and test backend + backend-build: + name: Build Admin Backend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download dependencies + run: | + go mod download + go mod verify + + - name: Build admin binary + run: | + go build -v -o pixiu-admin ./cmd/admin/admin.go + + - name: Run Go tests + run: | + go test -v -race -coverprofile=coverage.out -covermode=atomic ./admin/... + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + files: ./coverage.out + flags: admin-backend + name: admin-backend-coverage + + # Build and test frontend + frontend-build: + name: Build Admin Frontend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Cache node modules + uses: actions/cache@v4 + with: + path: | + admin/web/node_modules + ~/.yarn + key: ${{ runner.os }}-yarn-${{ hashFiles('admin/web/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Install dependencies + run: | + cd admin/web + yarn install + + - name: Run linter + run: | + cd admin/web + yarn lint || true + + - name: Run unit tests + run: | + cd admin/web + yarn test:unit || true + + - name: Build frontend + run: | + cd admin/web + yarn build + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: frontend-dist + path: admin/web/dist/ + retention-days: 7 + + # Docker Compose deployment test + docker-compose-test: + name: Docker Compose Deployment Test + runs-on: ubuntu-latest + needs: [backend-build, frontend-build] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Check if docker-compose.yml exists + run: | + if [ ! -f docker-compose.yml ]; then + echo "⚠️ docker-compose.yml not found in root directory" + echo "Skipping docker-compose tests" + exit 0 + fi + + - name: Start services with docker-compose + run: | + # Start etcd and any other services defined in docker-compose + docker-compose up -d + + - name: Wait for etcd to be ready + run: | + echo "Waiting for etcd to be ready..." + timeout 60 bash -c 'until docker ps | grep etcd | grep -q "Up"; do sleep 2; done' + + # Test etcd health + sleep 10 + curl -sf http://localhost:2379/health || exit 1 + + - name: Show running containers + run: | + echo "=== Running Docker Containers ===" + docker ps + + - name: Show docker-compose services + if: always() + run: | + docker-compose ps || true + + - name: Show service logs on failure + if: failure() + run: | + echo "=== Docker Compose Logs ===" + docker-compose logs || true + + - name: Stop services + if: always() + run: | + docker-compose down -v + + # Integration tests with database + integration-tests: + name: Integration Tests + runs-on: ubuntu-latest + needs: [backend-build] + + services: + mysql: + image: mysql:8.0 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: pixiu + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + + etcd: + image: quay.io/coreos/etcd:v3.6.1 + env: + ALLOW_NONE_AUTHENTICATION: yes Review Comment: The etcd image uses the `quay.io/coreos/etcd:v3.6.1` image with environment variable `ALLOW_NONE_AUTHENTICATION` which doesn't exist for this image. The CoreOS etcd image uses different environment variables than the Bitnami etcd image. For the CoreOS image, authentication is not enabled by default, so this environment variable is unnecessary and will be ignored. Consider removing this line or using the correct etcd image and configuration. ```suggestion ``` ########## .github/workflows/pixiu-admin-ci.yml: ########## @@ -0,0 +1,546 @@ +# 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. + +name: Pixiu-Admin CI + +on: + push: + branches: [ main, develop ] + paths: + - 'admin/**' + - 'docker-compose.yml' + - '.github/workflows/pixiu-admin-ci.yml' + pull_request: + branches: [ main, develop ] + paths: + - 'admin/**' + - 'docker-compose.yml' + - '.github/workflows/pixiu-admin-ci.yml' + +jobs: + # Build and test backend + backend-build: + name: Build Admin Backend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download dependencies + run: | + go mod download + go mod verify + + - name: Build admin binary + run: | + go build -v -o pixiu-admin ./cmd/admin/admin.go + + - name: Run Go tests + run: | + go test -v -race -coverprofile=coverage.out -covermode=atomic ./admin/... + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + files: ./coverage.out + flags: admin-backend + name: admin-backend-coverage + + # Build and test frontend + frontend-build: + name: Build Admin Frontend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Cache node modules + uses: actions/cache@v4 + with: + path: | + admin/web/node_modules + ~/.yarn + key: ${{ runner.os }}-yarn-${{ hashFiles('admin/web/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Install dependencies + run: | + cd admin/web + yarn install + + - name: Run linter + run: | + cd admin/web + yarn lint || true + + - name: Run unit tests + run: | + cd admin/web + yarn test:unit || true + + - name: Build frontend + run: | + cd admin/web + yarn build + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: frontend-dist + path: admin/web/dist/ + retention-days: 7 + + # Docker Compose deployment test + docker-compose-test: + name: Docker Compose Deployment Test + runs-on: ubuntu-latest + needs: [backend-build, frontend-build] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Check if docker-compose.yml exists + run: | + if [ ! -f docker-compose.yml ]; then + echo "⚠️ docker-compose.yml not found in root directory" + echo "Skipping docker-compose tests" + exit 0 + fi + + - name: Start services with docker-compose + run: | + # Start etcd and any other services defined in docker-compose + docker-compose up -d + + - name: Wait for etcd to be ready + run: | + echo "Waiting for etcd to be ready..." + timeout 60 bash -c 'until docker ps | grep etcd | grep -q "Up"; do sleep 2; done' + + # Test etcd health + sleep 10 + curl -sf http://localhost:2379/health || exit 1 + + - name: Show running containers + run: | + echo "=== Running Docker Containers ===" + docker ps + + - name: Show docker-compose services + if: always() + run: | + docker-compose ps || true + + - name: Show service logs on failure + if: failure() + run: | + echo "=== Docker Compose Logs ===" + docker-compose logs || true + + - name: Stop services + if: always() + run: | + docker-compose down -v + + # Integration tests with database + integration-tests: + name: Integration Tests + runs-on: ubuntu-latest + needs: [backend-build] + + services: + mysql: + image: mysql:8.0 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: pixiu + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + + etcd: + image: quay.io/coreos/etcd:v3.6.1 + env: + ALLOW_NONE_AUTHENTICATION: yes + ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379 + ETCD_ADVERTISE_CLIENT_URLS: http://localhost:2379 + ports: + - 2379:2379 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Initialize database + run: | + mysql -h 127.0.0.1 -u root -proot pixiu < admin/resources/sql/pixiu_demo.sql + + - name: Create test config + run: | + cat > /tmp/test-config.yaml <<EOF + server: + address: "127.0.0.1:8081" + etcd: + address: "127.0.0.1:2379" + path: "/pixiu/config/api" + mysql: + username: "root" + password: "root" + host: "127.0.0.1" + port: "3306" + dbname: "pixiu" + EOF + + - name: Run integration tests + run: | + go test -v -tags=integration ./admin/... || true + + - name: Test API operations + run: | + # Start admin server in background + go run ./cmd/admin/admin.go -c /tmp/test-config.yaml & + ADMIN_PID=$! + + # Wait for server to start + sleep 10 + + # Test resource creation + cat > /tmp/resource.yaml <<'EOFRESOURCE' + path: '/test' + type: restful + description: test resource + EOFRESOURCE + + curl -X POST http://localhost:8081/config/api/resource \ + -H "Content-Type: multipart/form-data" \ + -F "content=@/tmp/resource.yaml" + + # Test resource list + curl http://localhost:8081/config/api/resource/list + + # Cleanup + kill $ADMIN_PID || true + + # Manual deployment test (following README instructions) + manual-deployment-test: + name: Manual Deployment Test + runs-on: ubuntu-latest + needs: [backend-build] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Start etcd service + run: | + docker run -d -p 2379:2379 \ + --env ALLOW_NONE_AUTHENTICATION=yes \ + --env ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379 \ + --env ETCD_ADVERTISE_CLIENT_URLS=http://localhost:2379 \ + --name etcd \ + quay.io/coreos/etcd:v3.6.1 + + - name: Wait for etcd to be ready + run: | + echo "Waiting for etcd..." + timeout 60 bash -c 'until curl -sf http://localhost:2379/health 2>/dev/null; do sleep 2; done' + echo "✅ Etcd is ready" + + - name: Create test config file + run: | + mkdir -p /tmp/admin-test + cat > /tmp/admin-test/conf.yaml <<'EOF' + server: + address: "127.0.0.1:8081" + etcd: + address: "127.0.0.1:2379" + path: "/pixiu/config/api" + mysql: + username: "root" + password: "root" + host: "127.0.0.1" + port: "3306" + dbname: "pixiu" + zap: + level: "info" + format: "console" + prefix: "[PIXIU-ADMIN]" + director: "/tmp/logs" + linkName: "latest.log" + showLine: true + encodeLevel: "LowercaseColorLevelEncoder" + stacktraceKey: "stacktrace" + logInConsole: true + system: + env: "develop" + addr: 8081 + dbType: "mysql" + EOF + + - name: Build admin binary + run: | + go build -v -o /tmp/admin-test/pixiu-admin ./cmd/admin/admin.go + + - name: Start admin service in background + run: | + cd /tmp/admin-test + mkdir -p /tmp/logs + nohup ./pixiu-admin -c conf.yaml > /tmp/logs/admin.log 2>&1 & + echo $! > /tmp/admin.pid + echo "Admin PID: $(cat /tmp/admin.pid)" + + - name: Wait for admin service to be ready + run: | + echo "Waiting for admin service..." + for i in {1..30}; do + if curl -f http://localhost:8081/config/api/base 2>/dev/null; then + echo "✅ Admin service is ready" + exit 0 + fi + echo "Attempt $i/30 - waiting..." + sleep 2 + done + echo "❌ Admin service failed to start" + cat /tmp/logs/admin.log + exit 1 + + - name: Test admin API endpoints + run: | + echo "Testing base info endpoint..." + curl -f http://localhost:8081/config/api/base + + echo -e "\nTesting resource list endpoint..." + curl -f http://localhost:8081/config/api/resource/list + + echo -e "\nTesting cluster list endpoint..." + curl -f http://localhost:8081/config/api/cluster/list + + echo -e "\nTesting listener list endpoint..." + curl -f http://localhost:8081/config/api/listener/list Review Comment: The curl commands for testing API endpoints don't include any response validation. The `-f` flag will cause curl to fail on HTTP errors, but this doesn't verify that the responses contain expected data or are properly formatted. Consider adding basic validation of the response content to ensure the endpoints are returning meaningful data, not just HTTP 200 status codes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
