haystack/.github/workflows/docker_release.yml
2023-02-10 17:54:20 +01:00

119 lines
4.0 KiB
YAML

name: Docker image release
on:
workflow_dispatch:
push:
branches:
- main
tags:
- "v[0-9].[0-9]+.[0-9]+*"
env:
DOCKER_REPO_NAME: deepset/haystack
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: $DOCKER_REPO_NAME
- name: Build base images
uses: docker/bake-action@v2
env:
IMAGE_TAG_SUFFIX: ${{ steps.meta.outputs.version }}
HAYSTACK_VERSION: ${{ steps.meta.outputs.version }}
with:
workdir: docker
targets: base
push: true
- name: Test base images
run: |
EXPECTED_VERSION=$(cat VERSION.txt)
function test_image {
local TAG, PLATFORM, VERSION
TAG=$1
PLATFORM=$2
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"
}
test_image base-cpu-${{ steps.meta.outputs.version }} linux/amd64
test_image base-gpu-${{ steps.meta.outputs.version }} linux/amd64
test_image base-cpu-${{ steps.meta.outputs.version }} linux/arm64
test_image base-gpu-${{ steps.meta.outputs.version }} linux/arm64
- name: Build api images
uses: docker/bake-action@v2
env:
IMAGE_TAG_SUFFIX: ${{ steps.meta.outputs.version }}
BASE_IMAGE_TAG_SUFFIX: ${{ steps.meta.outputs.version }}
with:
workdir: docker
targets: api
push: true
- name: Get latest version of Haystack
id: latest-version
uses: pozetroninc/github-action-get-latest-release@master
if: startsWith(github.ref, 'refs/tags/')
with:
repository: ${{ github.repository }}
excludes: prerelease, draft
- 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@v2
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: api-latest
push: true
- name: Test api image no version in tag
if: steps.version.outputs.comparison-result == '>'
run: |
docker compose up -d
# Waits for containers to come up
sleep 15s
EXPECTED_VERSION=$(cat VERSION.txt)
VERSION=$(curl http://localhost:8000/hs_version | jq .hs_version)
[[ "$VERSION" = "$EXPECTED_VERSION" ]] || echo "::error 'Haystack version in REST API image is different from expected'"