Skip to content
Merged
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.docker.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
BOT_TOKEN=
LAVALINK_PASSWORD=
LAVALINK_HOST_PORT=2333
SPOTIFY_CLIENT_ID=
SPOTIFY_CLIENT_SECRET=
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ BOT_TOKEN=
LAVALINK_HOST=localhost
LAVALINK_PORT=2333
LAVALINK_PASSWORD=
SPOTIFY_CLIENT_ID=
SPOTIFY_CLIENT_SECRET=
11 changes: 7 additions & 4 deletions Dockerfile.lavalink
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ FROM eclipse-temurin:21-jre-jammy
ARG LAVALINK_VERSION=4.2.2
ARG YOUTUBE_PLUGIN_VERSION=1.18.0
ARG YOUTUBE_PLUGIN_JAR=youtube-plugin-1.18.0.jar
ARG LAVASRC_VERSION=4.8.3

ENV LAVALINK_HOME=/opt/lavalink

RUN apt-get update \
&& apt-get install -y --no-install-recommends curl ca-certificates \
&& apt-get install -y --no-install-recommends curl ca-certificates gettext-base \
&& rm -rf /var/lib/apt/lists/*

RUN useradd --create-home --shell /usr/sbin/nologin lavalink
Expand All @@ -16,11 +17,13 @@ WORKDIR /opt/lavalink

RUN mkdir -p plugins \
&& curl -fsSL -o Lavalink.jar "https://github.com/lavalink-devs/Lavalink/releases/download/${LAVALINK_VERSION}/Lavalink.jar" \
&& curl -fsSL -o "plugins/${YOUTUBE_PLUGIN_JAR}" "https://github.com/lavalink-devs/youtube-source/releases/download/${YOUTUBE_PLUGIN_VERSION}/${YOUTUBE_PLUGIN_JAR}"
&& curl -fsSL -o "plugins/${YOUTUBE_PLUGIN_JAR}" "https://github.com/lavalink-devs/youtube-source/releases/download/${YOUTUBE_PLUGIN_VERSION}/${YOUTUBE_PLUGIN_JAR}" \
&& curl -fsSL -o "plugins/lavasrc-plugin-${LAVASRC_VERSION}.jar" "https://github.com/topi314/LavaSrc/releases/download/${LAVASRC_VERSION}/lavasrc-plugin-${LAVASRC_VERSION}.jar"

COPY --chown=lavalink:lavalink lavalink/application.yml ./application.yml
COPY --chown=lavalink:lavalink lavalink/entrypoint.sh ./entrypoint.sh

RUN chown -R lavalink:lavalink /opt/lavalink
RUN chmod +x entrypoint.sh && chown -R lavalink:lavalink /opt/lavalink

USER lavalink

Expand All @@ -29,4 +32,4 @@ EXPOSE 2333
HEALTHCHECK --interval=10s --timeout=5s --start-period=20s --retries=12 \
CMD sh -c 'curl -fsS -H "Authorization: ${LAVALINK_PASSWORD}" http://localhost:2333/version >/dev/null'

CMD ["java", "-jar", "Lavalink.jar", "--spring.config.additional-location=file:./"]
ENTRYPOINT ["./entrypoint.sh"]
43 changes: 2 additions & 41 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

import os
import shutil
import signal
import subprocess
import sys
from pathlib import Path
from getpass import getpass

from utils.env_utils import parse_env_lines, read_env_file, write_env_value


ROOT_DIR = Path(__file__).resolve().parent
VENV_DIR = ROOT_DIR / "venv"
Expand All @@ -24,46 +25,6 @@
ENV_EXAMPLE_PATH = ROOT_DIR / ".env.example"


def read_env_file(path: Path) -> list[str]:
if not path.exists():
return []
return path.read_text(encoding="utf-8").splitlines()


def parse_env_lines(lines: list[str]) -> dict[str, str]:
values: dict[str, str] = {}
for line in lines:
stripped = line.strip()
if not stripped or stripped.startswith("#") or "=" not in stripped:
continue
key, value = stripped.split("=", 1)
values[key.strip()] = value.strip()
return values


def write_env_value(path: Path, key: str, value: str) -> None:
lines = read_env_file(path)
updated = False
new_lines: list[str] = []

for line in lines:
stripped = line.strip()
if stripped and not stripped.startswith("#") and "=" in stripped:
current_key = stripped.split("=", 1)[0].strip()
if current_key == key:
new_lines.append(f"{key}={value}")
updated = True
continue
new_lines.append(line)

if not updated:
if new_lines and new_lines[-1] != "":
new_lines.append("")
new_lines.append(f"{key}={value}")

path.write_text("\n".join(new_lines) + "\n", encoding="utf-8")


def ensure_dotenv() -> None:
if not ENV_PATH.exists() and ENV_EXAMPLE_PATH.exists():
ENV_PATH.write_text(ENV_EXAMPLE_PATH.read_text(encoding="utf-8"), encoding="utf-8")
Expand Down
Loading