diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..f94ce74b --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +VITE_STABILITY_APIKEY="sk-....." +APP_PORT=3000 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6abb6421..78287d58 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ node_modules !.yarn/releases !.yarn/sdks !.yarn/versions +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..5544b5e2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +# this can be updated to use a smaller image, customize build steps&stages, etc +FROM node:latest +ENV APP_PORT=3000 +WORKDIR /usr/src/app +COPY package.json yarn.lock ./ +COPY . . +RUN yarn +RUN echo "cachebust_1" +EXPOSE $APP_PORT +CMD ["yarn", "dev"] diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000..9795f72b --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,17 @@ +version: '3.9' +services: + app: + platform: linux/x86_64 + container_name: StableStudio + env_file: .env + restart: always + build: . + ports: + - 3000:3000 + stdin_open: true + tty: true + volumes: + - .:/usr/src/app + - /usr/src/app/.yarn + - /usr/src/app/.husky + - /usr/src/app/node_modules \ No newline at end of file diff --git a/package.json b/package.json index 52302fc8..91e50b36 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "packages/*" ] }, + "private": true, "scripts": { "postinstall": "node -e \"try { require('husky').install() } catch (e) {if (e.code !== 'MODULE_NOT_FOUND') throw e}\" && yarn build", "stablestudio-plugin": "yarn workspace @stability/stablestudio-plugin", @@ -16,7 +17,7 @@ "stablestudio-ui": "yarn workspace @stability/stablestudio-ui", "dev:use-example-plugin": "cross-env VITE_USE_EXAMPLE_PLUGIN=true yarn dev", "dev": "yarn workspaces foreach --all --interlaced --verbose --parallel --jobs unlimited run dev", - "build": "yarn workspaces foreach --all --interlaced --verbose --jobs unlimited run build", + "build": "yarn plugin import workspace-tools && yarn workspaces foreach --all --interlaced --verbose --jobs unlimited run build", "clean": "yarn workspaces foreach --all --interlaced --verbose --parallel --jobs unlimited run clean && rimraf node_modules" }, "devDependencies": { diff --git a/packages/stablestudio-plugin-stability/src/index.ts b/packages/stablestudio-plugin-stability/src/index.ts index c71ba7fe..008dd3ad 100644 --- a/packages/stablestudio-plugin-stability/src/index.ts +++ b/packages/stablestudio-plugin-stability/src/index.ts @@ -11,6 +11,19 @@ import { Struct, } from "./Proto"; +const setApiKeyFromEnvVar = () => { + const envApiKey = import.meta.env.VITE_STABILITY_APIKEY; + + const localStorageApiKey = localStorage.getItem("stability-apiKey"); + if (localStorageApiKey) return localStorageApiKey; + + if (envApiKey) { + localStorage.setItem("stability-apiKey", envApiKey); + return envApiKey; + } + +}; + const getStableDiffusionDefaultCount = () => 4; const getStableDiffusionDefaultInputFromPrompt = (prompt: string) => ({ prompts: [ @@ -50,7 +63,13 @@ export const createPlugin = StableStudio.createPlugin<{ | "deleteStableDiffusionImages" | "getStatus" > => { + + apiKey = setApiKeyFromEnvVar() || apiKey; + if (!apiKey) + + + return { createStableDiffusionImages: undefined, getStableDiffusionExistingImages: undefined, @@ -427,7 +446,7 @@ export const createPlugin = StableStudio.createPlugin<{ }), }; }; - + return { ...functionsWhichNeedAPIKey( localStorage.getItem("stability-apiKey") ?? undefined @@ -533,7 +552,6 @@ export const createPlugin = StableStudio.createPlugin<{ placeholder: "sk-...", required: true, password: true, - value: localStorage.getItem("stability-apiKey") ?? "", }, }, diff --git a/packages/stablestudio-ui/index.html b/packages/stablestudio-ui/index.html index 5b7614d6..b02805be 100644 --- a/packages/stablestudio-ui/index.html +++ b/packages/stablestudio-ui/index.html @@ -24,6 +24,6 @@
- +