Skip to content

Commit 6d8462a

Browse files
feat(integrations/chat): smoke test for docker image (botpress#14933)
1 parent 296d75d commit 6d8462a

1 file changed

Lines changed: 136 additions & 7 deletions

File tree

.github/workflows/docker-chat.yml

Lines changed: 136 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,20 @@ on:
88
- 'integrations/chat/**'
99
- 'packages/sdk/**'
1010

11-
workflow_dispatch: {}
11+
push:
12+
branches:
13+
- master
14+
paths:
15+
- 'integrations/chat/**'
16+
- 'packages/sdk/**'
17+
18+
workflow_dispatch:
19+
inputs:
20+
push_to_ecr:
21+
description: 'Push image to ECR after successful tests'
22+
required: true
23+
type: boolean
24+
default: true
1225

1326
permissions:
1427
id-token: write
@@ -19,17 +32,133 @@ concurrency:
1932
cancel-in-progress: false
2033

2134
jobs:
22-
docker-chat:
35+
build-test-push:
2336
runs-on: depot-ubuntu-latest
2437
steps:
2538
- uses: actions/checkout@v4
39+
2640
- name: Setup # FIXME: This should not be necessary, as the Dockerfile should be self-contained
2741
uses: ./.github/actions/setup
2842
with:
2943
extra_filters: '-F @botpresshub/chat'
30-
- uses: ./.github/actions/docker-build
44+
45+
- uses: aws-actions/configure-aws-credentials@v3
46+
if: ${{ github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.push_to_ecr) }}
47+
with:
48+
role-session-name: container_pusher
49+
role-to-assume: arn:aws:iam::986677156374:role/actions/build/container_pusher
50+
aws-region: us-east-1
51+
52+
- uses: aws-actions/amazon-ecr-login@v1
53+
if: ${{ github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.push_to_ecr) }}
54+
id: ecr
3155
with:
32-
repository: chat-integration
33-
dockerfile: ./integrations/chat/Dockerfile
34-
push: ${{ github.event_name == 'workflow_dispatch' }}
35-
depot-project: ${{ secrets.DEPOT_PROJECT_ID }}
56+
mask-password: true
57+
58+
- uses: docker/metadata-action@v4
59+
if: ${{ github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.push_to_ecr) }}
60+
id: meta
61+
with:
62+
images: ${{ steps.ecr.outputs.registry }}/chat-integration
63+
flavor: |
64+
latest=false
65+
tags: |
66+
type=sha,prefix=,format=long
67+
68+
- name: Set BUILD_DATE
69+
id: meta_date
70+
run: |
71+
export TZ=America/Toronto
72+
echo "timestamp=$(date +"%Y-%m-%d %H:%M:%S")" >> "$GITHUB_OUTPUT"
73+
74+
- name: Create ECR Registry
75+
if: ${{ github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.push_to_ecr) }}
76+
env:
77+
ECR_REPOSITORY: chat-integration
78+
run: |
79+
aws --version
80+
aws ecr create-repository --repository-name $ECR_REPOSITORY || true
81+
aws ssm get-parameter --name '/cloud/container-registry/ecr-policy-document' --query 'Parameter.Value' | jq -r '.' > repository-policy.json
82+
aws ecr set-repository-policy --repository-name $ECR_REPOSITORY --policy-text file://repository-policy.json &> /dev/null
83+
84+
- name: Set up Depot CLI
85+
uses: depot/setup-action@v1
86+
87+
- name: Build Docker image
88+
uses: depot/build-push-action@v1
89+
with:
90+
project: ${{ secrets.DEPOT_PROJECT_ID }}
91+
build-args: |
92+
MINIFY=true
93+
BUILD_DATE=${{ steps.meta_date.outputs.timestamp }}
94+
file: ./integrations/chat/Dockerfile
95+
context: .
96+
push: false
97+
load: true
98+
tags: chat-integration:test
99+
labels: ${{ steps.meta.outputs.labels }}
100+
101+
- name: Start Docker container
102+
run: |
103+
docker run -d \
104+
--name chat-test \
105+
-p 8081:8081 \
106+
-e SECRET_SIGNAL_URL=https://chat.botpress.dev \
107+
chat-integration:test
108+
109+
- name: Wait for container to be ready
110+
run: |
111+
echo "Waiting for container to start..."
112+
for i in {1..30}; do
113+
if docker ps --filter "name=chat-test" --filter "status=running" | grep -q chat-test; then
114+
echo "Container is running"
115+
sleep 5
116+
exit 0
117+
fi
118+
if docker ps -a --filter "name=chat-test" --filter "status=exited" | grep -q chat-test; then
119+
echo "Container exited prematurely!"
120+
docker logs chat-test
121+
exit 1
122+
fi
123+
echo "Waiting for container... ($i/30)"
124+
sleep 2
125+
done
126+
echo "Container did not start within expected time"
127+
docker ps -a
128+
exit 1
129+
130+
- name: Check health endpoint
131+
run: |
132+
echo "Checking /health endpoint..."
133+
for i in {1..15}; do
134+
if curl -f http://localhost:8081/health; then
135+
echo "Health check passed!"
136+
exit 0
137+
fi
138+
echo "Attempt $i/15 failed, retrying..."
139+
sleep 2
140+
done
141+
echo "Health check failed after 15 attempts"
142+
exit 1
143+
144+
- name: Show container logs on failure
145+
if: failure()
146+
run: docker logs chat-test
147+
148+
- name: Cleanup container
149+
if: always()
150+
run: docker rm -f chat-test || true
151+
152+
- name: Tag and push to ECR
153+
if: ${{ github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.push_to_ecr) }}
154+
env:
155+
ECR_REGISTRY: ${{ steps.ecr.outputs.registry }}
156+
IMAGE_TAG: ${{ github.sha }}
157+
run: |
158+
echo "Tagging image for ECR: $ECR_REGISTRY/chat-integration:$IMAGE_TAG"
159+
docker tag chat-integration:test $ECR_REGISTRY/chat-integration:$IMAGE_TAG
160+
161+
echo "Pushing to ECR..."
162+
docker push $ECR_REGISTRY/chat-integration:$IMAGE_TAG
163+
164+
echo "Successfully pushed image: $IMAGE_TAG"

0 commit comments

Comments
 (0)