Skip to content

Commit

Permalink
Changed base image to lsio, now properly implements PGID and PUID (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarons authored Jun 23, 2024
1 parent 6a29e95 commit d8c152a
Show file tree
Hide file tree
Showing 27 changed files with 125 additions and 39 deletions.
1 change: 1 addition & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ RUN \
rm allure-commandline-2.20.1.zip

ENV PATH "/allure/allure-2.20.1/bin:${PATH}"
RUN mkdir /config /icloud && chown -R vscode:vscode /config /icloud

WORKDIR /workspaces
4 changes: 2 additions & 2 deletions .github/workflows/ci-main-test-coverage-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
pip install -r requirements-test.txt
- name: Test with pytest
run: |
pytest
sudo mkdir /config /icloud && sudo chown -R $(id -u) /config /icloud && pytest
- name: Upload coverage artifacts
uses: actions/upload-artifact@v3
if: ${{ success() }}
Expand Down Expand Up @@ -227,6 +227,6 @@ jobs:
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
2 changes: 1 addition & 1 deletion .github/workflows/ci-pr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
# uses: mxschmitt/action-tmate@v3
- name: Test with pytest
run: |
pylint src/ tests/ && pytest
sudo mkdir /config /icloud && sudo chown -R $(id -u) /config /icloud && pylint src/ tests/ && pytest
- name: Generate Allure Report
uses: simple-elf/allure-report-action@master
if: always()
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"python.testing.pytestArgs": ["tests", "--no-cov"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
"python.testing.pytestEnabled": true,
"python.envFile": "${workspaceFolder}/tests/.env"
}
57 changes: 43 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,52 @@
FROM python:3.10-alpine3.19 AS build
RUN apk update && apk add git gcc musl-dev python3-dev libffi-dev openssl-dev cargo
COPY requirements.txt .
RUN python -m venv /venv
ENV PATH="/venv/bin/:$PATH"
RUN pip install -U pip
RUN pip install -r requirements.txt
FROM python:3.10-alpine3.19
# syntax=docker/dockerfile:1

FROM ghcr.io/linuxserver/baseimage-alpine:3.19

# set version label
ARG APP_VERSION=dev
ARG NEW_INSTALLATION_ENDPOINT=dev
ARG NEW_HEARTBEAT_ENDPOINT=dev
ENV NEW_INSTALLATION_ENDPOINT=$NEW_INSTALLATION_ENDPOINT
ENV NEW_HEARTBEAT_ENDPOINT=$NEW_HEARTBEAT_ENDPOINT
ENV APP_VERSION=$APP_VERSION
COPY --from=build /venv /venv
# Libmagic is required at runtime by python-magic
LABEL maintainer="mandarons"

ENV HOME="/app"
COPY requirements.txt .
RUN \
echo "**** install build packages ****" && \
apk add --no-cache --virtual=build-dependencies \
git \
gcc \
musl-dev \
python3-dev \
libffi-dev \
openssl-dev \
sudo libmagic shadow dumb-init \
cargo && \
echo "**** install packages ****" && \
apk add --no-cache \
python3 && \
echo "**** install icloud app ****" && \
python3 -m venv /lsiopy && \
pip install -U --no-cache-dir \
pip \
wheel && \
pip install -U --no-cache-dir -r requirements.txt && \
echo "**** cleanup ****" && \
apk del --purge \
build-dependencies && \
rm -rf \
/tmp/* \
${HOME}/.cache \
${HOME}/.cargo

# add local files
RUN apk update && apk add sudo libmagic shadow dumb-init
COPY root/ /
COPY . /app/
WORKDIR /app
ENV PATH="/venv/bin/:$PATH"
ENV PYTHONPATH="/app:${PYTHONPATH}"
ENTRYPOINT ["dumb-init", "--"]
CMD ["/app/init.sh"]

# ports and volumes
EXPOSE 8000
VOLUME /app
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Primary use case of iCloud-docker is to periodically sync wanted or all of your
### Installation using Docker Hub

```
docker run --name icloud -v ${PWD}/icloud:/app/icloud -v ${PWD}/config.yaml:/app/config.yaml -e ENV_ICLOUD_PASSWORD=<icloud_password> -v ${PWD}/session_data:/app/session_data mandarons/icloud-drive
docker run --name icloud -v ${PWD}/icloud:/icloud -v ${PWD}/config/config.yaml:/config/config.yaml -e ENV_ICLOUD_PASSWORD=<icloud_password> -v ${PWD}/session_data:/config/session_data mandarons/icloud-drive
```

### Installation using docker-compose
Expand All @@ -36,30 +36,29 @@ services:
- PUID=<insert the output of `id -u $user`>
- GUID=<insert the output of `id -g $user`>
env_file:
- .env.icloud #should contain ENV_ICLOUD_PASSWORD=<password>, ENV_CONFIG_FILE_PATH=<absolute path in container to config.yaml>
- .env.icloud #should contain ENV_ICLOUD_PASSWORD=<password>
container_name: icloud
restart: unless-stopped
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
# To override /app/config.yaml path in container, specify environment variable ENV_CONFIG_FILE_PATH=<absolute path in container to config.yaml>
- ${PWD}/icloud/config.yaml:/app/config.yaml
- ${PWD}/icloud/data:/app/icloud
- ${PWD}/session_data:/app/session_data
- ${PWD}/config/config.yaml:/config/config.yaml
- ${PWD}/icloud:/icloud
- ${PWD}/config/session_data:/config/session_data
```
### Authentication (required after container creation or authentication expiration)
```
# Login manually if ENV_ICLOUD_PASSWORD is not specified and/or 2FA is required
docker exec -it --user=icd icloud /bin/sh -c "icloud --username=<icloud-username> --session-directory=/app/session_data"
docker exec -it --user=icd icloud /bin/sh -c "icloud --username=<icloud-username> --session-directory=/config/session_data"
```

For China server users, Please add `--region=china` as follows:

```
# Login manually if ENV_ICLOUD_PASSWORD is not specified and/or 2FA is required
docker exec -it --user=icd icloud /bin/sh -c "icloud --username=<icloud-username> --region=china --session-directory=/app/session_data"
docker exec -it --user=icd icloud /bin/sh -c "icloud --username=<icloud-username> --region=china --session-directory=/config/session_data"
```

Follow the steps to authenticate.
Expand All @@ -72,14 +71,14 @@ app:
# level - debug, info (default), warning or error
level: "info"
# log filename icloud.log (default)
filename: "icloud.log"
filename: "/config/icloud.log"
credentials:
# iCloud drive username
username: "[email protected]"
# Retry login interval - default is 10 minutes, specifying -1 will retry login only once and exit
retry_login_interval: 600
# Drive destination
root: "icloud"
root: "/icloud"
discord:
# webhook_url: <your server webhook URL here>
# username: icloud-docker #or any other name you prefer
Expand Down
6 changes: 3 additions & 3 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ app:
logger:
# level - debug, info (default), warning or error
level: "info"
# log filename icloud.log (default)
filename: "icloud.log"
# log filename icloud.log
filename: "/config/icloud.log"
credentials:
# iCloud drive username
username: "[email protected]"
# Retry login interval - default is 10 minutes
retry_login_interval: 600
# Drive destination
root: "icloud"
root: "/icloud"
discord:
# webhook_url: <your server webhook URL here>
# username: icloud-docker #or any other name you prefer
Expand Down
8 changes: 1 addition & 7 deletions init.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
#!/bin/sh
echo '
====================================================
To support this project, please consider sponsoring.
https://github.com/sponsors/mandarons
https://www.buymeacoffee.com/mandarons
====================================================
'

cd /app && export PYTHONPATH=/app && export PATH=/venv/bin:$PATH && python ./src/main.py
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/ci-service-check/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
Empty file.
29 changes: 29 additions & 0 deletions root/etc/s6-overlay/s6-rc.d/init-adduser/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash

PUID=${PUID:-911}
PGID=${PGID:-911}

groupmod -o -g "$PGID" abc
usermod -o -u "$PUID" abc

echo "
====================================================
To support this project, please consider sponsoring.
https://github.com/sponsors/mandarons
https://www.buymeacoffee.com/mandarons

User UID: $(id -u abc)
User GID: $(id -g abc)
====================================================
"


if [[ -f /build_version ]]; then
cat /build_version
fi


lsiown abc:abc /app
lsiown abc:abc /config
lsiown abc:abc /defaults
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/init-adduser/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/init-adduser/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-adduser/run
Empty file.
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/init-custom-files/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
Empty file.
19 changes: 19 additions & 0 deletions root/etc/s6-overlay/s6-rc.d/init-icd-config/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash

# create our folders
mkdir -p \
/icloud \
/config/session

# # default config file
# cp -n \
# /defaults/pyload.cfg \
# /config/settings/pyload.cfg

# permissions
lsiown -R abc:abc \
/app \
/config
lsiown abc:abc \
/icloud
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/init-icd-config/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/init-icd-config/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-icd-config/run
Empty file.
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/init-migrations/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
Empty file.
6 changes: 6 additions & 0 deletions root/etc/s6-overlay/s6-rc.d/svc-icd/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash


exec \
s6-setuidgid abc /app/init.sh
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/svc-icd/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion run-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [ -f icloud.log ]; then rm -f icloud.log; fi
echo "Linting ..." &&
pylint src/ tests/ &&
echo "Testing ..." &&
pytest &&
ENV_CONFIG_FILE_PATH=./tests/data/test_config.yaml pytest &&
echo "Reporting ..." &&
allure generate --clean &&
echo "Done."

0 comments on commit d8c152a

Please sign in to comment.