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

Make different run environments more flexible #7

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
8 changes: 6 additions & 2 deletions digital_alchemy/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
ARG BUILD_FROM
FROM $BUILD_FROM

COPY install.sh /
RUN /install.sh
COPY --from=node:22-alpine /usr/local/bin /usr/local/bin
COPY --from=node:22-alpine /usr/local/lib/node_modules /usr/local/lib/node_modules
COPY --from=oven/bun:alpine /usr/local/bin /usr/local/bin

RUN rm -f /usr/local/bin/yarn /usr/local/bin/yarnpkg \
&& npm i -g yarn

# Copy data for add-on
COPY run.sh /
Expand Down
6 changes: 2 additions & 4 deletions digital_alchemy/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ arch:

options:
app_root: /share/digital_alchemy
main: src/main.ts
node_env: production
run_mode: tsx
environment: node_npm
packages: []

schema:
app_root: str
main: str
node_env: str
run_mode: list(node|tsx|bun)
environment: list(node_npm|node_yarn|bun|deno)
packages:
- str

Expand Down
30 changes: 0 additions & 30 deletions digital_alchemy/install.sh

This file was deleted.

58 changes: 35 additions & 23 deletions digital_alchemy/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,50 @@ if bashio::config.has_value 'packages'; then
done
fi


# Fetch configuration options
APP_ROOT=$(bashio::config 'app_root')
APP_MAIN=$(bashio::config 'main')
RUN_MODE=$(bashio::config 'run_mode')
ENVIRONMENT=$(bashio::config 'environment')

function prepareStart() {
if [[ -z $(jq -r '.scripts.start // empty' 'package.json') ]]; then
bashio::exit.nok "No start script found in package.json"
fi

PACKAGE_NAME=$(jq -r '.name' package.json)
bashio::log.info "Starting ${PACKAGE_NAME}..."
}

# Navigate to the app root
cd "${APP_ROOT}" || bashio::exit.nok "Could not navigate to application root: ${APP_ROOT}"
# Validate package.json exists
if [[ ! -f "package.json" ]]; then
bashio::exit.nok "package.json not found in APP_ROOT:'${APP_ROOT}'"
bashio::exit.nok "package.json not found in APP_ROOT: '${APP_ROOT}'"
fi

if [[ "${RUN_MODE}" == "bun" ]]; then
# npm install -g bun
bun --version
bun install
bun run "$APP_MAIN"
else
corepack enable && corepack prepare yarn@stable --activate
yarn config set compressionLevel mixed
yarn config set nodeLinker node-modules
yarn install

# Extract package name from package.json
PACKAGE_NAME=$(jq -r '.name' package.json)
bashio::log.info "Starting ${PACKAGE_NAME}..."

# Check run_mode and execute the corresponding command
if [[ "${RUN_MODE}" == "tsx" ]]; then
npx tsx "$APP_MAIN"
if [[ "${ENVIRONMENT}" == "node_npm" ]]; then
bashio::log.info "Installing dependencies..."
if [[ -f "package-lock.json" ]]; then
npm ci
else
node "$APP_MAIN"
npm install
fi

prepareStart
bashio::log.info " ...running npm start"

npm start
elif [[ "${ENVIRONMENT}" == "node_yarn" ]]; then
bashio::log.info "Installing dependencies..."
yarn install

prepareStart
bashio::log.info " ...running yarn start"
yarn start
elif [[ "${ENVIRONMENT}" == "bun" ]]; then
bashio::log.info "Installing dependencies..."
bun install --frozen-lockfile --production

prepareStart
bashio::log.info " ...running bun run start"
bun run start
fi