-
Notifications
You must be signed in to change notification settings - Fork 2k
176 lines (148 loc) · 7.15 KB
/
docker_release.yml
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
name: Docker image release
on:
workflow_dispatch:
push:
branches:
- v1.x
tags:
- "v[0-9].[0-9]+.[0-9]+*"
env:
DOCKER_REPO_NAME: deepset/haystack
jobs:
build-and-push:
name: Build ${{ matrix.target }} images
runs-on: ubuntu-latest-4-cores
strategy:
matrix:
target:
- "cpu"
- "cpu-remote-inference"
- "gpu"
steps:
- name: Checkout
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 DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: $DOCKER_REPO_NAME
- name: Build base images
uses: docker/bake-action@v4
env:
IMAGE_TAG_SUFFIX: ${{ steps.meta.outputs.version }}
HAYSTACK_VERSION: ${{ steps.meta.outputs.version }}
with:
workdir: docker
targets: base-${{ matrix.target }}
push: true
- name: Test base image
run: |
EXPECTED_VERSION=$(cat VERSION.txt)
if [[ $EXPECTED_VERSION == *"-"* ]]; then
EXPECTED_VERSION=$(cut -d '-' -f 1 < VERSION.txt)$(cut -d '-' -f 2 < VERSION.txt)
fi
TAG="base-${{ matrix.target }}-${{ steps.meta.outputs.version }}"
PLATFORM="linux/amd64"
VERSION=$(docker run --platform "$PLATFORM" --rm "deepset/haystack:$TAG" python -c"import haystack; print(haystack.__version__)")
[[ "$VERSION" = "$EXPECTED_VERSION" ]] || echo "::error 'Haystack version in deepset/haystack:$TAG image for $PLATFORM is different from expected'"
PLATFORM="linux/arm64"
VERSION=$(docker run --platform "$PLATFORM" --rm "deepset/haystack:$TAG" python -c"import haystack; print(haystack.__version__)")
[[ "$VERSION" = "$EXPECTED_VERSION" ]] || echo "::error 'Haystack version in deepset/haystack:$TAG image for $PLATFORM is different from expected'"
# Remove image after test to avoid filling the GitHub runner and prevent its failure
docker rmi "deepset/haystack:$TAG"
- name: Test non-inference image
if: contains(matrix.target, 'inference') != true
run: |
TAG="base-${{ matrix.target }}-${{ steps.meta.outputs.version }}"
# docker commands below always output a non-empty string, otherwise the step will exit abnormally
PLATFORM="linux/amd64"
TORCH_INSTALLED=$(docker run --platform "$PLATFORM" --rm "deepset/haystack:$TAG" pip list | grep torch || echo 'not found')
[[ "$TORCH_INSTALLED" != "not found" ]] || echo "::error::Pytorch is not installed in deepset/haystack:$TAG image for $PLATFORM"
PLATFORM="linux/arm64"
TORCH_INSTALLED=$(docker run --platform "$PLATFORM" --rm "deepset/haystack:$TAG" pip list | grep torch || echo 'not found')
[[ "$TORCH_INSTALLED" != "not found" ]] || echo "::error::Pytorch is not installed in deepset/haystack:$TAG image for $PLATFORM"
- name: Test inference image
if: contains(matrix.target, 'inference')
run: |
TAG="base-${{ matrix.target }}-${{ steps.meta.outputs.version }}"
# docker commands below always output a non-empty string, otherwise the step will exit abnormally
PLATFORM="linux/amd64"
TORCH_INSTALLED=$(docker run --platform "$PLATFORM" --rm "deepset/haystack:$TAG" sh -c "pip list | grep torch || echo 'not found'")
[[ "$TORCH_INSTALLED" == "not found" ]] || echo "::error::Pytorch is installed in deepset/haystack:$TAG image for $PLATFORM"
PLATFORM="linux/arm64"
TORCH_INSTALLED=$(docker run --platform "$PLATFORM" --rm "deepset/haystack:$TAG" sh -c "pip list | grep torch || echo 'not found'")
[[ "$TORCH_INSTALLED" == "not found" ]] || echo "::error::Pytorch is installed in deepset/haystack:$TAG image for $PLATFORM"
- name: Build api images
uses: docker/bake-action@v4
env:
IMAGE_TAG_SUFFIX: ${{ steps.meta.outputs.version }}
BASE_IMAGE_TAG_SUFFIX: ${{ steps.meta.outputs.version }}
with:
workdir: docker
targets: ${{ matrix.target }}
push: true
- name: Test inference API invocation
if: contains(matrix.target, 'inference')
env:
SERPERDEV_API_KEY: ${{ secrets.SERPERDEV_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
TAG="${{ matrix.target }}-${{ steps.meta.outputs.version }}"
PLATFORMS=("linux/amd64" "linux/arm64")
for PLATFORM in "${PLATFORMS[@]}"; do
docker run --name test-container -d \
--platform "$PLATFORM" \
-e PIPELINE_YAML_PATH=/opt/venv/lib/python3.10/site-packages/rest_api/pipeline/pipelines_web_lfqa.haystack-pipeline.yaml \
-e "RETRIEVER_PARAMS_API_KEY=$SERPERDEV_API_KEY" \
-e "PROMPTNODE_PARAMS_API_KEY=$OPENAI_API_KEY" \
-p 8080:8000 "deepset/haystack:$TAG"
I=0
until docker logs test-container 2>&1 | grep "Uvicorn running"; do
echo "Waiting"
sleep 2
((I++)) && ((I==100)) && echo "::error 'Timeout waiting for Uvicorn to start using deepset/haystack:$TAG image for $PLATFORM'"
done
RESULT=$(curl -s -X POST -H "Content-Type: application/json" -d "{\"query\": \"Where in Europe, should I live?\"}" http://localhost:8080/query)
[[ -n "$RESULT" ]] || echo "::error 'No response from inference API using deepset/haystack:$TAG image for $PLATFORM'"
docker rm -f test-container
done
- name: Get latest version of Haystack
id: latest-version
if: startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=$(gh api repos/${{ github.repository }}/releases/latest --jq ".tag_name")
echo "release=$VERSION" >> "$GITHUB_OUTPUT"
- name: Compare current version with latest
uses: madhead/semver-utils@latest
id: version
if: startsWith(github.ref, 'refs/tags/')
with:
# Version being built
version: ${{ github.ref_name }}
# Compare to latest
compare-to: ${{ steps.latest-version.outputs.release }}
# This step should only run when we release a new minor, so
# that we can tag the most recent image without the version number.
# For example, if the previous step builds `deepset/haystack:cpu-1.8.0`,
# this builds `deepset/haystack:cpu`
- name: Build api images no version in tag
uses: docker/bake-action@v4
if: steps.version.outputs.comparison-result == '>'
env:
IMAGE_TAG_SUFFIX: ${{ steps.meta.outputs.version }}
BASE_IMAGE_TAG_SUFFIX: ${{ steps.meta.outputs.version }}
with:
workdir: docker
targets: ${{ matrix.target }}-latest
push: true