From d7999a5544075fcc6492511e0133675d4b34ae31 Mon Sep 17 00:00:00 2001 From: webcoderz <19884161+webcoderz@users.noreply.github.com> Date: Fri, 17 Nov 2023 10:55:51 -0500 Subject: [PATCH] adding build system --- .github/workflows/build.yaml | 57 ++++++++++++++++++++++++++++++++++++ build/docker-bake.hcl | 24 +++++++++++++++ build/sd.Dockerfile | 54 ++++++++++++++++++++++++++++++++++ build/vars/BUILD_TAG | 1 + build/vars/REGISTRY | 1 + 5 files changed, 137 insertions(+) create mode 100644 .github/workflows/build.yaml create mode 100644 build/docker-bake.hcl create mode 100644 build/sd.Dockerfile create mode 100644 build/vars/BUILD_TAG create mode 100644 build/vars/REGISTRY diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 00000000000..bdac41941cb --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,57 @@ +name: Deploy Images to GHCR + + + +on: + pull_request: + types: [labeled] + +jobs: + cancel_outstanding: + name: Detect and cancel outstanding runs of this workflow + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Cancel Previous Runs + if: ${{ (github.event.label.name == 'release') && !contains(github.event.pull_request.labels.*.name, 'skip-cancel') }} + uses: styfle/cancel-workflow-action@0.11.0 + with: + access_token: ${{ secrets.GITHUB_TOKEN }} + + + push-store-image: + permissions: write-all + runs-on: ubuntu-latest + if: ${{ (github.event.label.name == 'release' ) && !contains(github.event.pull_request.labels.*.name, 'skip-cancel') }} + steps: + - name: 'Checkout GitHub Action' + uses: actions/checkout@main + - name: envvars + run: | + echo "RELEASE=$(cat build/vars/BUILD_TAG)" >> $GITHUB_ENV + echo "REGISTRY=$(cat build/vars/REGISTRY)" >> $GITHUB_ENV + + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + + - name: free space + run: | + bash .github/workflows/freespace.sh + ##https://github.com/orgs/community/discussions/25678 + - name: 'free up space' + + run: | + rm -rf /opt/hostedtoolcache + + - name: 'Build sd-web-ui image' + run: | + cd build && \ + RELEASE=${{ env.RELEASE }} \ + REGISTRY=${{ env.REGISTRY }} \ + docker buildx bake sd-web-ui -f docker-bake.hcl --push diff --git a/build/docker-bake.hcl b/build/docker-bake.hcl new file mode 100644 index 00000000000..5646e08e787 --- /dev/null +++ b/build/docker-bake.hcl @@ -0,0 +1,24 @@ + +variable "RELEASE" { + default = "v1.0.0" +} + +variable "REGISTRY" { + default = "" +} + +group "default" { + targets = ["sd-web-ui"] +} + +target "sd-web-ui" { + dockerfile = "sd.Dockerfile" + tags = ["${REGISTRY}${target.sd-web-ui.name}:${RELEASE}"] + context = "." + labels = { + "org.opencontainers.image.source" = "https://github.com/webcoderz/stable-diffusion-webui" + } +} + + +#RELEASE=$(cat build/vars/BUILD_TAG) REGISTRY=$(cat build/vars/REGISTRY) docker buildx bake --print \ No newline at end of file diff --git a/build/sd.Dockerfile b/build/sd.Dockerfile new file mode 100644 index 00000000000..d5183f227a1 --- /dev/null +++ b/build/sd.Dockerfile @@ -0,0 +1,54 @@ +FROM nvidia/cuda:12.2.0-base-ubuntu22.04 +ENV DEBIAN_FRONTEND noninteractive +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + + +ENV DEBIAN_FRONTEND noninteractive +RUN apt-get update -y \ + && apt-get upgrade -y \ + && apt-get install -y --no-install-recommends \ + curl \ + git \ + git-lfs \ + python3.10 \ + python3.10-venv \ + python3-pip \ + libgl1 \ + libglib2.0-0 +RUN apt-get clean -y && rm -rf /var/lib/apt/lists/* + +# user and workdir +RUN useradd -m user +RUN mkdir /work && chown -R user:user /work +USER user +WORKDIR /work + + +################################ +# setup +################################ + +RUN git clone https://github.com/webcoderz/stable-diffusion-webui.git +WORKDIR /work/stable-diffusion-webui + + + +# setup +RUN python3 -mvenv venv && /work/stable-diffusion-webui/venv/bin/python -c "from launch import *; prepare_environment()" --skip-torch-cuda-test --no-download-sd-model + + + +################################ +# entrypoint +################################ + + + + +EXPOSE 7860 +EXPOSE 8000 +EXPOSE 8265 +EXPOSE 6388 +EXPOSE 10001 + +CMD ["./webui.sh", "--xformers --cors-allow-origins=* --api"] \ No newline at end of file diff --git a/build/vars/BUILD_TAG b/build/vars/BUILD_TAG new file mode 100644 index 00000000000..95e94cdd37f --- /dev/null +++ b/build/vars/BUILD_TAG @@ -0,0 +1 @@ +v0.0.1 \ No newline at end of file diff --git a/build/vars/REGISTRY b/build/vars/REGISTRY new file mode 100644 index 00000000000..bfda55613df --- /dev/null +++ b/build/vars/REGISTRY @@ -0,0 +1 @@ +ghcr.io/webcoderz/stable-diffusion-webui/ \ No newline at end of file