Skip to content

Commit b17e003

Browse files
authored
Entrypoint logging and version string (#81)
* Cleaned up logging in docker file, disabled warning in prod builds as they tend to be spamy. * Added version string to footer on frontpage. Also logging version string in console on startup. * Reenabled minify for prod builds. * Removed unnecessary dash
1 parent 9318829 commit b17e003

File tree

11 files changed

+141
-33
lines changed

11 files changed

+141
-33
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@
3131
!README.md
3232
!LICENSE
3333
!docker/entrypoints/entrypoint*.sh
34+
!docker/entrypoints/common.sh

docker/Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ COPY ./backend/launch_redis_workers.py /repo/backend/
6262

6363
RUN uv sync
6464

65+
# Extract version from pyproject.toml
66+
RUN mkdir -p /version
67+
RUN python -c "import tomllib; print(tomllib.load(open('/repo/backend/pyproject.toml', 'rb'))['project']['version'])" > /version/backend.txt
68+
6569
# ------------------------------------------------------------------------------------ #
6670
# Development #
6771
# ------------------------------------------------------------------------------------ #
@@ -75,6 +79,19 @@ RUN --mount=type=cache,target=/var/cache/apk \
7579
RUN npm install -g pnpm
7680
RUN pnpm config set store-dir /repo/frontend/.pnpm-store
7781

82+
# Copy the lock files and install dependencies
83+
WORKDIR /repo
84+
COPY ./frontend/package.json /repo/frontend/
85+
COPY ./frontend/pnpm-lock.yaml /repo/frontend/
86+
87+
WORKDIR /repo/frontend
88+
RUN pnpm i
89+
90+
# Extract version from package.json
91+
RUN mkdir -p /version
92+
RUN python -c "import json; print(json.load(open('/repo/frontend/package.json'))['version'])" \
93+
> /version/frontend.txt
94+
7895
ENV IB_SERVER_CONFIG="dev_docker"
7996

8097
# relies on mounting this volume
@@ -113,12 +130,20 @@ WORKDIR /repo
113130
COPY ./frontend ./frontend/
114131
RUN chown -R beetle:beetle /repo
115132

133+
# Extract version from package.json
134+
RUN mkdir -p /version
135+
RUN python -c "import json; print(json.load(open('/repo/frontend/package.json'))['version'])" \
136+
> /version/frontend.txt
137+
116138
USER beetle
117139
WORKDIR /repo/frontend
118140
# RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
119141
RUN pnpm install
120142
RUN pnpm run build
121143

144+
145+
146+
122147
# ------------------------------------------------------------------------------------ #
123148
# Production #
124149
# ------------------------------------------------------------------------------------ #
@@ -129,9 +154,11 @@ ENV IB_SERVER_CONFIG="prod"
129154

130155
WORKDIR /repo
131156
COPY --from=build /repo/frontend/dist /repo/frontend/dist
157+
COPY --from=build /version /version
132158
COPY docker/entrypoints/entrypoint.sh .
133159
COPY docker/entrypoints/entrypoint_user_scripts.sh .
134160
COPY docker/entrypoints/entrypoint_fix_permissions.sh .
161+
COPY docker/entrypoints/common.sh .
135162
RUN chown -R beetle:beetle /repo
136163

137164
USER root

docker/entrypoints/common.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# A number of common functions used by entrypoints
2+
3+
log() {
4+
echo -e "[Entrypoint] $1"
5+
}
6+
7+
log_error() {
8+
echo -e "\033[0;31m[Entrypoint] $1\033[0m"
9+
}
10+
11+
log_current_user() {
12+
log "Running as '$(whoami)' with UID $(id -u) and GID $(id -g)"
13+
log "Current working directory: $(pwd)"
14+
}
15+
16+
log_version_info() {
17+
log "Version info:"
18+
log " Backend: $BACKEND_VERSION"
19+
log " Frontend: $FRONTEND_VERSION"
20+
log " Mode: $IB_SERVER_CONFIG"
21+
}
22+
23+
get_version_info() {
24+
if [ -f /version/backend.txt ]; then
25+
export BACKEND_VERSION=$(cat /version/backend.txt)
26+
else
27+
export BACKEND_VERSION="unk"
28+
fi
29+
30+
if [ -f /version/frontend.txt ]; then
31+
export FRONTEND_VERSION=$(cat /version/frontend.txt)
32+
else
33+
export FRONTEND_VERSION="unk"
34+
fi
35+
}
36+
37+
# Populate the environment variables for the version info
38+
get_version_info

docker/entrypoints/entrypoint.sh

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
12
#!/bin/sh
3+
source ./common.sh
24

3-
echo "Running as"
4-
id
5+
log_current_user
6+
log_version_info
57

68
cd /repo
79

@@ -13,17 +15,23 @@ mkdir -p /config/beets-flask
1315
# start backend #
1416
# ------------------------------------------------------------------------------------ #
1517

18+
# Ignore warnings for production builds
19+
export PYTHONWARNINGS="ignore"
20+
1621
# running the server from inside the backend dir makes imports and redis easier
1722
cd /repo/backend
1823

19-
redis-server --daemonize yes
24+
redis-server --daemonize yes >/dev/null 2>&1
2025

21-
python ./launch_redis_workers.py
26+
python ./launch_redis_workers.py > /logs/redis_workers.log 2>&1
2227

23-
redis-cli FLUSHALL
28+
redis-cli FLUSHALL >/dev/null 2>&1
2429

2530
# we need to run with one worker for socketio to work
2631
uvicorn beets_flask.server.app:create_app --port 5001 \
2732
--host 0.0.0.0 \
2833
--factory \
29-
--workers 4
34+
--workers 4 \
35+
--use-colors \
36+
--log-level info \
37+
--no-access-log

docker/entrypoints/entrypoint_dev.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/bin/sh
2+
source ./docker/entrypoints/common.sh
23

3-
whoami
4-
id
5-
pwd
4+
log_current_user
5+
log_version_info
6+
log "Starting development environment..."
67

78
cd /repo/frontend
89

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#!/bin/sh
22

33
if [ ! -z "$USER_ID" ] && [ ! -z "$GROUP_ID" ]; then
4-
echo "Updating UID to $USER_ID and GID to $GROUP_ID"
54
groupmod -g $GROUP_ID beetle
6-
usermod -u $USER_ID -g $GROUP_ID beetle
5+
usermod -u $USER_ID -g $GROUP_ID beetle > /dev/null 2>&1
76
chown -R beetle:beetle /home/beetle
87
chown -R beetle:beetle /repo
98
fi

frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "frontend",
33
"private": true,
4-
"version": "0.1.0",
4+
"version": "1.0.0",
55
"type": "module",
66
"scripts": {
77
"dev": "vite --host --cors",
@@ -37,6 +37,7 @@
3737
"@tanstack/eslint-plugin-query": "^5.78.0",
3838
"@tanstack/router-vite-plugin": "^1.120.13",
3939
"@types/diff": "^5.2.3",
40+
"@types/node": "^24.0.0",
4041
"@types/react": "^18.3.23",
4142
"@types/react-dom": "^18.3.7",
4243
"@types/react-window": "^1.8.8",

frontend/pnpm-lock.yaml

Lines changed: 35 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/routes/_frontpage/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ function Hero() {
152152

153153
function Footer() {
154154
const theme = useTheme();
155+
156+
let versionString = `v${__FRONTEND_VERSION__}`;
157+
if (__MODE__ !== "production") {
158+
// Append the mode to the version string if not in production
159+
versionString += ` (${__MODE__})`;
160+
}
161+
155162
return (
156163
<Box
157164
sx={(theme) => ({
@@ -179,7 +186,7 @@ function Footer() {
179186
variant="caption"
180187
sx={{ color: "grey.700", mr: "auto", alignSelf: "flex-end" }}
181188
>
182-
&copy; 2025 P. Spitzner &amp; S. Mohr
189+
{versionString} &copy; 2025 P. Spitzner &amp; S. Mohr
183190
</Typography>
184191

185192
<Link

0 commit comments

Comments
 (0)