From 101e86a9e2a8416d2b2181e2c99e06104fce1ce5 Mon Sep 17 00:00:00 2001 From: Spoked Date: Tue, 19 Dec 2023 01:19:22 -0500 Subject: [PATCH 1/7] add makefile. fix entrypoint. dockerfile needs entrypoint execution tweak though. --- Dockerfile | 67 +++++++++++++++++++++++++-------------------------- README.md | 6 ++--- entrypoint.sh | 29 ++++++++++------------ makefile | 42 ++++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 53 deletions(-) create mode 100644 makefile diff --git a/Dockerfile b/Dockerfile index d35b0ec2..80e0b067 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,42 +1,41 @@ -FROM alpine:3.19 - -LABEL org.label-schema.name="Iceberg" \ - org.label-schema.description="Iceberg Debrid Downloader" \ - org.label-schema.url="https://github.com/dreulavelle/iceberg" - -# Install necessary packages -RUN apk --update add python3 py3-pip nodejs npm bash shadow vim nano rclone && \ +# Frontend Builder +FROM node:20-alpine AS frontend +WORKDIR /app +COPY frontend/package*.json ./ +RUN npm install esbuild@0.19.9 +RUN npm install +COPY frontend/ . +RUN npm run build && npm prune --production + +# Final Image +FROM alpine:3.18 + +LABEL name="Iceberg" \ + description="Iceberg Debrid Downloader" \ + url="https://github.com/dreulavelle/iceberg" + +RUN apk --update add python3 py3-pip bash shadow vim nano rclone && \ rm -rf /var/cache/apk/* -# Install pnpm -RUN npm install -g pnpm - -# Set the working directory WORKDIR /iceberg -# Copy the application files -COPY . /iceberg/ - -# Set up Python virtual environment and install dependencies -RUN python3 -m venv /venv && \ - source /venv/bin/activate && \ - pip install --no-cache-dir -r requirements.txt - -# Build the frontend -RUN cd frontend && \ - pnpm install && \ - pnpm run build +# Frontend +RUN addgroup -S node && adduser -S node -G node +COPY --from=frontend --chown=node:node /app/build /iceberg/frontend/build +COPY --from=frontend --chown=node:node /app/node_modules /iceberg/frontend/node_modules +COPY --from=frontend --chown=node:node /app/package.json /iceberg/frontend/package.json -# Expose necessary ports -EXPOSE 4173 8080 +# Backend +COPY backend/ /iceberg/backend +RUN python3 -m venv /venv +COPY requirements.txt /iceberg/requirements.txt +RUN source /venv/bin/activate && pip install -r /iceberg/requirements.txt -# Copy and set permissions for the entrypoint script -COPY entrypoint.sh /usr/local/bin/entrypoint.sh -RUN chmod +x /usr/local/bin/entrypoint.sh +COPY entrypoint.sh ./entrypoint.sh +RUN chmod +x ./entrypoint.sh +ENTRYPOINT ["/iceberg/entrypoint.sh"] -# Set the entrypoint script -ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] +EXPOSE 3000 8080 -# Start the backend first, then the frontend (suppressed frontend output) -CMD cd backend && source /venv/bin/activate && exec python main.py & \ - cd frontend && pnpm run preview --host 0.0.0.0 >/dev/null 2>&1 +CMD cd backend && source /venv/bin/activate && exec python /iceberg/backend/main.py & \ + node /iceberg/frontend/build diff --git a/README.md b/README.md index 9f37df97..b7bc41be 100644 --- a/README.md +++ b/README.md @@ -41,10 +41,10 @@ services: container_name: Iceberg restart: unless-stopped environment: - - PUID=1000 - - GUID=1000 + PUID: "1000" + PGID: "1000" ports: - - "4173:4173" + - "3000:3000" volumes: - ./data:/iceberg/data ``` diff --git a/entrypoint.sh b/entrypoint.sh index 7e47ddf7..4a36f066 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,27 +1,24 @@ -#!/bin/sh +#!/bin/bash -echo "Starting Container with ${PUID}:${PGID} permissions..." +# Display the UID and GID that will be used +echo "Starting Container with ${PUID:-1000}:${PGID:-1000} permissions..." -# Create group if it doesn't exist or reuse the existing group -if ! getent group $PGID > /dev/null; then - addgroup -g $PGID iceberg +# Create or reuse group +if ! getent group "${PGID}" > /dev/null; then + addgroup -g "${PGID}" iceberg else - existing_group=$(getent group $PGID | cut -d: -f1) - echo "Group with GID $PGID already exists as $existing_group" + existing_group=$(getent group "${PGID}" | cut -d: -f1) > /dev/null iceberg_group=$existing_group fi -# Create user if it doesn't exist or reuse the existing user -if ! getent passwd $PUID > /dev/null; then - adduser -D -u $PUID -G ${iceberg_group:-iceberg} iceberg +# Create or reuse user +if ! getent passwd "${PUID}" > /dev/null; then + adduser -D -u "${PUID}" -G "${iceberg_group:-iceberg}" iceberg else - existing_user=$(getent passwd $PUID | cut -d: -f1) - echo "User with UID $PUID already exists as $existing_user" + existing_user=$(getent passwd "${PUID}" | cut -d: -f1) > /dev/null iceberg_user=$existing_user fi -# Change ownership of relevant directories -chown -R ${PUID}:${PGID} /iceberg - +chown -R "${PUID}:${PGID}" /iceberg echo "Initialization complete. Executing main process..." -exec su -s /bin/sh -c "$@" ${iceberg_user:-iceberg} +exec "$@" diff --git a/makefile b/makefile new file mode 100644 index 00000000..0b73d634 --- /dev/null +++ b/makefile @@ -0,0 +1,42 @@ +.PHONY: start restart stop logs exec help start-nocache restart-nocache + +help: + @echo Iceberg Local Development Environment + @echo ------------------------------------------------------- + @echo start : Build and run the Iceberg container + @echo start-nocache : Build and run the Iceberg container without using cache + @echo stop : Stop and remove the Iceberg container + @echo restart : Restart the Iceberg container + @echo restart-nocache : Restart the Iceberg container without using cache + @echo exec : Open a shell inside the Iceberg container + @echo logs : Show the logs of the Iceberg container + @echo ------------------------------------------------------- + +start: + docker build -t iceberg:latest -f Dockerfile . + docker run -d --name iceberg -p 3000:3000 -p 8080:8080 -e PUID=1000 -e PGID=1000 -v ${PWD}/data:/iceberg/data iceberg:latest + @echo Iceberg Frontend is running on http://localhost:3000/ + @echo Iceberg Backend is running on http://localhost:8080/items/ + @docker logs iceberg -f + +start-nocache: + docker build --no-cache -t iceberg:latest -f Dockerfile . + docker run -d --name iceberg -p 3000:3000 -p 8080:8080 -e PUID=1000 -e PGID=1000 -v ${PWD}/data:/iceberg/data iceberg:latest + @echo Iceberg Frontend is running on http://localhost:3000/ + @echo Iceberg Backend is running on http://localhost:8080/items/ + @docker logs iceberg -f + +stop: + -docker stop iceberg + -docker rm iceberg + -docker rmi iceberg:latest + +restart: stop start + +restart-nocache: stop start-nocache + +exec: + @docker exec -it iceberg /bin/sh + +logs: + @docker logs iceberg -f From 9fd7a8127569adbbdbbb24510b765cd6e5d4b9bc Mon Sep 17 00:00:00 2001 From: Spoked Date: Tue, 19 Dec 2023 01:49:22 -0500 Subject: [PATCH 2/7] Fixed entrypoint. Fixed user being set to root --- Dockerfile | 4 ++-- makefile | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 80e0b067..74976748 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ COPY frontend/ . RUN npm run build && npm prune --production # Final Image -FROM alpine:3.18 +FROM node:20-alpine LABEL name="Iceberg" \ description="Iceberg Debrid Downloader" \ @@ -20,7 +20,6 @@ RUN apk --update add python3 py3-pip bash shadow vim nano rclone && \ WORKDIR /iceberg # Frontend -RUN addgroup -S node && adduser -S node -G node COPY --from=frontend --chown=node:node /app/build /iceberg/frontend/build COPY --from=frontend --chown=node:node /app/node_modules /iceberg/frontend/node_modules COPY --from=frontend --chown=node:node /app/package.json /iceberg/frontend/package.json @@ -36,6 +35,7 @@ RUN chmod +x ./entrypoint.sh ENTRYPOINT ["/iceberg/entrypoint.sh"] EXPOSE 3000 8080 +USER node:node CMD cd backend && source /venv/bin/activate && exec python /iceberg/backend/main.py & \ node /iceberg/frontend/build diff --git a/makefile b/makefile index 0b73d634..792e9150 100644 --- a/makefile +++ b/makefile @@ -4,23 +4,23 @@ help: @echo Iceberg Local Development Environment @echo ------------------------------------------------------- @echo start : Build and run the Iceberg container - @echo start-nocache : Build and run the Iceberg container without using cache + @echo start-nocache : Build and run the Iceberg container without caching image @echo stop : Stop and remove the Iceberg container @echo restart : Restart the Iceberg container - @echo restart-nocache : Restart the Iceberg container without using cache + @echo restart-nocache : Restart the Iceberg container without caching image @echo exec : Open a shell inside the Iceberg container @echo logs : Show the logs of the Iceberg container @echo ------------------------------------------------------- start: docker build -t iceberg:latest -f Dockerfile . - docker run -d --name iceberg -p 3000:3000 -p 8080:8080 -e PUID=1000 -e PGID=1000 -v ${PWD}/data:/iceberg/data iceberg:latest + @docker run -d --name iceberg -p 3000:3000 -p 8080:8080 -e PUID=1000 -e PGID=1000 -v ${PWD}/data:/iceberg/data iceberg:latest @echo Iceberg Frontend is running on http://localhost:3000/ @echo Iceberg Backend is running on http://localhost:8080/items/ @docker logs iceberg -f start-nocache: - docker build --no-cache -t iceberg:latest -f Dockerfile . + @docker build --no-cache -t iceberg:latest -f Dockerfile . docker run -d --name iceberg -p 3000:3000 -p 8080:8080 -e PUID=1000 -e PGID=1000 -v ${PWD}/data:/iceberg/data iceberg:latest @echo Iceberg Frontend is running on http://localhost:3000/ @echo Iceberg Backend is running on http://localhost:8080/items/ From 782eed873a2dfe15c2ed3900214d9b50f427ef24 Mon Sep 17 00:00:00 2001 From: Spoked Date: Tue, 19 Dec 2023 01:54:43 -0500 Subject: [PATCH 3/7] Fix readme --- README.md | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b7bc41be..c55f65d1 100644 --- a/README.md +++ b/README.md @@ -49,14 +49,6 @@ services: - ./data:/iceberg/data ``` -> [!WARNING] -> You must have a standard settings.json file already in place before bind mounting it! -> An empty settings.json file, or no file at all, will cause issues! - -You can get a copy of the default settings [here](https://raw.githubusercontent.com/dreulavelle/iceberg/main/backend/utils/default_settings.json) - -After copying over the settings file (on a fresh install) you can bind mount it like the compose above. - ## Running outside of Docker First terminal: @@ -84,3 +76,19 @@ Rclone is mounted to /iceberg/vfs on your host machine -> settings should have: Plex container volume configuration for rclone mount is "/iceberg/vfs:/media/vfs" -> settings should have: "container_mount": "/media/vfs" Plex libraries you want to add to sections: movies -> /media/library/movies, shows -> /media/library/shows + + +## Development +You can view the readme in `make` to get started! + +```sh +make +``` + +To get started you can simply + +```sh +make start +``` + +You can restart with `make restart` **or** `make restart-nocache` to build the image without caching layers. From f5daacadf922507077b07a08b0ffcedaf46af3b3 Mon Sep 17 00:00:00 2001 From: Spoked Date: Tue, 19 Dec 2023 03:34:36 -0500 Subject: [PATCH 4/7] Done. Can now set PUID/PGID correctly. Updated Dev Env makefile. --- .dockerignore | 1 + .gitignore | 3 ++- Dockerfile | 4 --- entrypoint.sh | 38 +++++++++++++++++----------- makefile | 69 +++++++++++++++++++++++++++++++++------------------ 5 files changed, 72 insertions(+), 43 deletions(-) diff --git a/.dockerignore b/.dockerignore index eb3f86ff..d6838f2f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,6 +3,7 @@ .dockerignore docker-compose.yml Dockerfile +makefile # Frontend .DS_Store diff --git a/.gitignore b/.gitignore index d5511e5f..6096d90b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ settings.json .vscode __pycache__ .git -docker-compose.yml \ No newline at end of file +docker-compose.yml +makefile \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 74976748..b8ff047c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,7 +35,3 @@ RUN chmod +x ./entrypoint.sh ENTRYPOINT ["/iceberg/entrypoint.sh"] EXPOSE 3000 8080 -USER node:node - -CMD cd backend && source /venv/bin/activate && exec python /iceberg/backend/main.py & \ - node /iceberg/frontend/build diff --git a/entrypoint.sh b/entrypoint.sh index 4a36f066..0e619881 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,24 +1,34 @@ #!/bin/bash -# Display the UID and GID that will be used echo "Starting Container with ${PUID:-1000}:${PGID:-1000} permissions..." -# Create or reuse group -if ! getent group "${PGID}" > /dev/null; then - addgroup -g "${PGID}" iceberg +if ! [ "$PUID" -eq "$PUID" ] 2> /dev/null; then + echo "PUID is not a valid integer. Exiting..." + exit 1 +fi + +if ! [ "$PGID" -eq "$PGID" ] 2> /dev/null; then + echo "PGID is not a valid integer. Exiting..." + exit 1 +fi + +: ${USERNAME:=iceberg} +: ${GROUPNAME:=iceberg} + + +if ! getent group ${PGID} >/dev/null; then + addgroup -g $PGID $GROUPNAME > /dev/null else - existing_group=$(getent group "${PGID}" | cut -d: -f1) > /dev/null - iceberg_group=$existing_group + GROUPNAME=$(getent group ${PGID} | cut -d: -f1) fi -# Create or reuse user -if ! getent passwd "${PUID}" > /dev/null; then - adduser -D -u "${PUID}" -G "${iceberg_group:-iceberg}" iceberg +if ! getent passwd ${PUID} >/dev/null; then + adduser -D -u $PUID -G $GROUPNAME $USERNAME > /dev/null else - existing_user=$(getent passwd "${PUID}" | cut -d: -f1) > /dev/null - iceberg_user=$existing_user + USERNAME=$(getent passwd ${PUID} | cut -d: -f1) fi -chown -R "${PUID}:${PGID}" /iceberg -echo "Initialization complete. Executing main process..." -exec "$@" +chown -R ${USERNAME}:${GROUPNAME} /iceberg + +echo "Container Initialization complete." +exec su -m $USERNAME -c 'cd backend && source /venv/bin/activate && exec python /iceberg/backend/main.py & node /iceberg/frontend/build' diff --git a/makefile b/makefile index 792e9150..fa863767 100644 --- a/makefile +++ b/makefile @@ -1,42 +1,63 @@ -.PHONY: start restart stop logs exec help start-nocache restart-nocache +.PHONY: help start reset stop restart rebuild logs exec sc ec + +# Detect operating system +ifeq ($(OS),Windows_NT) + # For Windows + DATA_PATH := $(shell echo %cd%)\data +else + # For Linux + DATA_PATH := $(PWD)/data +endif help: @echo Iceberg Local Development Environment - @echo ------------------------------------------------------- - @echo start : Build and run the Iceberg container - @echo start-nocache : Build and run the Iceberg container without caching image - @echo stop : Stop and remove the Iceberg container - @echo restart : Restart the Iceberg container - @echo restart-nocache : Restart the Iceberg container without caching image - @echo exec : Open a shell inside the Iceberg container - @echo logs : Show the logs of the Iceberg container - @echo ------------------------------------------------------- + @echo ------------------------------------------------------------------------- + @echo start : Build and run the Iceberg container + @echo reset : Build and run the Iceberg container without caching image + @echo stop : Stop and remove the Iceberg container and image + @echo restart : Restart the Iceberg container (without rebuilding image) + @echo rebuild : Rebuild the Iceberg container (with rebuilding image) + @echo exec : Open a shell inside the Iceberg container + @echo logs : Show the logs of the Iceberg container + @echo sc : Show the contents of the settings.json file inside the Iceberg container + @echo ec : Edit the settings.json file inside the Iceberg container + @echo ------------------------------------------------------------------------- start: - docker build -t iceberg:latest -f Dockerfile . - @docker run -d --name iceberg -p 3000:3000 -p 8080:8080 -e PUID=1000 -e PGID=1000 -v ${PWD}/data:/iceberg/data iceberg:latest - @echo Iceberg Frontend is running on http://localhost:3000/ + @docker build -t iceberg:latest -f Dockerfile . + @docker run -d --name iceberg --hostname iceberg -p 3000:3000 -p 8080:8080 -e PUID=1000 -e PGID=1000 -v $(DATA_PATH):/iceberg/data iceberg:latest + @echo Iceberg Frontend is running on http://localhost:3000/status/ @echo Iceberg Backend is running on http://localhost:8080/items/ @docker logs iceberg -f -start-nocache: +reset: @docker build --no-cache -t iceberg:latest -f Dockerfile . - docker run -d --name iceberg -p 3000:3000 -p 8080:8080 -e PUID=1000 -e PGID=1000 -v ${PWD}/data:/iceberg/data iceberg:latest - @echo Iceberg Frontend is running on http://localhost:3000/ + @docker run -d --name iceberg --hostname iceberg -p 3000:3000 -p 8080:8080 -e PUID=1000 -e PGID=1000 -v $(DATA_PATH):/iceberg/data iceberg:latest + @echo Iceberg Frontend is running on http://localhost:3000/status/ @echo Iceberg Backend is running on http://localhost:8080/items/ @docker logs iceberg -f stop: - -docker stop iceberg - -docker rm iceberg - -docker rmi iceberg:latest - -restart: stop start + @-docker stop iceberg + @-docker rm iceberg + @-docker rmi iceberg:latest -restart-nocache: stop start-nocache +restart: + @-docker restart iceberg + @echo Iceberg Frontend is running on http://localhost:3000/status/ + @echo Iceberg Backend is running on http://localhost:8080/items/ + @docker logs iceberg -f -exec: - @docker exec -it iceberg /bin/sh +rebuild: stop reset logs: @docker logs iceberg -f + +exec: + @docker exec -it iceberg /bin/bash + +sc: + @docker exec -it iceberg /bin/bash -c "cat /iceberg/data/settings.json" + +ec: + @docker exec -it iceberg /bin/bash -c "vim /iceberg/data/settings.json" From dedeeb9ab6be964264831af5403280fc8f25d548 Mon Sep 17 00:00:00 2001 From: Spoked Date: Tue, 19 Dec 2023 03:42:18 -0500 Subject: [PATCH 5/7] Sneak in update lol --- makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/makefile b/makefile index fa863767..97a17822 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -.PHONY: help start reset stop restart rebuild logs exec sc ec +.PHONY: help start reset stop restart rebuild logs exec sc ec update # Detect operating system ifeq ($(OS),Windows_NT) @@ -21,6 +21,7 @@ help: @echo logs : Show the logs of the Iceberg container @echo sc : Show the contents of the settings.json file inside the Iceberg container @echo ec : Edit the settings.json file inside the Iceberg container + @echo update : Update the Iceberg container @echo ------------------------------------------------------------------------- start: @@ -61,3 +62,7 @@ sc: ec: @docker exec -it iceberg /bin/bash -c "vim /iceberg/data/settings.json" + +update: + @git pull + @rebuild \ No newline at end of file From fd439f92eecb94c686fbc284b6da0fbb9a7fe2f0 Mon Sep 17 00:00:00 2001 From: Spoked Date: Tue, 19 Dec 2023 03:43:57 -0500 Subject: [PATCH 6/7] Update help --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index 97a17822..24f74658 100644 --- a/makefile +++ b/makefile @@ -21,7 +21,7 @@ help: @echo logs : Show the logs of the Iceberg container @echo sc : Show the contents of the settings.json file inside the Iceberg container @echo ec : Edit the settings.json file inside the Iceberg container - @echo update : Update the Iceberg container + @echo update : Update this repository from GitHub and rebuild image @echo ------------------------------------------------------------------------- start: From e5d0271c5d1cb20331c24dee4e92cb94b7b2a1af Mon Sep 17 00:00:00 2001 From: Spoked Date: Tue, 19 Dec 2023 03:45:56 -0500 Subject: [PATCH 7/7] Correct syntax for update. --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index 24f74658..6affd144 100644 --- a/makefile +++ b/makefile @@ -65,4 +65,4 @@ ec: update: @git pull - @rebuild \ No newline at end of file + @make rebuild \ No newline at end of file