feat: various modifications
- Default ubuntu user is removed - Can add apt packages during image building with --apt-packages="list of pkg" - Remove and/or prune podman image option - Fix condition checks
This commit is contained in:
+10
-4
@@ -6,6 +6,8 @@ FROM ubuntu:${UBUNTU_VERSION}
|
||||
ARG NODE_VERSION=24.21.0
|
||||
ARG OPENCODE_VERSION=2.0.3
|
||||
|
||||
ARG EXTRA_APT_PACKAGES=""
|
||||
|
||||
ARG DEV_UID=1000
|
||||
ARG DEV_GID=1000
|
||||
|
||||
@@ -49,16 +51,22 @@ RUN apt-get update \
|
||||
zip \
|
||||
&& update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java \
|
||||
&& update-alternatives --set javac /usr/lib/jvm/java-17-openjdk-amd64/bin/javac \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen \
|
||||
&& locale-gen \
|
||||
&& ln -s "$(command -v fdfind)" /usr/local/bin/fd
|
||||
|
||||
RUN if [ -n "${EXTRA_APT_PACKAGES}" ]; then \
|
||||
echo "Installing extra packages: ${EXTRA_APT_PACKAGES}" \
|
||||
&& apt-get install -y --no-install-recommends ${EXTRA_APT_PACKAGES}; \
|
||||
fi
|
||||
|
||||
RUN rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY ./certs /usr/local/share/ca-certificates
|
||||
RUN update-ca-certificates
|
||||
ENV NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt
|
||||
|
||||
# Remove ubuntu user and create the dev one
|
||||
# Remove ubuntu user and create the dev one with host uid and gid
|
||||
RUN (userdel -r ubuntu 2>/dev/null || true) \
|
||||
&& (groupdel ubuntu 2>/dev/null || true) \
|
||||
&& groupadd --gid "${DEV_GID}" dev \
|
||||
@@ -100,6 +108,4 @@ ENV HOME=/home/dev \
|
||||
|
||||
WORKDIR /workspace
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/opencode-dev-entrypoint"]
|
||||
|
||||
CMD ["bash"]
|
||||
|
||||
@@ -6,33 +6,58 @@ cd "$SCRIPT_DIR"
|
||||
|
||||
UBUNTU_VERSION="${UBUNTU_VERSION:-26.04}"
|
||||
NODE_VERSION="${NODE_VERSION:-24.21.0}"
|
||||
OPENCODE_VERSION="${OPENCODE_VERSION:-2.0.3}"
|
||||
OPENCODE_VERSION="${OPENCODE_VERSION:-2.0.22}"
|
||||
IMAGE="${IMAGE_REPO:-localhost/opencode-dev}"
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 [--no-cache] [--update] [--dry-run]"
|
||||
echo 'Usage: $0 [--no-cache] [--update] [--dry-run] [--remove] [--prune] [--apt-packages="pack1 pack2"]'
|
||||
exit 2
|
||||
}
|
||||
|
||||
BUILD_OPTS=()
|
||||
DRY_RUN=0
|
||||
REMOVE=0
|
||||
PRUNE=0
|
||||
# EXTRA_APT_PACKAGES="${EXTRA_APT_PACKAGES:-}"
|
||||
EXTRA_APT_PACKAGES=()
|
||||
|
||||
while (($#)); do
|
||||
case "$1" in
|
||||
--no-cache) BUILD_OPTS+=(--no-cache) ;;
|
||||
--update) BUILD_OPTS+=(--no-cache --pull=newer) ;;
|
||||
--dry-run) DRY_RUN=1 ;;
|
||||
--remove) REMOVE=1 ;;
|
||||
--prune) PRUNE=1 ;;
|
||||
--apt-packages=*)
|
||||
read -ra _pkgs <<< "${1#*=}"
|
||||
EXTRA_APT_PACKAGES="${_pkgs[@]}" ;;
|
||||
-h|--help) usage ;;
|
||||
*) echo "Unknown option: $1" >&2; usage ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [[ -n "${EXTRA_APT_PACKAGES[@]}" ]]; then
|
||||
echo "--> Apt extra pkg: ${EXTRA_APT_PACKAGES[*]}"
|
||||
fi
|
||||
|
||||
if ((REMOVE || PRUNE)); then
|
||||
if ((REMOVE)); then
|
||||
podman image rm "${IMAGE}" 2>/dev/null
|
||||
fi
|
||||
if ((PRUNE)); then
|
||||
podman image prune -f 2>/dev/null
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
CMD=(
|
||||
podman build
|
||||
"${BUILD_OPTS[@]}"
|
||||
--build-arg "UBUNTU_VERSION=${UBUNTU_VERSION}"
|
||||
--build-arg "NODE_VERSION=${NODE_VERSION}"
|
||||
--build-arg "OPENCODE_VERSION=${OPENCODE_VERSION}"
|
||||
--build-arg "EXTRA_APT_PACKAGES=${EXTRA_APT_PACKAGES[*]}"
|
||||
--build-arg "DEV_UID=$(id -u)"
|
||||
--build-arg "DEV_GID=$(id -g)"
|
||||
-t "$IMAGE"
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
# CERT_DIR="${CERT_DIR:-/host-certs}"
|
||||
#
|
||||
# if [[ -d "$CERT_DIR" ]]; then
|
||||
# shopt -s nullglob
|
||||
# certs=("$CERT_DIR"/*.crt "$CERT_DIR"/*.pem)
|
||||
# if ((${#certs[@]})); then
|
||||
# mkdir -p /usr/local/share/ca-certificates/opencode-host
|
||||
# for cert in "${certs[@]}"; do
|
||||
# target="/usr/local/share/ca-certificates/opencode-host/$(basename "${cert%.*}").crt"
|
||||
# if openssl x509 -in "$cert" -noout >/dev/null 2>&1; then
|
||||
# cp -f "$cert" "$target"
|
||||
# else
|
||||
# echo "WARNING: ignoring invalid CA certificate: $cert" >&2
|
||||
# fi
|
||||
# done
|
||||
# if update-ca-certificates >/tmp/opencode-ca.log 2>&1; then
|
||||
# :
|
||||
# else
|
||||
# echo "WARNING: update-ca-certificates failed; continuing." >&2
|
||||
# cat /tmp/opencode-ca.log >&2 || true
|
||||
# fi
|
||||
# fi
|
||||
# fi
|
||||
|
||||
host_lang="${HOST_LANG:-${LANG:-C.UTF-8}}"
|
||||
host_lc_all="${HOST_LC_ALL:-${LC_ALL:-}}"
|
||||
|
||||
# Generate a host locale when it is a valid UTF-8 locale and not already present.
|
||||
if [[ "$host_lang" == *.UTF-8 && "$host_lang" != "C.UTF-8" ]]; then
|
||||
if ! locale -a | grep -Fxqi "${host_lang//UTF-8/utf8}"; then
|
||||
if [[ "$host_lang" =~ ^([A-Za-z_]+)\.UTF-8$ ]]; then
|
||||
locale_name="${BASH_REMATCH[1]}.UTF-8"
|
||||
if grep -qE "^#?[[:space:]]*${locale_name}[[:space:]]+UTF-8" /etc/locale.gen 2>/dev/null; then
|
||||
sed -i -E "s/^#[[:space:]]*(${locale_name}[[:space:]]+UTF-8)/\1/" /etc/locale.gen
|
||||
else
|
||||
printf '%s UTF-8\n' "$locale_name" >> /etc/locale.gen
|
||||
fi
|
||||
locale-gen "$locale_name" >/dev/null 2>&1 || \
|
||||
echo "WARNING: could not generate locale $host_lang; continuing." >&2
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
export LANG="$host_lang"
|
||||
if [[ -n "$host_lc_all" ]]; then
|
||||
export LC_ALL="$host_lc_all"
|
||||
fi
|
||||
|
||||
# exec su -s /bin/bash dev -c 'cd "${START_DIR:-/workspace}" && exec "$@"' -- "$@"
|
||||
cd "${START_DIR:-/workspace}"
|
||||
exec "$@"
|
||||
+2
-5
@@ -64,8 +64,6 @@ ARGS=(
|
||||
--security-opt=no-new-privileges
|
||||
--cap-drop=ALL
|
||||
|
||||
-e "HOST_LANG=${LANG:-C.UTF-8}"
|
||||
-e "HOST_LC_ALL=${LC_ALL:-}"
|
||||
-e "START_DIR=${START_DIR}"
|
||||
|
||||
-v "$OPC_CONFIG:/home/dev/.config/opencode:rw"
|
||||
@@ -75,17 +73,16 @@ ARGS=(
|
||||
-v "$NPM_CACHE:/home/dev/.npm:rw"
|
||||
-v "$PIP_CACHE:/home/dev/.cache/pip:rw"
|
||||
-v "$PROJECTS_DIR:/workspace:rw"
|
||||
-v "$SCRIPT_DIR/entrypoint.sh:/usr/local/bin/opencode-dev-entrypoint:ro"
|
||||
)
|
||||
|
||||
if [[ -f "$HOME/.gitconfig" ]]; then
|
||||
ARGS+=(-v "$HOME/.gitconfig:/home/dev/.gitconfig:ro")
|
||||
else
|
||||
echo "WARNING: host .gitconfig not found"
|
||||
echo "WARNING: host .gitconfig not found, using container inner configuration"
|
||||
fi
|
||||
|
||||
# Additional bind mounts:
|
||||
# ./dev.sh /project --mount "$HOME/other:/extra"
|
||||
# ./dev.sh --mount "$HOME/other:/extra"
|
||||
while (($#)); do
|
||||
case "$1" in
|
||||
--mount)
|
||||
Reference in New Issue
Block a user