Skip to content

Commit

Permalink
create working example of using exec to create Python virtual environ…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
sebovzeoueb committed Feb 12, 2025
1 parent dd5f4e8 commit 2633786
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 72 deletions.
1 change: 1 addition & 0 deletions Dockerfile.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dev_launcher.py
# non-container files
cli
concierge_packages
bun_installer

# compose files
**/docker-compose*
1 change: 1 addition & 0 deletions Dockerfile.local.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dev_launcher.py
# non-container files
cli
concierge_packages
bun_installer

# compose files
**/docker-compose*
Expand Down
Binary file modified bun_installer/assets/docker_compose.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion bun_installer/assets/index.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ name: concierge

# this is a bit of a hack to conditionally include keycloak if we're running security, the blank compose stops Docker from complaining when doing an unsecured instance.
include:
- ./concierge_packages/installer/src/install_concierge/docker_compose/docker_compose_dependencies/${KEYCLOAK_SERVICE_FILE:-docker-compose-blank.yml}
- ./docker_compose_dependencies/${KEYCLOAK_SERVICE_FILE:-docker-compose-blank.yml}

services:
ollama:
extends:
file: concierge_packages/installer/src/install_concierge/docker_compose/docker_compose_dependencies/docker-compose-ollama.yml
file: ./docker_compose_dependencies/docker-compose-ollama.yml
service: ${OLLAMA_SERVICE:-ollama}
opensearch-node1:
extends:
file: concierge_packages/installer/src/install_concierge/docker_compose/docker_compose_dependencies/docker-compose-opensearch.yml
file: ./docker_compose_dependencies/docker-compose-opensearch.yml
service: ${OPENSEARCH_SERVICE:-opensearch-node-disable-security}

volumes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ include:
services:
concierge:
extends:
file: concierge_packages/installer/src/install_concierge/docker_compose/docker_compose_dependencies/docker-compose-concierge.yml
file: ./docker_compose_dependencies/docker-compose-concierge.yml
service: ${CONCIERGE_SERVICE:-concierge}
build:
dockerfile: Dockerfile.local
context: ../../..
dockerfile: ../../../Dockerfile.local

networks:
default:
Expand Down
6 changes: 3 additions & 3 deletions bun_installer/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ zxcvbnOptions.setOptions(options)

const password1El = document.getElementById("keycloak_password_first")! as HTMLInputElement
const password2El = document.getElementById("keycloak_password")! as HTMLInputElement
const formSubmitEl = document.getElementById("install_submit")! as HTMLButtonElement
const formSubmitEls = document.querySelectorAll(".install_button")
const loggingEls = document.querySelectorAll(".logging_element")
const loggingToggle = document.getElementById("activity_logging")! as HTMLInputElement
const formEl = document.getElementById("install_form") as HTMLFormElement
Expand All @@ -51,9 +51,9 @@ const patchFormErrors = (contents: VNodeChildren) => {
formErrors = patch(formErrors, h("div#form_errors.error", contents))
}

const enableSubmit = () => formSubmitEl.disabled = false
const enableSubmit = () => formSubmitEls.forEach(el => (el as HTMLButtonElement).disabled = false)

const disableSubmit = () => formSubmitEl.disabled = true
const disableSubmit = () => formSubmitEls.forEach(el => (el as HTMLButtonElement).disabled = true)

const checkPasswords = () => {
const password1 = password1El.value
Expand Down
17 changes: 16 additions & 1 deletion bun_installer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ import { $ } from "bun"
import streamHtml from "./server/streamHtml.js"
import { WebUILink } from "./server/webUiLink.js"
import getVersion from "./server/getVersion.js"
import { parseArgs } from "node:util"

const { values } = parseArgs({
args: Bun.argv,
options: {
'dev-mode': {
type: 'boolean',

},
},
strict: true,
allowPositionals: true,
});

const devMode = !!values['dev-mode']

const app = new Hono()

Expand Down Expand Up @@ -46,7 +61,7 @@ app.get('/', async c => {
<ExistingRemover></ExistingRemover>
<section>
<h3>Install Concierge</h3>
<InstallOptionsForm></InstallOptionsForm>
<InstallOptionsForm devMode={devMode}></InstallOptionsForm>
</section>
</> : <section>
<h3>Docker isn't running, please start it!</h3>
Expand Down
3 changes: 2 additions & 1 deletion bun_installer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
"node-forge": "^1.3.1"
},
"scripts": {
"dev": "bun run --watch index.tsx",
"dev_server": "bun run --watch index.tsx",
"dev_client": "bun build ./client/index.ts --outfile ./assets/index.js --watch",
"dev_install": "bun run build_zip && bun run build_client && bun run index.tsx --dev-mode",
"build_zip": "bun run ./build/zipDockerCompose.ts",
"build_client": "bun build ./client/index.ts --outfile ./assets/index.js --minify",
"build_win": "bun run build_zip && bun run build_client && bun build ./index.tsx --compile --target=bun-windows-x64 --outfile dist/windows/concierge",
Expand Down
6 changes: 6 additions & 0 deletions bun_installer/pythonTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { $ } from "bun"
import util from "node:util"
const exec = util.promisify(await import("node:child_process").then(child_process => child_process.exec))

await exec("python3 -m venv ..")
await $`.\\Scripts\\python -m pip install -r dev_requirements.txt`.cwd("..")
24 changes: 19 additions & 5 deletions bun_installer/server/doInstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import KcAdminClient from '@keycloak/keycloak-admin-client'
import getEnvPath from "./getEnvPath"
import * as envfile from "envfile"
import getVersion from "./getVersion"
import { platform } from "node:os"
import python from "bun_python"

const logMessage = (message: string) => {
console.log(message)
return message
}

export default async function* (options: FormData, environment = "production") {
export default async function* (options: FormData) {
const environment = options.get("dev_mode")?.toString() == "True" ? "development" : "production"
// we need the compose files to be available outside of the executable bundle so the shell can use them
const buf = await file(dockerComposeZip).arrayBuffer()
const zip = new AdmZip(Buffer.from(buf))
Expand Down Expand Up @@ -88,7 +91,7 @@ export default async function* (options: FormData, environment = "production") {
continue
}
}
yield logMessage("got Keycloak credentials")
yield logMessage("got Keycloak credentials.")
}
envs.OPENSEARCH_SERVICE = "opensearch-node-enable-security"
envs.KEYCLOAK_SERVICE_FILE = "docker-compose-keycloak.yml"
Expand All @@ -103,13 +106,24 @@ export default async function* (options: FormData, environment = "production") {
envs.CONCIERGE_VERSION = getVersion()
envs.OLLAMA_SERVICE = options.has("use_gpu") ? "ollama-gpu" : "ollama"
await updateEnv()
yield logMessage("launching Docker containers")
await $`docker compose -f ./docker_compose/docker-compose.yml up -d`
yield logMessage("launching Docker containers...")
if (environment == "development") {
await $`docker compose -f ./docker_compose/docker-compose-dev.yml up -d`
yield logMessage("configuring Python environment...")
// TODO: venv
if (platform() == 'win32') await $`.\\Scripts\\python -m pip install -r dev_requirements.txt`.cwd("..")
else await $`./bin/python -m pip install -r dev_requirements.txt`.cwd("..")
}
else await $`docker compose -f ./docker_compose/docker-compose.yml up -d`
if (securityLevel == "demo") {
yield logMessage("adding demo users")
envs.IS_SECURITY_DEMO = "True"
await updateEnv()
await $`docker exec -d concierge python -m concierge_scripts.add_keycloak_demo_users`
if (environment == "development") {
if (platform() == 'win32') await $`.\\Scripts\\python -m concierge_scripts.add_keycloak_demo_users`.cwd("..")
else await $`./bin/python -m concierge_scripts.add_keycloak_demo_users`.cwd("..")
}
else await $`docker exec -d concierge python -m concierge_scripts.add_keycloak_demo_users`
}
console.log("Installation done\n")
}
5 changes: 3 additions & 2 deletions bun_installer/server/installOptionsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import getDefaultDirectory from "./getDefaultDirectory"
import * as envfile from "envfile"
import getEnvPath from "./getEnvPath"

export const InstallOptionsForm = async () => {
export const InstallOptionsForm = async (props: {devMode: boolean}) => {
const envFile = Bun.file(getEnvPath())
const envs = await envFile.exists() && await envFile.text().then(body => envfile.parse(body))
const securityEnabled = envs && envs.CONCIERGE_SECURITY_ENABLED == "True"
Expand Down Expand Up @@ -79,7 +79,8 @@ export const InstallOptionsForm = async () => {
<div id="password_status" class="error"></div>
</fieldset>
<div id="form_errors" class="error"></div>
<button type="submit" id="install_submit">Start Installation!</button>
<button type="submit" id="install_submit" class="install_button">Start Installation!</button>
{props.devMode && <button type="submit" id="install_submit_dev" class="install_button" name="dev_mode" value="True">Install Development Configuration</button>}

</form>
)
Expand Down
3 changes: 2 additions & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ pytest-playwright~=0.6.2
nest_asyncio
-e concierge_packages/script_builder
-e concierge_packages/installer
-r local_requirements.txt
-r local_requirements.txt
-r requirements.txt
8 changes: 0 additions & 8 deletions docker-compose-launch-keycloak.yml

This file was deleted.

44 changes: 0 additions & 44 deletions docker-compose-opensearch-demo.yml

This file was deleted.

2 changes: 1 addition & 1 deletion docker-compose-zip-policy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ services:
image: javieraviles/zip
volumes:
- ./keycloak_javascript:/input
- ./concierge_packages/installer/src/install_concierge/docker_compose/docker_compose_dependencies/keycloak_javascript:/output
- ./bun_installer/build/docker_compose/docker_compose_dependencies/keycloak_javascript:/output
command: sh -c "cd /input; zip -r /output/concierge.jar ."

0 comments on commit 2633786

Please sign in to comment.