diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..84da32c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.git +.gitea +.angular +node_modules +frontend/dist +data +*.log diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 83ffb88..0f2d092 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -15,7 +15,10 @@ jobs: DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} DEPLOY_USER: ${{ secrets.DEPLOY_USER }} DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }} + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} + REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} GITEA_REF: ${{ gitea.ref }} + GITEA_SHA: ${{ gitea.sha }} run: | set -Eeuo pipefail mkdir -p ~/.ssh @@ -29,17 +32,34 @@ jobs: *) exit 0 ;; esac REPO_URL=ssh://git@git.dumas.ddns.net:222/chris.dumas/ComfyUiPortalNext.git + IMAGE_REF=git.dumas.ddns.net/chris.dumas/comfyui-portal-next:sha-${GITEA_SHA} + + if [ -z "$REGISTRY_USERNAME" ] || [ -z "$REGISTRY_PASSWORD" ]; then + echo 'REGISTRY_USERNAME and REGISTRY_PASSWORD are required Gitea secrets' + exit 1 + fi + + printf '%s' "$REGISTRY_PASSWORD" | ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=yes "${DEPLOY_USER}@${DEPLOY_HOST}" "docker login git.dumas.ddns.net --username '$REGISTRY_USERNAME' --password-stdin" + ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=yes "${DEPLOY_USER}@${DEPLOY_HOST}" " set -Eeuo pipefail + trap 'docker logout git.dumas.ddns.net >/dev/null 2>&1 || true' EXIT mkdir -p '$TARGET_DIR' if [ ! -d '$TARGET_DIR/.git' ]; then git init '$TARGET_DIR' && cd '$TARGET_DIR' && git remote add origin '$REPO_URL'; else cd '$TARGET_DIR' && git remote set-url origin '$REPO_URL'; fi cd '$TARGET_DIR' GIT_SSH_COMMAND='ssh -p 222 -o StrictHostKeyChecking=no' git fetch origin '$BRANCH' git reset --hard 'origin/$BRANCH' git clean -fdx -e data/ -e data/** + if ! docker manifest inspect '$IMAGE_REF' >/dev/null 2>&1; then + docker build --tag '$IMAGE_REF' . + docker push '$IMAGE_REF' + else + echo 'Reusing existing immutable image $IMAGE_REF' + fi docker ps -q --filter publish=$PORT | xargs -r docker rm -f docker compose -p '$PROJECT' -f docker-compose.yml -f '$COMPOSE_FILE' down --remove-orphans || true - docker compose -p '$PROJECT' -f docker-compose.yml -f '$COMPOSE_FILE' up -d --build + IMAGE_REF='$IMAGE_REF' docker compose -p '$PROJECT' -f docker-compose.yml -f '$COMPOSE_FILE' pull + IMAGE_REF='$IMAGE_REF' docker compose -p '$PROJECT' -f docker-compose.yml -f '$COMPOSE_FILE' up -d " for attempt in 1 2 3 4 5 6; do curl --fail --silent --show-error --max-time 15 "$HEALTH_URL/api/health" && exit 0 || sleep 5; done exit 1 diff --git a/README.md b/README.md index 6d439d8..ae69dd7 100644 --- a/README.md +++ b/README.md @@ -14,3 +14,5 @@ The first run seeds `data/users.json` from `ADMIN_USERNAME` and `ADMIN_PASSWORD` ## Deployment Gitea Actions deploys `develop`, `qa`, and `main` to the existing ComfyUiPortal target directories and preserves the existing 7002/6002/5002 port contract. On first startup of a fresh data directory, provide `ADMIN_USERNAME` and `ADMIN_PASSWORD` in the deployment host environment. Existing target data is retained during repository cutover. + +The deployment workflow builds an immutable image tagged with the source commit SHA and publishes it to the Gitea container registry. If that SHA-tagged image already exists, the workflow reuses it instead of rebuilding. Configure `REGISTRY_USERNAME` and `REGISTRY_PASSWORD` as Gitea Actions secrets. Compose receives the exact image reference through `IMAGE_REF`, so the same artifact can be redeployed or promoted without rebuilding. diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index af3c374..af84a54 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -1,9 +1,11 @@ services: app: - container_name: comfy-uiportal-dev + container_name: comfy-uiportal-next-dev environment: PORT: 7002 BRANCH_NAME: develop APP_DATA_DIR: /mnt/appdata/dev/ComfyUiPortal/data + ADMIN_USERNAME: ${ADMIN_USERNAME:-} + ADMIN_PASSWORD: ${ADMIN_PASSWORD:-} ports: - "7002:7002" diff --git a/docker-compose.yml b/docker-compose.yml index 2ab9e45..1329d85 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,6 @@ services: app: - build: . - image: comfy-uiportal:${BRANCH_NAME:-main} + image: ${IMAGE_REF:-git.dumas.ddns.net/chris.dumas/comfyui-portal-next:latest} restart: unless-stopped volumes: - ${APP_DATA_DIR:-./data}:/app/data