base changes

This commit is contained in:
Richard Sperry 2025-04-13 23:53:50 -07:00
parent 5521843c6e
commit df25516364
14 changed files with 334 additions and 150 deletions

View file

@ -0,0 +1,38 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose
{
"name": "Existing Docker Compose (Extend)",
// Sets the run context to one level up instead of the .devcontainer folder.
"context": "../vscode",
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerFile": "../vscode/Dockerfile",
// The optional 'workspaceFolder' property is the path VS Code should open by default when
// connected. This is typically a file mount in .devcontainer/docker-compose.yml
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}"
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Uncomment the next line if you want start specific services in your Docker Compose config.
// "runServices": [],
// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
// "shutdownAction": "none",
// Uncomment the next line to run commands after the container is created.
// "postCreateCommand": "cat /etc/os-release",
// Configure tool-specific properties.root
// "customizations": {},
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "devcontainer"
}

View file

@ -0,0 +1,26 @@
version: '3.8'
services:
# Update this to the name of the service you want to work with in your docker-compose.yml file
app:
# Uncomment if you want to override the service's Dockerfile to one in the .devcontainer
# folder. Note that the path of the Dockerfile and context is relative to the *primary*
# docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile"
# array). The sample below assumes your primary file is in the root of your project.
#
build:
context: ../vscode
dockerfile: Dockerfile
volumes:
# Update this to wherever you want VS Code to mount the folder of your project
- ..:/workspaces:cached
# Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
# cap_add:
# - SYS_PTRACE
# security_opt:
# - seccomp:unconfined
# Overrides default command so things don't shut down after the process ends.
command: sleep infinity

4
repository.yaml Normal file
View file

@ -0,0 +1,4 @@
---
name: vscode
url: https://github.com/rsperry79/addon-vscode/
maintainer: Richard Sperry <https://github.com/rsperry79/addon-vscode/>

5
todo.txt Normal file
View file

@ -0,0 +1,5 @@
cli
https://github.com/coder/code-server/blob/e3c09efcbcdfd632cbeac6044692d7ea9f493386/src/node/cli.ts#L35
conf
https://github.com/coder/code-server/blob/e3c09efcbcdfd632cbeac6044692d7ea9f493386/src/node/cli.ts#L65

View file

@ -12,128 +12,87 @@ ENV \
# Set shell
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# Copy Python requirements file
COPY requirements.txt /tmp/requirements.txt
# Copy in extensions list
COPY vscode.extensions /root/vscode.extensions
# Setup base system
ARG BUILD_ARCH=amd64
ARG CODE_SERVER_VERSION="v4.99.2"
ARG CODE_SERVER_VERSION="4.98.2"
ARG HA_CLI_VERSION="4.37.0"
# hadolint ignore=SC2181, DL3008
RUN \
apt-get update \
\
&& apt-get install -y --no-install-recommends \
ack=3.6.0-1 \
libarchive-tools=3.6.2-1+deb12u2 \
build-essential=12.9 \
colordiff=1.0.20-1 \
git=1:2.39.5-0+deb12u2 \
iputils-ping=3:20221126-1+deb12u1 \
locales=2.36-9+deb12u7 \
mariadb-client=1:10.11.11-0+deb12u1 \
mosquitto-clients=2.0.11-1.2+deb12u1 \
net-tools=2.10-0.1 \
nmap=7.93+dfsg1-1 \
openssh-client=1:9.2p1-2+deb12u5 \
openssl=3.0.15-1~deb12u1 \
python3-dev=3.11.2-1+b1 \
python3=3.11.2-1+b1 \
unzip=6.0-28 \
uuid-runtime=2.38.1-5+deb12u1 \
wget>=1.21.3-1+b2 \
zip=3.0-13 \
zsh=5.9-4+b5 \
less=590-2.1~deb12u2 \
\
&& sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \
&& locale-gen \
\
&& curl https://bootstrap.pypa.io/get-pip.py | python3 \
\
&& if [[ "${BUILD_ARCH}" = "aarch64" ]]; then ARCH="arm64"; fi \
&& if [[ "${BUILD_ARCH}" = "amd64" ]]; then ARCH="amd64"; fi \
&& curl -J -L -o /tmp/code.tar.gz \
"https://github.com/coder/code-server/releases/download/${CODE_SERVER_VERSION}/code-server-${CODE_SERVER_VERSION#v}-linux-${ARCH}.tar.gz" \
&& mkdir -p /usr/local/lib/code-server \
&& tar zxvf \
/tmp/code.tar.gz \
--strip 1 -C /usr/local/lib/code-server \
\
&& ln -s /usr/local/lib/code-server/bin/code-server /usr/local/bin/code-server \
\
&& mkdir -p /root/.code-server/extensions \
&& uuid=$(uuidgen) \
&& while read -r ext; do \
extention="${ext%%#*}" \
vendor="${extention%%.*}"; \
slug="${extention#*.}"; \
version="${ext##*#}"; \
\
echo "Installing vscode extension: ${slug} by ${vendor} @ ${version} "; \
\
echo "https://marketplace.visualstudio.com/_apis/public/gallery/publishers/${vendor}/vsextensions/${slug}/${version}/vspackage"; \
curl -JL --retry 5 -o "/tmp/${extention}-${version}.vsix" \
-H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36" \
-H "x-market-user-id: ${uuid}" \
"https://marketplace.visualstudio.com/_apis/public/gallery/publishers/${vendor}/vsextensions/${slug}/${version}/vspackage"; \
mkdir -p "/usr/local/lib/code-server/lib/vscode/extensions/${extention}-${version}"; \
bsdtar --strip-components=1 -xf "/tmp/${extention}-${version}.vsix" \
-C "/usr/local/lib/code-server/lib/vscode/extensions/${extention}-${version}" extension; \
[ $? -ne 0 ] && exit 1; \
sleep 1; \
done < /root/vscode.extensions \
&& ls -la /usr/local/lib/code-server/lib/vscode/extensions/ \
\
&& curl -L -s -o /usr/bin/ha \
"https://github.com/home-assistant/cli/releases/download/${HA_CLI_VERSION}/ha_${BUILD_ARCH}" \
&& chmod a+x /usr/bin/ha \
\
&& git clone --branch master --single-branch --depth 1 \
"https://github.com/robbyrussell/oh-my-zsh.git" ~/.oh-my-zsh \
\
&& git clone --branch master --single-branch --depth 1 \
"https://github.com/zsh-users/zsh-autosuggestions" \
~/.oh-my-zsh/custom/plugins/zsh-autosuggestions \
&& git clone --branch master --single-branch --depth 1 \
"https://github.com/zsh-users/zsh-syntax-highlighting.git" \
~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting \
\
&& sed -i -e "s#bin/bash#bin/zsh#" /etc/passwd \
\
&& update-alternatives \
--install /usr/bin/python python /usr/bin/python3 10 \
\
&& pip3 install --no-cache-dir -r /tmp/requirements.txt \
\
&& apt-get purge -y --auto-remove \
build-essential \
libarchive-tools \
python3-dev \
uuid-runtime \
\
&& find /usr/local \
\( -type d -a -name test -o -name tests -o -name '__pycache__' \) \
-o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
-exec rm -rf '{}' + \
\
&& rm -fr \
/root/.cache \
/tmp/* \
/var/{cache,log}/* \
/var/lib/apt/lists/*
# Copy root filesystem
# Install packages
# TODO: If versions are set, will either run in devcontainers or HA but not both.
# TODO: Check if all are needed
# hadolint ignore=DL3008
RUN apt-get update \
&& apt-get full-upgrade -y \
&& apt-get install -y --no-install-recommends \
ack \
libarchive-tools \
colordiff \
git \
iputils-ping \
locales \
mariadb-client \
mosquitto-clients \
net-tools=2.10-0.1 \
openssh-client \
openssl \
python3-dev \
python3 \
zsh \
unzip \
htop \
nano \
&& rm -rf /var/lib/apt/lists/*
#System configuration
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && locale-gen && \
update-locale LANG=en_US.UTF-8 && \
curl https://bootstrap.pypa.io/get-pip.py | python3
# Install code-server
WORKDIR /tmp/
RUN curl -fsSL https://code-server.dev/install.sh | sh -s -- --version ${CODE_SERVER_VERSION}
# Install Home Assistant CLI
WORKDIR /tmp/
# hadolint ignore=SC2086
RUN if [ "${BUILD_ARCH}" = "aarch64" ]; then HA_CLI_URL="https://github.com/home-assistant/cli/releases/download/${HA_CLI_VERSION}/ha_arm64"; \
elif [ "${BUILD_ARCH}" = "amd64" ]; then HA_CLI_URL="https://github.com/home-assistant/cli/releases/download/${HA_CLI_VERSION}/ha_amd64"; fi \
&& curl -J -L -o ha ${HA_CLI_URL} \
&& mv ./ha "/usr/bin/ha" \
&& chmod +x "/usr/bin/ha"
#Copy root file system
COPY rootfs /
# Install Oh My ZSH
# hadolint ignore=SC2086
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" \
&& git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions \
&& git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting \
&& sed -i -e "s#bin/bash#bin/zsh#" /etc/passwd
# Install Python packages
COPY ./requirements.txt /tmp/requirements.txt
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 10 && \
pip3 install --no-cache-dir -r /tmp/requirements.txt
# Cleanup apt cache
RUN apt-get purge -y --auto-remove \
libarchive-tools \
python3-dev
# Cleanup files
RUN find /usr/local \
\( -type d -a -name test -o -name tests -o -name '__pycache__' \) \
-o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
-exec rm -rf '{}' + && \
rm -fr /root/.cache /tmp/* /var/{cache,log}/* /var/lib/apt/lists/*
# Health check
HEALTHCHECK \
CMD curl --fail http://127.0.0.1:1337/healthz || exit 1
# Build arguments
# Build Final image
ARG BUILD_ARCH
ARG BUILD_DATE
ARG BUILD_DESCRIPTION

View file

@ -41,7 +41,7 @@ options:
packages: []
init_commands: []
schema:
log_level: list(trace|debug|info|notice|warning|error|fatal)?
log_level: list(trace|debug|info|warn|error)?
config_path: str?
packages:
- str

View file

@ -9,25 +9,25 @@ declare config_path
bashio::log.info 'Starting code-server...'
config_path="/config"
if bashio::config.has_value 'config_path'; then
config_path=$(bashio::config 'config_path')
fi
options+=(--config="$CODE_SERVER_CONFIG_PATH/config.yaml")
# options+=(--user-data-dir="$CODE_SERVER_CONFIG_PATH/User")
# options+=(--extensions-dir="$CODE_SERVER_CONFIG_PATH/extensions")
options+=(--port 1337)
options+=(--user-data-dir "/data/vscode")
options+=(--extensions-dir "/data/vscode/extensions")
options+=(--host 0.0.0.0)
options+=(--disable-telemetry)
options+=(--disable-update-check)
# options+=(--disable-telemetry)
# options+=(--disable-update-check)
# options+=(--disable-getting-started-override)
# options+=(--auth none)
config
# Disable code authentication, we use HA authentication
options+=(--auth none)
options+=(--disable-workspace-trust)
# Export env variables for the Home Assistant extension
export HASS_SERVER="http://supervisor/core"
export HASS_TOKEN="${SUPERVISOR_TOKEN:-}"
# Run the code server
cd "${config_path}" || bashio::exit.nok "Could not change working directory"
exec code-server "${options[@]}" "${config_path}"
cd "${CODE_SERVER_CONFIG_PATH}" || bashio::exit.nok "Could not change working directory"
exec code-server "${options[@]}" "/config"

View file

@ -5,6 +5,7 @@
# Sets up code-server.
# ==============================================================================
declare config_path
bashio::log.info "Initalizing code-server configs"
# List of previous config hashes, to allow upgrade "default" configs.
readonly -a PREVIOUS_DEFAULT_CONFIG_HASHES=(
@ -23,39 +24,75 @@ readonly -a PREVIOUS_DEFAULT_CONFIG_HASHES=(
2212babaa9dc46d38ba239052c9c05151abe517cc8b493d0d351a96bf70c1efa4f7479f6ed0b75811429ba649906eb5657d73b0732b460e718a5c66603dcdbda
)
readonly DEFAULT_FILES_PATH="/usr/lib/code-server/defaults"
readonly DEFAULT_CONFIG_PATH="/config/addons_config/vscode"
# Ensure config path exists
if bashio::config.has_value 'config_path'; then
# If a path is set in HA, then try or fail addon start
config_path=$(bashio::config 'config_path')
if ! bashio::fs.directory_exists "${config_path}"; then
bashio::exit.nok "Configured config path does not exists"
fi
fi
# Ensure persistent data folder exists.
if ! bashio::fs.directory_exists '/data/vscode'; then
mkdir -p /data/vscode/extensions \
else
# otherwise set to local dir
config_path="$DEFAULT_CONFIG_PATH"
if ! bashio::fs.directory_exists "$config_path"; then
bashio::log.info "Config path did not exist, createing $config_path"
mkdir -p $config_path \
|| bashio::exit.nok "Could not create persistent storage folder."
fi
# Clean up copies of extensions we deliver from the persistent storage
while read -r ext; do
extension="${ext%%#*}"
# shellcheck disable=SC2086
rm -f -r /data/vscode/extensions/${extension,,}*
done < /root/vscode.extensions
export CODE_SERVER_CONFIG_PATH=$config_path
bashio::log.info "using code-server config path: $config_path"
# Ensure user extensions folder exists
mkdir -p /data/vscode/extensions
# Ensure code-server config
if ! bashio::fs.file_exists $config_path/config.yaml; then
cp "$DEFAULT_FILES_PATH/config.yaml" "$config_path/config.yaml"
fi
if bashio::config.has_value 'log_level'; then
sed -i "/log_level=/c log_level=\"$log_level\"" "$config_path/config.yaml"
fi
# Ensure extensions path
ext_path="$config_path/extensions"
if [ ! -d "$ext_path" ]; then
mkdir -p $ext_path \
|| bashio::exit.nok "Could not create persistent extensions folder."
# Only do this on folder create so users can remove faulty extentions.
# Install code-server extensions via code-server so terminate is aware of them.
while read -r extention; do
if [ ! -e $ext_path/$extention* ]; then
code-server --install-extension="$extention" --extensions-dir="$ext_path" --user-data-dir "$config_path";
fi;
done < "$DEFAULT_FILES_PATH/vscode.extensions"
fi
sed -i "/extensions-dir=/c extensions-dir=\"$ext_path\"" "$config_path/config.yaml"
# Ensure User settings path
user_path="$config_path/user"
if [ ! -d "$user_path" ]; then
mkdir -p $user_path \
|| bashio::exit.nok "Could not create persistent User folder."
fi
sed -i "/user-data-dir=/c user-data-dir=\"$user_path\"" "$config_path/config.yaml"
# Sets up default user settings on first start.
if ! bashio::fs.file_exists '/data/vscode/User/settings.json'; then
mkdir -p /data/vscode/User \
|| bashio::exit.nok "Could not create persistent storage folder."
if ! bashio::fs.file_exists $user_path/settings.json; then
cp "$DEFAULT_FILES_PATH/settings.json" "$user_path/settings.json"
else
# Upgrade if settings.json is still default from previous version.
current=$(sha512sum $user_path/settings.json|cut -d " " -f 1)
if [[ " ${PREVIOUS_DEFAULT_CONFIG_HASHES[*]} " == *" ${current} "* ]]; then
cp /root/.code-server/settings.json /data/vscode/User/settings.json
cp "$DEFAULT_FILES_PATH/settings.json" "$user_path/settings.json"
fi
fi
# Upgrade settings.json is still default from previous version.
current=$(sha512sum /data/vscode/User/settings.json|cut -d " " -f 1)
if [[ " ${PREVIOUS_DEFAULT_CONFIG_HASHES[*]} " == *" ${current} "* ]]; then
cp /root/.code-server/settings.json /data/vscode/User/settings.json
if ! bashio::fs.file_exists $user_path/workspaces.json; then
cp "$DEFAULT_FILES_PATH/workspaces.json" "$user_path/workspaces.json"
fi

View file

@ -0,0 +1,3 @@
#!/bin/sh
exec /usr/local/lib/code-server/bin/code-server --config="$CODE_SERVER_CONFIG_PATH/config.yaml" "${@}"

View file

@ -0,0 +1,10 @@
bind-addr: 0.0.0.0
port: 1337
auth: none
cert: false
disable-getting-started-override: true
disable-update-check: true
disable-telemetry: true
log_level: warn
user-data-dir: /data/vscode/user
extensions-dir: /data/vscode/extentions

View file

@ -0,0 +1,99 @@
{
"files.associations": {
"*.dash": "yaml",
"**/esphome/*.yaml": "esphome",
"**/esphome/**/*.yaml": "esphome",
"*.yaml": "home-assistant"
},
"files.watcherExclude": {
".nfs**": true,
".Trash-0/**": true,
"**/__pycache__/**": true,
"**/._*": true,
"**/.cloud": true,
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
"**/.HA_VERSION": true,
"**/.storage": true,
"**/*.db-shm": true,
"**/*.db-wal": true,
"**/*.db": true,
"**/*.log": true,
"**/deps/**": true,
"**/node_modules": true,
"**/OZW_Log.txt": true,
"**/pyozw.sqlite": true
},
"search.exclude": {
".Trash-0/**": true,
"**/__pycache__/**": true,
"**/._*": true,
"**/.cloud": true,
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
"**/.git": true,
"**/.HA_VERSION": true,
"**/.storage": true,
"**/*.db-shm": true,
"**/*.db-wal": true,
"**/*.db": true,
"**/*.log": true,
"**/deps/**": true,
"**/node_modules": true,
"**/OZW_Log.txt": true,
"**/pyozw.sqlite": true
},
"files.exclude": {
".Trash-0/**": true,
"**/__pycache__": true,
"**/.cloud": true,
"**/.DS_Store": true,
"**/.git": true,
"**/.HA_VERSION": true,
"**/.storage": true,
"**/*.db-shm": true,
"**/*.db-wal": true,
"**/*.db": true,
"**/deps/**": true,
"**/node_modules": true
},
"yaml.customTags": [
"!env_var scalar",
"!include_dir_list scalar",
"!include_dir_merge_list scalar",
"!include_dir_merge_named scalar",
"!include_dir_named scalar",
"!include scalar",
"!secret scalar"
],
"[yaml]": {
"editor.autoIndent": "full",
"editor.insertSpaces": true,
"editor.tabSize": 2,
"editor.quickSuggestions": {
"other": true,
"comments": false,
"strings": true
}
},
"[home-assistant]": {
"editor.autoIndent": "full",
"editor.insertSpaces": true,
"editor.tabSize": 2,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.formatOnPaste": true
},
"editor.renderWhitespace": "boundary",
"esphome.validator": "local",
"telemetry.enableTelemetry": false,
"terminal.integrated.copyOnSelection": true,
"terminal.integrated.shell.linux": "/usr/bin/zsh",
"update.mode": "none",
"vsicons.dontShowNewVersionMessage": true,
"vsicons.projectDetection.disableDetect": true,
"workbench.iconTheme": "vs-seti",
"yaml.format.enable": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.rulers": [80, 88, 100, 120]
}

View file

@ -0,0 +1,6 @@
{
"rootWorkspaces": [],
"folderURIWorkspaces": [],
"emptyWorkspaceInfos": [],
"emptyWorkspaces": []
}

View file

@ -1,3 +0,0 @@
#!/bin/sh
exec /usr/local/lib/code-server/bin/code-server "${@}"