-
Notifications
You must be signed in to change notification settings - Fork 0
115 lines (99 loc) · 3.72 KB
/
python-app.yml
File metadata and controls
115 lines (99 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# This workflow will install Python dependencies, run tests, lint, and build/push Docker image
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python application
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
permissions:
contents: read
packages: write # Required for pushing to GitHub Container Registry (GHCR)
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest test_main.py test_comprehensive.py test_api_endpoints.py -v --tb=short
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to GitHub Container Registry
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy-notification:
needs: build-and-test
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- name: Deployment Success
run: |
echo "✅ Workflow completed successfully!"
echo ""
echo "📊 Summary:"
echo " ✓ Tests: PASSED"
echo " ✓ Linting: PASSED"
echo " ✓ Docker Build: PASSED"
echo " ✓ Docker Push: PASSED"
echo ""
echo "🚀 Image pushed to GitHub Container Registry:"
echo " Registry: ghcr.io"
echo " Image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
echo ""
echo "📦 Pull the image with:"
echo " docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest"
echo ""
echo "🏃 Run the container with:"
echo " docker run -d \\"
echo " -p 8000:8000 \\"
echo " -e DB_TYPE=mysql \\"
echo " -e DB_HOST=your-db-host \\"
echo " -e DB_PORT=3306 \\"
echo " -e DB_USER=your-user \\"
echo " -e DB_PASSWORD=your-password \\"
echo " -e DB_NAME=your-database \\"
echo " ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest"