-
Notifications
You must be signed in to change notification settings - Fork 66
214 lines (187 loc) · 7.87 KB
/
dev-ci.yaml
File metadata and controls
214 lines (187 loc) · 7.87 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
name: Dev CI/CD Pipeline
on:
pull_request:
branches: [ "main" ]
types: [opened, synchronize, reopened]
push:
branches: [ "main" ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ghcr.io/versuscontrol/ai-infrastructure-agent
jobs:
# Phase 1: Build check for PRs - verify image builds successfully without pushing
pr-build-check:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata for PR build check
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=ref,event=pr,prefix=pr-
labels: |
org.opencontainers.image.title=AI Infrastructure Agent (PR Build Check)
org.opencontainers.image.description=AI-powered infrastructure discovery and management agent - PR build verification
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.url=https://github.com/${{ github.repository }}
- name: Build Docker image (no push)
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=pr-${{ github.event.number }}
BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
COMMIT_SHA=${{ github.sha }}
- name: Comment PR with build status
uses: actions/github-script@v7
with:
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Docker Build Status')
);
const body = `## Docker Build Status
**Build Successful** for PR #${{ github.event.number }}
### Build Details
- **Platforms**: linux/amd64, linux/arm64
- **Tags**: \`${{ steps.meta.outputs.tags }}\`
- **Commit**: ${{ github.sha }}
- **Version**: pr-${{ github.event.number }}
### Next Steps
- Image build verification passed
- Ready for code review and merge
- Upon merge to main, dev image will be built and pushed automatically
---
*Updated at: ${{ github.event.head_commit.timestamp }}*`;
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
}
- name: Build summary
run: |
echo "## Docker Build Check Summary" >> $GITHUB_STEP_SUMMARY
echo "**Build Status**: SUCCESS" >> $GITHUB_STEP_SUMMARY
echo "**PR Number**: #${{ github.event.number }}" >> $GITHUB_STEP_SUMMARY
echo "**Platforms**: linux/amd64, linux/arm64" >> $GITHUB_STEP_SUMMARY
echo "**Tags**: ${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
echo "**Next**: Image will be pushed when PR is merged to main" >> $GITHUB_STEP_SUMMARY
# Phase 2: Build and push dev image when PR is merged to main
dev-build-push:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for dev image
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=raw,value=dev
type=raw,value=dev-{{sha}}
type=raw,value=dev-{{date 'YYYYMMDD-HHmmss'}}
labels: |
org.opencontainers.image.title=AI Infrastructure Agent (Development)
org.opencontainers.image.description=AI-powered infrastructure discovery and management agent - Development build
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.url=https://github.com/${{ github.repository }}
org.opencontainers.image.documentation=https://github.com/${{ github.repository }}/blob/main/README.md
- name: Build and push dev image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=dev-${{ github.sha }}
BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
COMMIT_SHA=${{ github.sha }}
- name: Inspect dev image
run: |
echo "Inspecting published dev image..."
docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:dev
- name: Create deployment summary
run: |
echo "## Dev Image Deployment Summary" >> $GITHUB_STEP_SUMMARY
echo "**Status**: Successfully built and pushed" >> $GITHUB_STEP_SUMMARY
echo "**Registry**: ${{ env.REGISTRY }}" >> $GITHUB_STEP_SUMMARY
echo "**Available Tags**:" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.meta.outputs.tags }}" | sed 's/^/- /' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Docker Pull Commands" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo "# Latest dev image" >> $GITHUB_STEP_SUMMARY
echo "docker pull ${{ env.IMAGE_NAME }}:dev" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "# Specific commit" >> $GITHUB_STEP_SUMMARY
echo "docker pull ${{ env.IMAGE_NAME }}:dev-${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Image Details" >> $GITHUB_STEP_SUMMARY
echo "- **Platforms**: linux/amd64, linux/arm64" >> $GITHUB_STEP_SUMMARY
echo "- **Version**: dev-${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "- **Commit**: [${{ github.sha }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})" >> $GITHUB_STEP_SUMMARY
echo "- **Build Time**: $(date -u)" >> $GITHUB_STEP_SUMMARY
- name: Post deployment notification
run: |
echo "Dev image successfully deployed!"
echo "Image location: ${{ env.IMAGE_NAME }}:dev"
echo "Registry: ${{ env.REGISTRY }}"
echo "Platforms: linux/amd64, linux/arm64"
echo ""
echo "Available tags:"
echo "${{ steps.meta.outputs.tags }}" | sed 's/^/ - /'