Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker with env #58

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_STABILITY_APIKEY="sk-....."
APP_PORT=3000
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ node_modules
!.yarn/releases
!.yarn/sdks
!.yarn/versions
.env
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
17 changes: 17 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
22 changes: 20 additions & 2 deletions packages/stablestudio-plugin-stability/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -50,7 +63,13 @@ export const createPlugin = StableStudio.createPlugin<{
| "deleteStableDiffusionImages"
| "getStatus"
> => {

apiKey = setApiKeyFromEnvVar() || apiKey;

if (!apiKey)



return {
createStableDiffusionImages: undefined,
getStableDiffusionExistingImages: undefined,
Expand Down Expand Up @@ -427,7 +446,7 @@ export const createPlugin = StableStudio.createPlugin<{
}),
};
};

return {
...functionsWhichNeedAPIKey(
localStorage.getItem("stability-apiKey") ?? undefined
Expand Down Expand Up @@ -533,7 +552,6 @@ export const createPlugin = StableStudio.createPlugin<{
placeholder: "sk-...",
required: true,
password: true,

value: localStorage.getItem("stability-apiKey") ?? "",
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/stablestudio-ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
<div id="modal-root" class="dark overflow-hidden text-white"></div>
<div id="app" class="dark"></div>

<script type="module" src="/src/index.tsx"></script>
<script type="module" src="./src/index.tsx"></script>
</body>
</html>
2 changes: 2 additions & 0 deletions packages/stablestudio-ui/src/Environment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ declare global {
interface ImportMetaEnv {
readonly VITE_GIT_HASH: string;
readonly VITE_USE_EXAMPLE_PLUGIN: string;
readonly VITE_STABILITY_APIKEY: string;
}
}

Expand All @@ -20,6 +21,7 @@ export namespace Environment {
const variables = {
VITE_GIT_HASH: import.meta.env.VITE_GIT_HASH,
VITE_USE_EXAMPLE_PLUGIN: import.meta.env.VITE_USE_EXAMPLE_PLUGIN ?? "false",
VITE_STABILITY_APIKEY: import.meta.env.VITE_STABILITY_APIKEY,
} as const;

export function get(name: VariableName): string {
Expand Down
1 change: 1 addition & 0 deletions packages/stablestudio-ui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default defineConfig(({ mode }) => {
server: {
port: 3000,
fs: { strict: false },
host:'0.0.0.0',
},

optimizeDeps: {
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"target": "ESNext",
"types": ["vite/client"],
"lib": ["DOM", "DOM.Iterable", "ESNext"],

"esModuleInterop": true,
Expand Down