Skip to content

Always specify config file in command and always run as gemstash user.#7

Merged
hadrianvalentine merged 12 commits intomasterfrom
use_config_file
Sep 29, 2020
Merged

Always specify config file in command and always run as gemstash user.#7
hadrianvalentine merged 12 commits intomasterfrom
use_config_file

Conversation

@hadrianvalentine
Copy link
Copy Markdown
Contributor

@hadrianvalentine hadrianvalentine commented Sep 18, 2020

Problem

Currently a bug exists where we only specify the gemstash config when the root user is used.
See output from top below:
v1 Gemstash
Screenshot 2020-09-18 at 15 40 15
v2 Gemstash
Screenshot 2020-09-18 at 15 40 25

As you can see, when we run gemstash v2, which uses rootless containers in, we do not specify a config file. The result of this is that gemstash writes and reads data to and from /home/gemstash/.gemstash instead of /home/gemstash/data where we mount our data volume. As a result we're not able to query gem versions from our restored database.

Solution

Remove the entrypoint.sh file and specify a simpler entrypoint in the Dockerfile.
Results from local build
Screenshot 2020-09-22 at 11 16 20

@hadrianvalentine hadrianvalentine requested a review from a team as a code owner September 18, 2020 13:56
@zacblazic
Copy link
Copy Markdown
Member

Really good job on finding this. 🎉

I'd change the approach you've taken in fixing it though.

I'm thinking we should probably drop the entrypoint.sh entirely as we shouldn't be supporting running as root anyways. You'd probably then set the USER to gemstash and modify the CMD to include tini and the --config-file flag.

Thoughts?

@itskingori
Copy link
Copy Markdown
Member

I'm thinking we should probably drop the entrypoint.sh entirely as we shouldn't be supporting running as root anyways. You'd probably then set the USER to gemstash and modify the CMD to include tini and the --config-file flag.

I agree that we might as well clean it up. Using entry points was pre-securitycontext where it was a hacky way to force the app running as a certain user. Better to keep the image generic and tweak runtime configuration outside the docker image.

@hadrianvalentine
Copy link
Copy Markdown
Contributor Author

SGTM 👌

Comment thread Dockerfile
@hadrianvalentine
Copy link
Copy Markdown
Contributor Author

I'm thinking we should probably drop the entrypoint.sh entirely as we shouldn't be supporting running as root anyways. You'd probably then set the USER to gemstash and modify the CMD to include tini and the --config-file flag.

Done
8fd658c
ef265b9

Also, updated the description with a screen shot of the process from local testing.

Comment thread Dockerfile
hadrianvalentine and others added 2 commits September 22, 2020 12:30
@itskingori
Copy link
Copy Markdown
Member

In 5912c04 you removed app/config.yml.erb. I think then we have two options:

  1. You can return it in and update the docker-compose.*.yml files to point to it ... which are used to test it.
  2. Or ... we remove the docker-compose.*.yml so that we don't need it.

In #7 (comment) I made the argument that the Dockefile should be kept generic (which you have done) ... it's just that this repo has docker-compose files that are representative of what would be our kubernetes manifests. And right now they are broken without a custom command:

I'm leaning on no.2 as most of what the docker-compose files demonstrate would be in the Gemstash docs. But keen on Zac's comments. Either way, I don't think this should be a blocker as it seems to me this is turning into a bit of a 🐰 🕳️ for you. We can merge this for the sake of progress and address it later.

@zacblazic
Copy link
Copy Markdown
Member

In 5912c04 you removed app/config.yml.erb. I think then we have two options:

  1. You can return it in and update the docker-compose.*.yml files to point to it ... which are used to test it.
  2. Or ... we remove the docker-compose.*.yml so that we don't need it.

In #7 (comment) I made the argument that the Dockefile should be kept generic (which you have done) ... it's just that this repo has docker-compose files that are representative of what would be our kubernetes manifests. And right now they are broken without a custom command:

I'm leaning on no.2 as most of what the docker-compose files demonstrate would be in the Gemstash docs. But keen on Zac's comments. Either way, I don't think this should be a blocker as it seems to me this is turning into a bit of a 🐰 🕳️ for you. We can merge this for the sake of progress and address it later.

I have a bit of a different opinion on the generic-ness idea, but I think I have good a reason for that.

This is a public repository and I'd say the idea would be that anyone else could easily get Gemstash up and running on whatever container runtime or orchestration tooling they're using. To support this notion, you need to be able to spin up the container with as little configuration as possible for the general use-case.

That said I think there are two options which sort of align with your first point.

Non-generic

  • A configuration file with good defaults and/or environment variable support, added to the image.
  • A default CMD that makes use of that configuration file.
  • Specification of the init process (i.e. tini) as the ENTRYPOINT if that is how we intend people to use it.
  • Specification of the USER to the intended user.
  • A docker-compose file(s) that sets the required environment variables for the configuration, plus other things like volumes etc.

Generic

  • A configuration file with good defaults and/or environment variable support, which doesn't necessarily have to be added to the image (i.e. can be used via docker-compose). However, I think always putting a default configuration in the image is a good idea.
  • Either set no CMD or set it to /bin/sh or similar.
  • No ENTRYPOINT.
  • Specification of the USER to the intended user. This is important even for the generic approach as it will allow the container to run rootless by default.
  • A docker-compose file(s) that mounts a configuration file (if the configuration file is not added to the image), sets the entrypoint, command, environment variables and other things like volumes etc.

As I mentioned I'm in favour of the non-generic approach. Both will be easy to get started from a docker-compose perspective, but for the generic approach, moving it to another platform such as Kubernetes will require that the user always specifies things like command, entrypoint, custom configuration file etc. The non-generic approach will however provide a simpler setup process while still having the flexibility to override the defaults we set in the Dockerfile.

That said, I echo your notion that this should not block @hadrianvalentine too much. I'm okay with whatever we do but just dropping my opinion!

@hadrianvalentine
Copy link
Copy Markdown
Contributor Author

I should've explained where I think this should go in light of King's initial suggestion of being more generic. I don't think there's any reason we should be explicitly specifying the config location when Gemstash already has a sensible default. I was planning on mounting the config file to the appropriate default locations from a configmap. In the config map we would specify base_path which is what gemstash would use to store that data. If we do that we'll have a generic image that should just work and how we handle configuration will be more inline with what we're currently doing for other services.

@itskingori
Copy link
Copy Markdown
Member

I should've explained where I think this should go in light of King's initial suggestion of being more generic. I don't think there's any reason we should be explicitly specifying the config location when Gemstash already has a sensible default.

Ah, yes. That location is the default so it should Just Work™! 🤦🏽‍♂️ Then I think we're good to go!! 💪🏽

itskingori
itskingori previously approved these changes Sep 23, 2020
Comment thread app/config.yml.erb
@@ -1,33 +0,0 @@
:base_path: <%= "#{ENV['GEMSTASH_HOME']}/data" %>
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.

We should put this back.

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 is true!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

#7 (comment)
☝️ As suggested above, I was going to put it in the config map.

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.

Oops, I'm referring to the file itself.

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.

Right right! 🤕

Copy link
Copy Markdown
Member

@itskingori itskingori Sep 23, 2020

Choose a reason for hiding this comment

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

I blame the pain meds! 😅 Lemme take a step back.

Comment thread Dockerfile
@itskingori
Copy link
Copy Markdown
Member

I should've explained where I think this should go in light of King's initial suggestion of being more generic. I don't think there's any reason we should be explicitly specifying the config location when Gemstash already has a sensible default.

Ah, yes. That location is the default so it should Just Work™! 🤦🏽‍♂️ Then I think we're good to go!! 💪🏽

I take this back. I think the config file shouldn't have been deleted. We read envs through it.

@itskingori
Copy link
Copy Markdown
Member

Sorry @hadrianvalentine I feel like I've misled you a bit. 🙈 🙉 🙊

@hadrianvalentine
Copy link
Copy Markdown
Contributor Author

hadrianvalentine commented Sep 23, 2020

Sorry @hadrianvalentine I feel like I've misled you a bit. 🙈 🙉 🙊

I don't think so. Unless I'm missing something, we should be able to remove config here and specify it in our manifests instead.

@itskingori
Copy link
Copy Markdown
Member

itskingori commented Sep 23, 2020

I don't think so. Unless I'm missing something, we should be able to remove config here and specify it in our manifests instead.

Yeah. I think I'm responding too quickly without thinking everything through ... so gonna take a step back for now. 🙈

@zacblazic
Copy link
Copy Markdown
Member

zacblazic commented Sep 23, 2020

Sorry @hadrianvalentine I feel like I've misled you a bit. 🙈 🙉 🙊

I don't think so. Unless I'm missing something, we should be able to remove config here and specify it in our manifests instead.

We can't remove it from here without breaking docker-compose etc. IMO we should keep the config baked into the image and just override with a config map if necessary.

@hadrianvalentine
Copy link
Copy Markdown
Contributor Author

We can't remove it from here without breaking docker-compose etc. IMO we should keep the config baked into the image and just override with a config map if necessary.

Gemstash will revert to its default config. Gemstash isn't aware of that file unless you explicitly tell it to be. I've just build and run successfully using docker compose.

@hadrianvalentine
Copy link
Copy Markdown
Contributor Author

Perhaps we should remove volumes though to make it more generic?

@itskingori
Copy link
Copy Markdown
Member

Perhaps we should remove volumes though to make it more generic?

Agreed. I don't like image that specify VOLUME. Should be up to the user to mount a volume as they see fit.

@zacblazic
Copy link
Copy Markdown
Member

We can't remove it from here without breaking docker-compose etc. IMO we should keep the config baked into the image and just override with a config map if necessary.

Gemstash will revert to its default config. Gemstash isn't aware of that file unless you explicitly tell it to be. I've just build and run successfully using docker compose.

Could you post what the config looks like? I don't think it will support the environment variables we use in our compose files:

@hadrianvalentine
Copy link
Copy Markdown
Contributor Author

hadrianvalentine commented Sep 23, 2020

These appear to be the defaults for the version we're currently using unless a config file is present:
https://github.com/rubygems/gemstash/blob/v2.0.0/lib/gemstash/configuration.rb#L8-L18

I think the only thing we'd need to change is removing the volume from the dockerfile and the docker-compose files since the user should be able to specify their own volume location via config.

Thoughts?

@zacblazic
Copy link
Copy Markdown
Member

These appear to be the defaults for the version we're currently using unless a config file is present:
https://github.com/rubygems/gemstash/blob/v2.0.0/lib/gemstash/configuration.rb#L8-L18

Yeah, so the default one won't work with our docker-compose files in this repository. If we want to toss the config we need to toss the docker-compose files and remove references to them in the readme.

I think the only thing we'd need to change is removing the volume from the dockerfile and the docker-compose files since the user should be able to specify their own volume location via config.

Thoughts?

Don't mind removing the VOLUME from the Dockerfile, as for the docker-compose files, see above.

@hadrianvalentine
Copy link
Copy Markdown
Contributor Author

I've been thinking about this issue. I think there are two solutions to the compose file issue (aside from just deleting them):

I think quite like the docker configs approach because it means we can keep the images clean and not bake in unnecessary config. Thoughts?

@itskingori
Copy link
Copy Markdown
Member

I think quite like the docker configs approach because it means we can keep the images clean and not bake in unnecessary config. Thoughts?

I like the config approach too! If you're willing to give it a stab I'm ok with that.

@hadrianvalentine
Copy link
Copy Markdown
Contributor Author

Reverted changes to remove config from images as discussed in standup.

zacblazic
zacblazic previously approved these changes Sep 29, 2020
@hadrianvalentine
Copy link
Copy Markdown
Contributor Author

Update the changelog c2df0e9.

@hadrianvalentine hadrianvalentine merged commit 6bf18e9 into master Sep 29, 2020
@delete-merged-branch delete-merged-branch Bot deleted the use_config_file branch September 29, 2020 11:59
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.

3 participants