Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete the contents of the /tmp directory #76

Merged
merged 1 commit into from
Mar 19, 2024

Conversation

edruder
Copy link
Contributor

@edruder edruder commented Mar 16, 2024

Cached files in the /tmp directory can cause errors after renaming the project--nuke them so they don't cause grief.

Copy link
Owner

@nickjj nickjj left a comment

Choose a reason for hiding this comment

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

Thanks, I've dropped in a few comments.

The contents of the /tmp directory need to be deleted because they contain
references to the old project name and can cause errors if they're not removed.

Some of the files to be deleted are owned by users that only exist in the
Copy link
Owner

Choose a reason for hiding this comment

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

This project will run your container as a non-root user, files that land in tmp/ will be owned by the user of the process. We shouldn't need to ever use sudo here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm. I only added sudo because without it I got error messages about needing sudo.

I'll give it a shot.

Copy link
Owner

@nickjj nickjj Mar 16, 2024

Choose a reason for hiding this comment

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

Can you show the output of ls -la tmp/ when it produced an error?

Copy link
Contributor Author

@edruder edruder Mar 16, 2024

Choose a reason for hiding this comment

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

Now I don't see any error! ¯\(ツ)

I didn't preserve that session, so OOL.

Copy link
Owner

Choose a reason for hiding this comment

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

I wonder if you ran any Docker commands with sudo. That would have an effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I don't use sudo unless forced. 🙂

# the `.keep` file.
# -----------------------------------------------------------------------------
function delete_tmp {
sudo rm -rf ./tmp/* && touch ./tmp/.keep
Copy link
Owner

Choose a reason for hiding this comment

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

Going back to message in discussion #75, can you address this?

I'd suggest recursively deleting all of the contents in the tmp directory except for the .keep file since tmp/.keep is committed to version control. This will leave the original modified times on the directory and keep file too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The touched tmp/.keep does have a different modified time, but it doesn't show up as a modified file in git.

Do you think the modified time matters, since the modified time of the rest of the files are either the time when the repo was cloned, or the time when the rename script was run?

Copy link
Owner

Choose a reason for hiding this comment

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

I think if we leave the tmp/ directory in tact with the original modified time of the file, it's worth doing the same for the keep file. Something like find tmp/ ! -name ".keep" -delete should do the trick but I didn't test it. We would want to make sure the solution works with both the macOS and GNU version of find.

sudo rm -rf ./tmp/* && touch ./tmp/.keep
}

while true; do
Copy link
Owner

Choose a reason for hiding this comment

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

I think we can get by without needing a prompt for this.

@@ -51,6 +51,38 @@ find . -type f -exec \
-pe "s/${FIND_MODULE_NAME}/${MODULE_NAME}/g;" {} +
# -----------------------------------------------------------------------------

cat << 'EOF'
Copy link
Owner

Choose a reason for hiding this comment

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

I think all of this can go away and you can drop a 1 liner to delete the contents of the directory in this section of the script The core of the script which renames a few things. and then adjust this comment to be something like The core of the script.

Given this rename script is likely used shortly after creating the project and temporary files are temporary, there's nothing of value to protect or warn against.

@edruder
Copy link
Contributor Author

edruder commented Mar 16, 2024

I just pushed changes that I think simplify things the way that you want, though I haven't changed to a find that doesn't delete the .keep file.

@edruder
Copy link
Contributor Author

edruder commented Mar 16, 2024

  • I just pushed changes that use find s.t. the .keep file isn't deleted.
  • I changed your find suggestion slightly s.t. it works on both MacOS and Ubuntu.
  • I tweaked the comment s.t. it explains the need to delete the contents of the tmp directory.

@nickjj
Copy link
Owner

nickjj commented Mar 17, 2024

I changed your find suggestion slightly s.t. it works on both MacOS and Ubuntu.

Do you have a source around needing to set mindepth for it to work on macOS? I don't have a Mac to test.

I tweaked the comment s.t. it explains the need to delete the contents of the tmp directory.

I think we can remove the comments all together and adjust it to: #76 (comment)

Other than these 2 things, you can delete this text from the readme file too:

If you get an error upping the project related to RuntimeError: invalid bytecode then you have old tmp/ files sitting around related to the old project name, you can run ./run clean to clear all temporary files and fix the error.

@edruder
Copy link
Contributor Author

edruder commented Mar 18, 2024

I changed your find suggestion slightly s.t. it works on both MacOS and Ubuntu.

Do you have a source around needing to set mindepth for it to work on macOS? I don't have a Mac to test.

macOS didn't need mindepth–it worked fine with your exact suggestion. When I tried the same command on an Ubuntu VPS that I have, it didn't work–I found mindepth in an example somewhere, tried it, and it worked on my Ubuntu VPS. Then tried the command with mindepth on macOS and it still worked. WDYT?

I tweaked the comment s.t. it explains the need to delete the contents of the tmp directory.

I think we can remove the comments all together and adjust it to: #76 (comment)

Other than these 2 things, you can delete this text from the readme file too:

If you get an error upping the project related to RuntimeError: invalid bytecode then you have old tmp/ files sitting around related to the old project name, you can run ./run clean to clear all temporary files and fix the error.

OK. I'll modify the PR to reflect this.

@nickjj
Copy link
Owner

nickjj commented Mar 18, 2024

Sounds good, we can keep it in. I made a test directory and filled it with touch .keep && mkdir -p ok/cool && touch ok/cool/yep && touch sure. Both commands left a .keep file but without -mindepth 1, it threw a non-empty directory error.

bin/rename-project Outdated Show resolved Hide resolved
Copy link
Owner

@nickjj nickjj left a comment

Choose a reason for hiding this comment

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

Beyond the review comment, can you also update the changelog file?

You can add the following bullet under A whole bunch of changes related to Rails 7.1.0 which is under the unreleased changes:

  • Update rename-project script to auto-delete temporary files

Then it's good to go for being merged.

@JBerendes
Copy link
Contributor

I don't seem to have any problems with anything else in the tmp except the server.pid not getting cleaned up on a crash or computer restart.

I added this function and haven't had issues
function dc_up { rm -f tmp/pids/server.pid docker compose up "${@}" }

now i use
./run dc_up or ./run dc_up --build

Cached files in the /tmp directory can cause errors after renaming the
project--nuke them so they don't cause grief.
@nickjj
Copy link
Owner

nickjj commented Mar 19, 2024

Yep that's what I noticed too in practice but other changes can trigger it, #16 has more details.

For pid files, there's #65, there's a few ways to solve this such as configuring Puma and other services not to write pid files or cleaning them up automatically in an entrypoint.

@edruder edruder requested a review from nickjj March 19, 2024 20:38
Copy link
Owner

@nickjj nickjj left a comment

Choose a reason for hiding this comment

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

Looks good, thanks a lot for powering through this!

@nickjj nickjj merged commit 89514db into nickjj:main Mar 19, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants