-
Notifications
You must be signed in to change notification settings - Fork 1.2k
131 lines (130 loc) · 4.59 KB
/
build.yaml
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
env:
REGISTRY: ghcr.io/anthropics/anthropic-quickstarts
name: build
on:
pull_request:
paths:
- .github/**
- computer-use-demo/**
push:
branches:
- main
paths:
- .github/**
- computer-use-demo/**
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: true
matrix:
platform:
- amd64
- arm64
steps:
- uses: actions/checkout@v4
- name: Login to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set image tag
run: |
short_sha=$(git rev-parse --short ${{ github.sha }})
echo "TAG=${REGISTRY}:computer-use-demo-${short_sha}" >> "$GITHUB_ENV"
- name: Build Docker image
uses: docker/build-push-action@v5
with:
platforms: linux/${{ matrix.platform }}
context: computer-use-demo
push: false
tags: ${{ env.TAG }}
cache-from: type=gha,scope=computer-use-${{ matrix.platform }}
cache-to: type=gha,mode=max,scope=computer-use-${{ matrix.platform }}
load: true
- name: Run container
run: docker run -d -p 8051:8051 ${{ env.TAG }}
- name: Check streamlit
run: |
timeout=60
start_time=$(date +%s)
docker_id=$(docker ps --filter "ancestor=${{ env.TAG }}" --format "{{.ID}}")
echo "docker_id=$docker_id" >> "$GITHUB_ENV"
while true; do
current_time=$(date +%s)
elapsed=$((current_time - start_time))
if [ $elapsed -ge $timeout ]; then
echo "Timeout reached. Container did not respond within $timeout seconds."
exit 1
fi
response=$(docker exec $docker_id curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8501 || echo "000")
if [ "$response" = "200" ]; then
echo "Container responded with 200 OK"
exit 0
fi
done
- name: Check VNC
run: docker exec $docker_id nc localhost 5900 -z
- name: Check noVNC
run: docker exec $docker_id curl -s -o /dev/null -w "%{http_code}" http://localhost:6080 | grep -q 200 || exit 1
- name: Check landing page
run: docker exec $docker_id curl -s -o /dev/null -w "%{http_code}" http://localhost:8080 | grep -q 200 || exit 1
- name: Determine push tags
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "PUSH_TAGS=${TAG}-${{ matrix.platform }}" >> "$GITHUB_ENV"
else
echo "PUSH_TAGS=${TAG}-${{ matrix.platform }},${REGISTRY}:computer-use-demo-latest-${{ matrix.platform }}" >> "$GITHUB_ENV"
fi
- name: Push Docker image
uses: docker/build-push-action@v5
with:
platforms: linux/${{ matrix.platform }}
context: computer-use-demo
push: true
tags: ${{ env.PUSH_TAGS }}
cache-from: type=gha,scope=computer-use-${{ matrix.platform }}
cache-to: type=gha,mode=max,scope=computer-use-${{ matrix.platform }}
merge:
runs-on: ubuntu-latest
needs:
- build
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Login to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set image tag
run: |
echo "SHORT_SHA=$(git rev-parse --short ${{ github.sha }})" >> "$GITHUB_ENV"
- name: Create SHA manifest and push
run: |
docker buildx imagetools create -t \
${REGISTRY}:computer-use-demo-${SHORT_SHA} \
${REGISTRY}:computer-use-demo-${SHORT_SHA}-amd64 \
${REGISTRY}:computer-use-demo-${SHORT_SHA}-arm64
- name: Create latest manifest and push
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
docker buildx imagetools create -t \
${REGISTRY}:computer-use-demo-latest \
${REGISTRY}:computer-use-demo-latest-amd64 \
${REGISTRY}:computer-use-demo-latest-arm64