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

Refactor how we set/restore ownership of drupal settings file to allow reuse... #179

Conversation

jasonhildebrand
Copy link
Contributor

...in containers based on this one.

The net effect of this PR on its own is none - everything works as before, I have simply factored out these two functions.

I'll be submitting a PR against isle-dc shortly where I make use of these functions to fix an issue occurring there.

@jasonhildebrand
Copy link
Contributor Author

Here is the issue this refactoring helps to fix: Islandora-Devops/isle-dc#208

Copy link
Contributor

@nigelgbanks nigelgbanks left a comment

Choose a reason for hiding this comment

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

Good stuff, just a small gotcha with the restoration of perms being outside of the restore function.

if [ ! -z "${previous_owner_group}" ]; then
chown "${previous_owner_group}" "${site_directory}/settings.php"
fi
restore_settings_ownership ${site} ${previous_owner_group}

# Restrict access to settings.php
chmod 444 "${site_directory}/settings.php"
Copy link
Contributor

Choose a reason for hiding this comment

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

We should move the correction of permissions into restore_settings_ownership

# Restrict access to settings.php
chmod 444 "${site_directory}/settings.php"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes - good catch. I've made this change.

# send debug output to stderr because the caller typically captures output from this function.
#>&2 echo "adjusting ownership of ${site_directory}/settings.php"
if [ -f "${site_directory}/settings.php" ]; then
previous_owner_group=$(stat -c "%u:%g" "${site_directory}/settings.php")
Copy link
Contributor

Choose a reason for hiding this comment

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

On review I don't know why we'd ever have an owner/group other than nginx:nginx (100:101)? With the possible exception if it's bind mounted. Possibly all files in /var/www/drupal have the hosts users group to allow for host edits or something... That being said it doesn't hurt anything. Just a thought as to why did we do this in the first place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch re: permissions. I've moved this into the function.

Restoring ownership is only important when it's bind mounted. It ensures the file remains readable/writable by the host user. I've added a comment in the code to this effect.

# Restore owner/group to previous value
if [ ! -z "${previous_owner_group}" ]; then
#echo "restoring ${site_directory}/settings.php"
#echo "previous_owner_group ${previous_owner_group}"
Copy link
Contributor

Choose a reason for hiding this comment

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

We can remove the commented out #echo statements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed - I've taken them out.

@nigelgbanks nigelgbanks merged commit 78e2348 into Islandora-Devops:main Jan 13, 2022
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.

2 participants