diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 8ffcfed16..d71d1116e 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -11,36 +11,83 @@ env: IMAGE_PLATFORMS: linux/amd64 PACKAGE: "unstructured" PIP_VERSION: "22.2.1" - BUILD_TYPE_TAG_SUFFIX: "" + PYTHON_VERSION: "3.8" + NLTK_DATA: ${{ github.workspace }}/nltk_data + TEST_IMAGE_NAME: "unstructured-dev" jobs: - build: + setup: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v3 + - uses: actions/checkout@v3 + - uses: actions/cache@v3 + id: virtualenv-cache + with: + path: | + .venv + nltk_data + key: unstructured-${{ runner.os }}-${{ hashFiles('requirements/*.txt') }} + - name: Set up Python ${{ env.PYTHON_VERSION }} + uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + - name: Setup virtual environment (no cache hit) + if: steps.virtualenv-cache.outputs.cache-hit != 'true' + run: | + python${{ env.PYTHON_VERSION }} -m venv .venv + source .venv/bin/activate + make install-ci + + build: + runs-on: ubuntu-latest + needs: [setup] + steps: + - name: Checkout code + uses: actions/checkout@v3 - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 + - name: Set virtualenv cache + uses: actions/cache@v3 + id: virtualenv-cache + with: + path: | + .venv + nltk_data + key: unstructured-${{ runner.os }}-${{ hashFiles('requirements/*.txt') }} - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 - - name: Login to Quay.io - uses: docker/login-action@v1 - with: - registry: quay.io - username: ${{ secrets.QUAY_IO_ROBOT_USERNAME }} - password: ${{ secrets.QUAY_IO_ROBOT_TOKEN }} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 - # TODO(rniko): add a step to test the built image before pushing. Will add after https://unstructured-ai.atlassian.net/browse/CORE-745 is done - - name: Build and push Docker image - run: | - VERSION=$(grep -Po '(?<=__version__ = ")[^"]*' unstructured/__version__.py) - GIT_SHA=$(git rev-parse --short HEAD) - IMAGE_NAME=${{ env.PACKAGE }} - docker buildx build --platform=${{ env.IMAGE_PLATFORMS }} --provenance=false --push \ - --build-arg PIP_VERSION=${{ env.PIP_VERSION }} \ - -t ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_NAMESPACE }}/${IMAGE_NAME}:${GIT_SHA} \ - -t ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_NAMESPACE }}/${IMAGE_NAME}:${VERSION} \ - -t ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_NAMESPACE }}/${IMAGE_NAME}:latest . + - name: Login to Quay.io + uses: docker/login-action@v1 + with: + registry: quay.io + username: ${{ secrets.QUAY_IO_ROBOT_USERNAME }} + password: ${{ secrets.QUAY_IO_ROBOT_TOKEN }} + + - name: Build and push Docker image + run: | + VERSION=$(grep -Po '(?<=__version__ = ")[^"]*' unstructured/__version__.py) + GIT_SHA=$(git rev-parse --short HEAD) + IMAGE_NAME=${{ env.PACKAGE }} + docker buildx create --use --driver=docker-container + docker buildx build --platform=${{ env.IMAGE_PLATFORMS }} --provenance=false --load \ + --cache-to type=gha,scope=$GITHUB_REF_NAME-$IMAGE_NAME \ + --cache-from type=gha,scope=$GITHUB_REF_NAME-$IMAGE_NAME \ + --build-arg PIP_VERSION=${{ env.PIP_VERSION }} \ + --progress plain \ + -t ${{ env.TEST_IMAGE_NAME }}:latest \ + -t ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_NAMESPACE }}/${IMAGE_NAME}:${GIT_SHA} \ + -t ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_NAMESPACE }}/${IMAGE_NAME}:${VERSION} \ + -t ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_NAMESPACE }}/${IMAGE_NAME}:latest . + + - name: Test image + run: | + source .venv/bin/activate + make docker-test + + - name: Push image + run: | + docker image push --all-tags ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_NAMESPACE }}/${{ env.PACKAGE }}