-
Notifications
You must be signed in to change notification settings - Fork 3
129 lines (113 loc) · 3.94 KB
/
docker-build.yml
File metadata and controls
129 lines (113 loc) · 3.94 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: Build and Push Docker Image
on:
push:
branches:
- main
- develop
tags:
- 'v*'
pull_request:
branches:
- main
- develop
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
# First job: Build and test the image before pushing
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Build Docker image for testing
run: |
docker build -t hed-bot-test:ci -f ./deploy/Dockerfile --build-arg GIT_COMMIT=${{ github.sha }} .
- name: Smoke test - Start container
run: |
docker run -d --name hed-bot-test \
-p 38427:38427 \
-e REQUIRE_API_AUTH=false \
-e LLM_PROVIDER=openrouter \
-e OPENROUTER_API_KEY=test-key-for-ci \
-e LLM_TEMPERATURE=0.1 \
hed-bot-test:ci
- name: Wait for container to start
run: |
echo "Waiting for container to initialize..."
sleep 45
- name: Smoke test - Check health endpoint
run: |
echo "Checking health endpoint..."
curl -f http://localhost:38427/health || {
echo "Health check failed! Container logs:"
docker logs hed-bot-test
exit 1
}
echo "Health check passed!"
- name: Smoke test - Check container is healthy
run: |
STATUS=$(docker inspect --format='{{.State.Health.Status}}' hed-bot-test 2>/dev/null || echo "no-healthcheck")
echo "Container health status: $STATUS"
if [ "$STATUS" = "unhealthy" ]; then
echo "Container is unhealthy! Logs:"
docker logs hed-bot-test
exit 1
fi
- name: Cleanup test container
if: always()
run: |
docker stop hed-bot-test || true
docker rm hed-bot-test || true
# Second job: Push to registry (on main, develop, and tags - not PRs)
build-and-push:
needs: build-and-test
# Push on main, develop, or tags - skip for PRs (feature branches)
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/'))
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
# Branch-based tags
type=ref,event=branch
# Tag-based tags (v1.0.0 -> 1.0.0)
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
# Latest tag for main branch
type=raw,value=latest,enable={{is_default_branch}}
# Dev tag for develop branch
type=raw,value=dev,enable=${{ github.ref == 'refs/heads/develop' }}
# Commit SHA for traceability
type=sha,prefix=sha-
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./deploy/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GIT_COMMIT=${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Image digest
run: echo "${{ steps.meta.outputs.tags }}"