Skip to content

feat(server): add a readme file to the Upload folder#17055

Closed
aviv926 wants to merge 30 commits intoimmich-app:mainfrom
aviv926:main
Closed

feat(server): add a readme file to the Upload folder#17055
aviv926 wants to merge 30 commits intoimmich-app:mainfrom
aviv926:main

Conversation

@aviv926
Copy link
Copy Markdown
Collaborator

@aviv926 aviv926 commented Mar 23, 2025

Description

Many users use Immich for a quick and convenient replacement for G photos. Sometimes these are users for whom Immich is their first self-host application, so mistakes can happen.
To this end, I believe there is a real need to add a file that warns inexperienced users about the danger of touching folders created by Immich in order to prevent any data loss / problems with the proper functioning of the system.
To this end, this PR focuses on adding a README.TXT file to the Upload folder in order to warn users before making changes to this folder.

How Has This Been Tested?

I edited the file on the current system where Immich is running and checked that the README.TXT file was indeed created in its intended location (Upload) and the system continues to operate without a problem.

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if applicable
  • I have no unrelated changes in the PR.
  • I have confirmed that any new dependencies are strictly necessary.
  • I have written tests for new code (if applicable)
  • I have followed naming conventions/patterns in the surrounding code
  • All code in src/services/ uses repositories implementations for database calls, filesystem operations, etc.
  • All code in src/repositories/ is pretty basic/simple and does not have any immich specific logic (that belongs in src/services/)

Note:

Since Immich allows the user to choose whether to use the Upload folder for source files or the Library folder, should we consider adding an identical file there as well?

@aviv926 aviv926 requested a review from danieldietzler as a code owner March 23, 2025 23:27
@aviv926 aviv926 requested review from bo0tzz and removed request for danieldietzler March 23, 2025 23:27
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 23, 2025

Label error. Requires exactly 1 of: changelog:.*. Found: 🗄️server. A maintainer will add the required label.

Comment thread server/start.sh Outdated

echo "Initializing Immich $IMMICH_SOURCE_REF"

cat <<EOF > /usr/src/app/upload/upload/README.txt
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cat <<EOF > /usr/src/app/upload/upload/README.txt
cat << 'EOF' > /usr/src/app/upload/upload/README.txt

I don't think there is a need for variable interpolation in this block.

Is there a way we can refer to the WORKDIR instead of hard coding the /usr/src... patch that will probably change in the future?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have enough knowledge to make this happen, maybe one of the developers can help with this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tbh I would just not do this. I'd just add a comment in the compose (and maybe .env?) file.

@mmomjian
Copy link
Copy Markdown
Collaborator

I definitely think we need a file in the library/ folder as well, either that or just put it in the UPLOAD_LOCATION root. I don't see the point to put it only in upload/

@aviv926
Copy link
Copy Markdown
Collaborator Author

aviv926 commented Mar 23, 2025

I definitely think we need a file in the library/ folder as well, either that or just put it in the UPLOAD_LOCATION root. I don't see the point to put it only in upload/

I also think it's better.
There was a discussion about this on Discord today.

@bo0tzz
Copy link
Copy Markdown
Member

bo0tzz commented Mar 24, 2025

I don't think hardcoding the path in the start.sh script is the way to go for this. The path can change (for example, the AIO image uses a different one). I think a better place to handle this is probably in the storage service bootstrap, where we also manage the .immich files. https://github.com/immich-app/immich/blob/main/server/src/services/storage.service.ts

@aviv926
Copy link
Copy Markdown
Collaborator Author

aviv926 commented Mar 26, 2025

I don't think hardcoding the path in the start.sh script is the way to go for this. The path can change (for example, the AIO image uses a different one). I think a better place to handle this is probably in the storage service bootstrap, where we also manage the .immich files. https://github.com/immich-app/immich/blob/main/server/src/services/storage.service.ts

Okay, I'm not familiar with ts, so I used GPT (I'll completely understand if you don't want to merge it). From what I've tested, the code does indeed create a README.TXT file in the Upload and Library folders.

Comment thread server/src/services/storage.service.ts Outdated
await this.verifyReadAccess(folder);
await this.verifyWriteAccess(folder);

// Ensure README.TXT is created in UPLOAD and LIBRARY folders only
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is unnecessary.

Comment thread server/src/services/storage.service.ts Outdated
try {
let exists = false;
try {
await this.storageRepository.stat(readmePath);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure there is an exists/existsSync call you may use instead.

Comment thread server/src/services/storage.service.ts Outdated
@@ -63,6 +68,38 @@ export class StorageService extends BaseService {
}

@OnJob({ name: JobName.DELETE_FILES, queue: QueueName.BACKGROUND_TASK })
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createReadmeFile absolutely shouldn't run on DELETE_FILES lol

Copy link
Copy Markdown
Member

@bo0tzz bo0tzz Apr 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be on the next function down instead. It getting separated didn't cause any test failures, which suggests maybe we're missing some coverage there?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Job queueing tests are quite limited still, yea :(

Comment thread server/src/services/storage.service.ts Outdated
try {
await this.storageRepository.stat(readmePath);
exists = true;
} catch (error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nested exceptions are imo always ugly and avoidable in almost all cases. Could you refactor this?

Comment thread .github/workflows/docker-build.yml Fixed
Comment thread .github/workflows/docker-build.yml Fixed
Comment thread .github/workflows/docker-build.yml Fixed
Comment thread .github/workflows/docker-build.yml Fixed
Comment thread .github/workflows/docker-build.yml Fixed
Comment thread .github/workflows/docker-build.yml Fixed
Comment thread .github/workflows/docker-build.yml Fixed
Comment thread .github/workflows/docker-build.yml Fixed
Comment thread .github/workflows/docker-build.yml Fixed
@aviv926 aviv926 marked this pull request as draft May 2, 2025 14:15
@aviv926 aviv926 marked this pull request as ready for review May 3, 2025 20:27
@aviv926 aviv926 requested a review from danieldietzler May 3, 2025 20:27
Comment thread .github/workflows/Custom_Build.yml Fixed
Comment thread .github/workflows/Custom_Build.yml Fixed
Comment thread .github/workflows/Custom_Build.yml Fixed
Comment thread .github/workflows/Custom_Build.yml Fixed
password: ${{ secrets.GHCR_PAT }}

- name: Build and push server image
uses: docker/build-push-action@v6

Check failure

Code scanning / zizmor

action is not pinned to a hash (required by blanket policy) Error

action is not pinned to a hash (required by blanket policy)
Comment thread .github/workflows/Custom_Build.yml Fixed
Comment thread .github/workflows/Custom_Build.yml Fixed
Comment thread .github/workflows/Custom_Build.yml Fixed
Comment thread .github/workflows/Custom_Build.yml Fixed
Comment thread .github/workflows/Custom_Build.yml Fixed
Comment thread .github/workflows/Custom_Build.yml Fixed
Comment thread .github/workflows/Custom_Build.yml Fixed
Comment thread .github/workflows/Custom_Build.yml Fixed
Comment thread .github/workflows/Custom_Build.yml Fixed
Comment thread .github/workflows/Custom_Build.yml Fixed
Comment thread .github/workflows/Custom_Build.yml Fixed
Comment thread .github/workflows/Custom_Build.yml Fixed

- name: Log in to GHCR
if: env.exists == 'false'
uses: docker/login-action@v3

Check failure

Code scanning / zizmor

action is not pinned to a hash (required by blanket policy) Error

action is not pinned to a hash (required by blanket policy)
Comment thread .github/workflows/Custom_Build.yml Fixed
Comment thread .github/workflows/Custom_Build.yml Fixed
Comment thread .github/workflows/Custom_Build.yml Fixed
Comment thread .github/workflows/Custom_Build.yml Fixed
Comment on lines +46 to +48
run: |
git branch -f dockerimageML ${{ steps.get_release.outputs.tag }}
git push origin dockerimageML --force

Check notice

Code scanning / zizmor

steps.get_release.outputs.tag may expand into attacker-controllable code Note

steps.get_release.outputs.tag may expand into attacker-controllable code
Comment on lines +57 to +60
- name: Checkout `dockerimageML`
uses: actions/checkout@v4
with:
ref: dockerimageML

Check warning

Code scanning / zizmor

does not set persist-credentials: false Warning

does not set persist-credentials: false
ref: dockerimageML

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

Check failure

Code scanning / zizmor

action is not pinned to a hash (required by blanket policy) Error

action is not pinned to a hash (required by blanket policy)
Comment thread .github/workflows/Custom_Build.yml Fixed
workflow_dispatch:

permissions:
contents: write

Check failure

Code scanning / zizmor

contents: write is overly broad at the workflow level Error

contents: write is overly broad at the workflow level

permissions:
contents: write
packages: write

Check failure

Code scanning / zizmor

packages: write is overly broad at the workflow level Error

packages: write is overly broad at the workflow level
Comment on lines +32 to +35
- name: Check out this repo
uses: actions/checkout@v4
with:
fetch-depth: 0

Check warning

Code scanning / zizmor

does not set persist-credentials: false Warning

does not set persist-credentials: false
Comment on lines +95 to +98
- name: Checkout `dockerimageML`
uses: actions/checkout@v4
with:
ref: dockerimageML

Check warning

Code scanning / zizmor

does not set persist-credentials: false Warning

does not set persist-credentials: false
ref: dockerimageML

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

Check failure

Code scanning / zizmor

action is not pinned to a hash (required by blanket policy) Error

action is not pinned to a hash (required by blanket policy)
uses: docker/setup-buildx-action@v3

- name: Log in to GHCR
uses: docker/login-action@v3

Check failure

Code scanning / zizmor

action is not pinned to a hash (required by blanket policy) Error

action is not pinned to a hash (required by blanket policy)
password: ${{ secrets.GHCR_PAT }}

- name: Build & push ML image (${{ matrix.device }})
uses: docker/build-push-action@v6

Check failure

Code scanning / zizmor

action is not pinned to a hash (required by blanket policy) Error

action is not pinned to a hash (required by blanket policy)
@danieldietzler
Copy link
Copy Markdown
Member

We have discussed this again and decided we don't want it after all. We already have plenty of warnings in various places. Sorry for having you waste some time on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants