WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 2a9672b

Browse files
committed
Adds basic cicd
1 parent 0e1118e commit 2a9672b

File tree

4 files changed

+276
-0
lines changed

4 files changed

+276
-0
lines changed

.github/workflows/main.yml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
name: Webhook Relay CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
tags: [ 'v*' ]
7+
pull_request:
8+
branches: [ main ]
9+
10+
jobs:
11+
lint:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: '3.11'
20+
cache: 'pip'
21+
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install ".[dev]"
26+
27+
- name: Run black
28+
run: black --check src tests
29+
30+
- name: Run isort
31+
run: isort --check-only --profile black src tests
32+
33+
- name: Run flake8
34+
run: flake8 src tests
35+
36+
- name: Run mypy
37+
run: mypy src
38+
39+
test:
40+
runs-on: ubuntu-latest
41+
strategy:
42+
matrix:
43+
python-version: ['3.8', '3.9', '3.10', '3.11']
44+
45+
steps:
46+
- uses: actions/checkout@v3
47+
48+
- name: Set up Python ${{ matrix.python-version }}
49+
uses: actions/setup-python@v4
50+
with:
51+
python-version: ${{ matrix.python-version }}
52+
cache: 'pip'
53+
54+
- name: Install dependencies
55+
run: |
56+
python -m pip install --upgrade pip
57+
pip install ".[all,dev]"
58+
59+
- name: Run tests
60+
run: pytest --cov=webhook_relay tests/
61+
62+
- name: Upload coverage to Codecov
63+
uses: codecov/codecov-action@v3
64+
with:
65+
fail_ci_if_error: false
66+
67+
build-and-publish:
68+
needs: [lint, test]
69+
runs-on: ubuntu-latest
70+
permissions:
71+
contents: read
72+
packages: write
73+
74+
steps:
75+
- uses: actions/checkout@v3
76+
77+
- name: Set up Docker Buildx
78+
uses: docker/setup-buildx-action@v2
79+
80+
- name: Extract metadata for Docker
81+
id: meta
82+
uses: docker/metadata-action@v4
83+
with:
84+
images: kapicorp/webhook_relay
85+
tags: |
86+
type=semver,pattern={{version}}
87+
type=semver,pattern={{major}}.{{minor}}
88+
type=ref,event=branch
89+
type=sha,format=long
90+
91+
- name: Build and push Docker image
92+
uses: docker/build-push-action@v4
93+
with:
94+
context: .
95+
push: ${{ github.event_name != 'pull_request' }}
96+
tags: ${{ steps.meta.outputs.tags }}
97+
labels: ${{ steps.meta.outputs.labels }}
98+
cache-from: type=gha
99+
cache-to: type=gha,mode=max
100+
101+
build-python-package:
102+
needs: [lint, test]
103+
runs-on: ubuntu-latest
104+
steps:
105+
- uses: actions/checkout@v3
106+
107+
- name: Set up Python
108+
uses: actions/setup-python@v4
109+
with:
110+
python-version: '3.11'
111+
112+
- name: Install build tools
113+
run: |
114+
python -m pip install --upgrade pip
115+
pip install build twine
116+
117+
- name: Build package
118+
run: python -m build
119+
120+
- name: Check package
121+
run: twine check dist/*
122+
123+
- name: Upload artifacts
124+
uses: actions/upload-artifact@v3
125+
with:
126+
name: python-package
127+
path: dist/

Dockerfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
FROM python:3.11-slim
2+
3+
# Set environment variables
4+
ENV PYTHONDONTWRITEBYTECODE=1 \
5+
PYTHONUNBUFFERED=1 \
6+
PIP_NO_CACHE_DIR=off \
7+
PIP_DISABLE_PIP_VERSION_CHECK=on
8+
9+
# Create app directory
10+
WORKDIR /app
11+
12+
# Install dependencies
13+
COPY README.md ./
14+
COPY pyproject.toml ./
15+
RUN pip install --upgrade pip && \
16+
pip install build && \
17+
pip install --no-deps ".[all]"
18+
19+
# Copy the source code
20+
COPY src /app/src
21+
22+
# Build the package to ensure any build-time steps are completed
23+
RUN pip install -e .
24+
25+
# Create a non-root user to run the application
26+
RUN addgroup --system webhook && \
27+
adduser --system --ingroup webhook webhookuser
28+
29+
# Switch to the non-root user
30+
USER webhookuser
31+
32+
# Set up volume for configuration
33+
VOLUME /config
34+
35+
# Expose ports
36+
EXPOSE 8000 9090 9091
37+
38+
# Set the entrypoint
39+
ENTRYPOINT ["python", "-m"]
40+
41+
# Default command (can be overridden)
42+
CMD ["webhook_relay.collector.app", "serve", "--config", "/config/collector_config.yaml"]

Makefile

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
.PHONY: help install dev test lint format clean docker-build docker-run
2+
3+
PYTHON := python
4+
PIP := $(PYTHON) -m pip
5+
PYTEST := $(PYTHON) -m pytest
6+
BLACK := $(PYTHON) -m black
7+
ISORT := $(PYTHON) -m isort
8+
FLAKE8 := $(PYTHON) -m flake8
9+
MYPY := $(PYTHON) -m mypy
10+
11+
help: ## Show this help message
12+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
13+
14+
install: ## Install the package and dependencies
15+
$(PIP) install -e ".[all]"
16+
17+
dev: ## Install development dependencies
18+
$(PIP) install -e ".[all,dev]"
19+
20+
test: ## Run tests
21+
$(PYTEST) tests/
22+
23+
test-cov: ## Run tests with coverage
24+
$(PYTEST) --cov=webhook_relay tests/
25+
26+
lint: ## Run linters
27+
$(BLACK) --check src tests
28+
$(ISORT) --check-only --profile black src tests
29+
$(FLAKE8) src tests
30+
$(MYPY) src
31+
32+
format: ## Format code
33+
$(BLACK) src tests
34+
$(ISORT) --profile black src tests
35+
36+
clean: ## Clean build artifacts
37+
rm -rf build/
38+
rm -rf dist/
39+
rm -rf *.egg-info
40+
rm -rf .coverage
41+
rm -rf .pytest_cache
42+
rm -rf .mypy_cache
43+
find . -type d -name __pycache__ -exec rm -rf {} +
44+
45+
docker-build: ## Build Docker image
46+
docker build -t webhook-relay .
47+
48+
docker-run-collector: ## Run collector service in Docker
49+
docker run -p 8000:8000 -p 9090:9090 -v $(PWD)/examples:/config webhook-relay webhook_relay.collector.app serve --config /config/collector_config.yaml
50+
51+
docker-run-forwarder: ## Run forwarder service in Docker
52+
docker run -p 9091:9091 -v $(PWD)/examples:/config webhook-relay webhook_relay.forwarder.app serve --config /config/forwarder_config.yaml
53+
54+
docker-compose-up: ## Run all services with docker-compose
55+
docker-compose up -d
56+
57+
docker-compose-down: ## Stop all services with docker-compose
58+
docker-compose down

docker-compose.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
version: '3.8'
2+
3+
services:
4+
collector:
5+
build: .
6+
image: webhook-relay:latest
7+
command: webhook_relay.collector.app serve --config /config/collector_config.yaml
8+
ports:
9+
- "8000:8000" # API port
10+
- "9090:9090" # Metrics port
11+
volumes:
12+
- ./examples:/config
13+
environment:
14+
- WEBHOOK_RELAY_LOG_LEVEL=INFO
15+
networks:
16+
- webhook-net
17+
restart: unless-stopped
18+
19+
forwarder-example:
20+
build: .
21+
image: webhook-relay:latest
22+
command: webhook_relay.forwarder.app serve --config /config/forwarder_config.yaml
23+
ports:
24+
- "9091:9091" # Metrics port
25+
volumes:
26+
- ./examples:/config
27+
environment:
28+
- WEBHOOK_RELAY_LOG_LEVEL=INFO
29+
networks:
30+
- webhook-net
31+
restart: unless-stopped
32+
depends_on:
33+
- collector
34+
35+
# Example of a target service that might receive the forwarded webhooks
36+
# This is just a placeholder for demonstration
37+
target-service:
38+
image: nginx:alpine
39+
ports:
40+
- "8080:80"
41+
networks:
42+
- webhook-net
43+
restart: unless-stopped
44+
volumes:
45+
- ./examples/nginx-placeholder.conf:/etc/nginx/conf.d/default.conf
46+
47+
networks:
48+
webhook-net:
49+
driver: bridge

0 commit comments

Comments
 (0)