David Chu commited on
Commit
43fe182
·
unverified ·
1 Parent(s): 3865f47

ci: test and push to docker hub

Browse files
Files changed (2) hide show
  1. .github/workflows/tests.yml +78 -0
  2. docker-compose.yml +21 -0
.github/workflows/tests.yml ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: tests
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - main
8
+
9
+ permissions:
10
+ contents: read
11
+ id-token: write
12
+
13
+ env:
14
+ IMAGE_NAME: hhschu/elna
15
+ UV_CACHE_DIR: /tmp/.uv-cache
16
+
17
+ jobs:
18
+ ruff-check:
19
+ runs-on: ubuntu-latest
20
+ steps:
21
+ - uses: actions/checkout@v4
22
+ - name: Run ruff check
23
+ uses: astral-sh/ruff-action@v3
24
+
25
+ ruff-format:
26
+ runs-on: ubuntu-latest
27
+ steps:
28
+ - uses: actions/checkout@v4
29
+ - name: Run ruff format
30
+ uses: astral-sh/ruff-action@v3
31
+ with:
32
+ args: "format --check --diff"
33
+
34
+ pyright:
35
+ runs-on: ubuntu-latest
36
+ steps:
37
+ - uses: actions/checkout@v4
38
+
39
+ - name: Set up Python
40
+ uses: astral-sh/setup-uv@v6
41
+ with:
42
+ enable-cache: true
43
+ version: "latest"
44
+ python-version: 3.12
45
+
46
+ - name: Run type check
47
+ run: uv run --frozen --with pyright pyright
48
+
49
+ build-and-push-image:
50
+ runs-on: ubuntu-latest
51
+ steps:
52
+ - uses: actions/checkout@v4
53
+
54
+ - name: Login to Docker Hub
55
+ uses: docker/login-action@v3
56
+ with:
57
+ username: ${{ vars.DOCKERHUB_USERNAME }}
58
+ password: ${{ secrets.DOCKERHUB_TOKEN }}
59
+
60
+ - name: Set up Docker Buildx
61
+ uses: docker/setup-buildx-action@v3
62
+
63
+ - name: Extract metadata (tags, labels) for Docker
64
+ id: meta
65
+ uses: docker/metadata-action@v5
66
+ with:
67
+ images: ${{ env.IMAGE_NAME }}
68
+ tags: |
69
+ type=raw,value=latest,enable={{is_default_branch}}
70
+ type=ref,event=tag
71
+ type=ref,event=pr
72
+
73
+ - name: Build and push Docker image
74
+ uses: docker/build-push-action@v5
75
+ with:
76
+ push: ${{ github.ref == 'refs/heads/main' }}
77
+ tags: ${{ steps.meta.outputs.tags }}
78
+ labels: ${{ steps.meta.outputs.labels }}
docker-compose.yml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ services:
2
+ webserver:
3
+ image: hhschu/elna
4
+ pull_policy: always
5
+ security_opt:
6
+ - "no-new-privileges:true"
7
+ cap_drop:
8
+ - ALL
9
+ env_file:
10
+ - .env
11
+ command:
12
+ - fastapi
13
+ - run
14
+ - --port=80
15
+ - app/main.py
16
+ restart: "unless-stopped"
17
+ healthcheck:
18
+ test: ["CMD-SHELL", "curl -f http://localhost:80/health || exit 1"]
19
+ interval: 5m
20
+ start_period: 30s
21
+ start_interval: 5s