diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml new file mode 100644 index 0000000..b6bba90 --- /dev/null +++ b/.github/workflows/docker-push.yml @@ -0,0 +1,42 @@ +name: Push Docker image to GitHub Container Registry + +on: + push: + tags: + - '*' + +jobs: + build-and-push: + runs-on: ubuntu-22.04 + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Prune Docker System + run: docker system prune -af + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets._GITHUB_PAT }} + + - name: Git lowercase repository owner + id: repository-owner-lowercase + uses: ASzc/change-string-case-action@v6 + with: + string: ${{ github.repository_owner }} + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: | + ghcr.io/${{ steps.repository-owner-lowercase.outputs.lowercase }}/rvc-api:${{ github.ref_name }} + ghcr.io/${{ steps.repository-owner-lowercase.outputs.lowercase }}/rvc-api:latest diff --git a/Dockerfile b/Dockerfile index 388e4ee..b5df782 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,11 @@ FROM alpine:3.19.1 as assets -RUN apk add --update \ - bash \ - git \ - git-lfs +RUN apk add \ + --update \ + --no-cache \ + bash \ + git \ + git-lfs COPY --chmod=755 ./assets-download.sh /assets-download.sh @@ -16,20 +18,26 @@ SHELL [ "/bin/bash", "-c" ] RUN apt update && \ apt install -y \ libsndfile1 \ - libsndfile1-dev + libsndfile1-dev && \ + apt clean && \ + rm -rf /var/lib/apt/lists/* COPY --from=assets /assets /assets WORKDIR /app -RUN pip install "poetry==1.7.1" - COPY ./pyproject.toml . -RUN poetry install +RUN pip install \ + --no-cache-dir \ + "poetry==1.7.1" && \ + poetry config virtualenvs.create false && \ + poetry install \ + --no-interaction \ + --no-root && \ + poetry cache clear --all . COPY ./rvc ./rvc - COPY ./.env-docker ./.env CMD [ "poetry", "run", "poe", "rvc-api" ] diff --git a/assets-download.sh b/assets-download.sh index aa745b4..83d7f53 100644 --- a/assets-download.sh +++ b/assets-download.sh @@ -2,6 +2,12 @@ # # Downloads required large files for RVC. +function download() { + local path="$1" + echo "Downloading ${path}" + git lfs pull --include="${path}" +} + set -e REPO_FOLDER="VoiceConversionWebUI" @@ -16,27 +22,31 @@ git clone https://huggingface.co/lj1995/VoiceConversionWebUI "${REPO_FOLDER}" pushd "${REPO_FOLDER}" +git config advice.detachedHead false + git checkout "${assets_commit_hash}" unset GIT_LFS_SKIP_SMUDGE unset GIT_CLONE_PROTECTION_ACTIVE -git lfs pull --include="hubert_base.pt" -git lfs pull --include="pretrained" -git lfs pull --include="uvr5_weights" -git lfs pull --include="rmvpe.pt" -git lfs pull --include="rmvpe.onnx" +download "hubert_base.pt" +download "pretrained" +download "uvr5_weights" +download "rmvpe.pt" +download "rmvpe.onnx" + +rm -rf .git popd mkdir -p "${assets_dir}" -cp "${REPO_FOLDER}/hubert_base.pt" "${assets_dir}/hubert_base.pt" +mv "${REPO_FOLDER}/hubert_base.pt" "${assets_dir}/hubert_base.pt" mkdir -p "${assets_dir}/rmvpe" -cp "${REPO_FOLDER}/rmvpe.pt" "${assets_dir}/rmvpe/rmvpe.pt" -cp "${REPO_FOLDER}/rmvpe.onnx" "${assets_dir}/rmvpe/rmvpe.onnx" +mv "${REPO_FOLDER}/rmvpe.pt" "${assets_dir}/rmvpe/rmvpe.pt" +mv "${REPO_FOLDER}/rmvpe.onnx" "${assets_dir}/rmvpe/rmvpe.onnx" -cp -r "${REPO_FOLDER}/pretrained" "${assets_dir}/pretrained" -cp -r "${REPO_FOLDER}/uvr5_weights" "${assets_dir}/uvr5_weights" +mv "${REPO_FOLDER}/pretrained" "${assets_dir}/pretrained" +mv "${REPO_FOLDER}/uvr5_weights" "${assets_dir}/uvr5_weights"