Skip to content

Commit

Permalink
✨ feat: Added Docker push workflow, Dockerfile updates, and build script
Browse files Browse the repository at this point in the history
add Docker Push workflow and stages for building and pushing Docker images with different variants for autoraghq/autorag, including handling production image tagging and updating Docker Hub description.
  • Loading branch information
hongsw committed Oct 7, 2024
1 parent 3232c90 commit d4d36a6
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 11 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/docker-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Docker Push

on:
push:
branches: [ "main" ]
tags: [ "v*.*.*" ]
pull_request:
branches: [ "main" ]

env:
DOCKER_REPO: "autoraghq/autorag"

jobs:
check-version:
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.version_changed.outputs.changed }}
steps:
- name: Checkout code
uses: actions/checkout@v4.2.0

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v45.0.3

- name: Check for VERSION file change
id: version_changed
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
echo "changed=false" >> $GITHUB_OUTPUT
if echo "${ALL_CHANGED_FILES}" | grep -q 'VERSION'; then
echo "changed=true" >> $GITHUB_OUTPUT
fi
build-and-push:
needs: check-version
if: needs.check-version.outputs.changed == 'true'
runs-on: ubuntu-latest
strategy:
matrix:
variant: [all] # [all, ko, dev, parsing]
steps:
- name: Checkout code
uses: actions/checkout@v4.2.0

- name: Read VERSION file
run: echo "VERSION=$(cat autorag/VERSION)" >> $GITHUB_ENV

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.7.1

- name: Login to Docker Hub
uses: docker/login-action@v3.3.0
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5.5.1
with:
images: ${{ env.DOCKER_REPO }}
tags: |
type=raw,value=${{ env.VERSION }}-${{ matrix.variant }}
type=raw,value=${{ matrix.variant }},enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=latest-${{ matrix.variant }},enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
- name: Build and push Docker image
uses: docker/build-push-action@v6.9.0
with:
context: .
file: ./Dockerfile
push: true
# push: ${{ github.event_name != 'pull_request' && matrix.variant != 'test' }}
tags: ${{ env.DOCKER_REPO }}:${{ env.VERSION }}-${{matrix.variant}}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
TARGET_STAGE=${{ matrix.variant }}
- name: Tag and push 'all' for production
run: |
docker pull ${{ env.DOCKER_REPO }}:${{ env.VERSION }}-${{matrix.variant}}
docker tag ${{ env.DOCKER_REPO }}:${{ env.VERSION }}-${{matrix.variant}} ${{ env.DOCKER_REPO }}:latest
docker push ${{ env.DOCKER_REPO }}:${{ env.VERSION }}-${{matrix.variant}}
docker push ${{ env.DOCKER_REPO }}:latest
# - name: Update Docker Hub description
# uses: peter-evans/dockerhub-description@v3
# with:
# username: ${{ secrets.DOCKER_HUB_USERNAME }}
# password: ${{ secrets.DOCKER_HUB_PASSWORD }}
# repository: ${{ env.DOCKER_REPO }}
# short-description: ${{ github.event.repository.description }}
36 changes: 26 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Base stage: Install dependencies
# Base stage: Install common dependencies
FROM python:3.10-slim AS base

# Install system dependencies
Expand All @@ -19,27 +19,43 @@ WORKDIR /usr/src/app
# Install Python dependencies
RUN pip install --upgrade pip setuptools setuptools-scm
COPY requirements.txt /usr/src/app/requirements.txt

RUN pip install -r requirements.txt

# Copy project files
COPY . /usr/src/app
RUN pip install -e ./

# Test stage: Run tests if CI=true
# Test stage
FROM base AS test

# Install testing dependencies
RUN pip install pytest pytest-xdist

# Run tests if CI is set to true
RUN pytest -o log_cli=true --log-cli-level=INFO -n auto tests
# Ko stage
FROM base AS ko
RUN pip install --no-cache-dir kiwipiepy>=0.18.0 konlpy
ENTRYPOINT ["python", "-m", "autorag.cli"]

# Dev stage
FROM base AS dev
RUN pip install --no-cache-dir ruff pre-commit
ENTRYPOINT ["python", "-m", "autorag.cli"]

# Parsing stage
FROM base AS parsing
RUN pip install --no-cache-dir PyMuPDF pdfminer.six pdfplumber unstructured jq "unstructured[pdf]" "PyPDF2<3.0" pdf2image
ENTRYPOINT ["python", "-m", "autorag.cli"]

# Parsing stage
FROM base AS all
# TODO
ENTRYPOINT ["python", "-m", "autorag.cli"]

# Production stage: Create final image for production
# Production stage (includes all features)
FROM base AS production
RUN pip install --no-cache-dir \
kiwipiepy>=0.18.0 konlpy \
ruff pre-commit \
PyMuPDF pdfminer.six pdfplumber unstructured jq "unstructured[pdf]" "PyPDF2<3.0" pdf2image

COPY projects /usr/src/app/projects

# Set the entrypoint for the production application
ENTRYPOINT ["python", "-m", "autorag.cli"]
# ENTRYPOINT ["bash"]
2 changes: 1 addition & 1 deletion autorag/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.3
0.3.3-rc16
39 changes: 39 additions & 0 deletions build_and_push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# Check if version is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <version>"
exit 1
fi

VERSION=$1
DOCKER_REPO="autoraghq/autorag"

# Array of variants
variants=("all" "ko" "dev" "parsing" "test")

# Build and push for each variant
for variant in "${variants[@]}"
do
echo "Building $DOCKER_REPO:$VERSION-$variant"
docker build --build-arg TARGET_STAGE=$variant -t $DOCKER_REPO:$VERSION-$variant -f Dockerfile .

echo "Pushing $DOCKER_REPO:$VERSION-$variant"
docker push $DOCKER_REPO:$VERSION-$variant

# If it's a release build, also tag and push as latest for that variant
if [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Tagging and pushing $DOCKER_REPO:$variant"
docker tag $DOCKER_REPO:$VERSION-$variant $DOCKER_REPO:$variant
docker push $DOCKER_REPO:$variant
fi
done

# Special handling for 'production' as 'all'
if [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Tagging and pushing $DOCKER_REPO:all"
docker tag $DOCKER_REPO:$VERSION-production $DOCKER_REPO:all
docker push $DOCKER_REPO:all
fi

echo "Build and push complete for all variants"

0 comments on commit d4d36a6

Please sign in to comment.