haystack/.github/workflows/docker_release.yml
Silvano Cerza 6e241262ad
ci: Change docker_release.yml workflow to run after successful PyPi release (#4293)
* Change docker_release.yml workflow to run after successful PyPi release

* Add warning on name change in pypi_release.yml
2023-03-01 09:50:47 +01:00

118 lines
3.8 KiB
YAML

name: Docker image release
on:
push:
branches:
- main
workflow_run:
workflows: [Project release on PyPi]
types:
- completed
env:
DOCKER_REPO_NAME: deepset/haystack
jobs:
build-and-push:
name: Build ${{ matrix.target }} image for ${{ matrix.platform }}
# We need this to run only when we're merging in main or the PyPi release was successful
if: ${{ github.event_name == 'push' || github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
strategy:
matrix:
target:
- "cpu"
- "gpu"
platform:
- "linux/amd64"
- "linux/arm64"
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 image
uses: docker/bake-action@v2
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)
TAG="base-${{ matrix.target }}-${{ steps.meta.outputs.version }}"
PLATFORM="${{ matrix.platform }}"
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: Build api image
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: ${{ matrix.target }}
push: true
set: "*.platform=${{ matrix.platform }}"
- 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@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: ${{ matrix.target }}-latest
push: true
set: "*.platform=${{ matrix.platform }}"