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

Add docker to all components. #1

Merged
merged 4 commits into from
Jan 22, 2025
Merged

Add docker to all components. #1

merged 4 commits into from
Jan 22, 2025

Conversation

sennav
Copy link
Contributor

@sennav sennav commented Jan 21, 2025

Hey Katie,

First of all, thank you for the presentation, I saw it on Youtube a few days ago and got inspired to try out myself. It would be really fun to build an engine in Rust that could be like a lambda runner and that's what I plan to try out in the future. I just have to learn from your code and learn more Rust before (pretty much a Rust n00b here 🐣).

While running your code I made some modifications to make it easier to run it locally, I pretty much added everything to containers so you can just run docker compose -f docker-compose.yaml up and it should just work™. I haven't changed any documentation yet since maybe you'll have feedback on the code and I'd have to change the code plus documentation, and I'm lazy. I can make another commit with the docs later. There are some things I am unsure if you want to keep separate somehow since you run this code on some server, I'm mainly thinking about having the certs on the backend image, maybe there could be production image and a local dev one, not sure about that.

I also have been considering changing the game to the prisioner's game, Derek Muller from Veritassium made a really nice video about it and this seems like a perfect project to implement bots for it (it also goes well with the title of your presentation, maybe 😅). Ofc this could be a separate repo altogether.

Let me know if you have any questions or feedback, have a good one.

* Introduce a postgres docker container.
* Introduce a docker container to the client (via nginx).
* Introuce a docker container with minio to replace S3 in a local setup.
* Creates a script to generate a dummy cert file (satisfies the image
  generation requirement but not used on local development due to
  missing env variables).
@@ -6,7 +6,7 @@
"dependencies": {
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@g-loot/react-tournament-brackets": "^1.0.30",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems to be deprecated.

"packageManager": "[email protected]",
"overrides": {
"react-tournament-brackets": {
"styled-components": "$styled-components"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe I had to bump styled-components for some reason or the npm version I'm using is detecting that it conflicts with the version styled-components required from react-tournament-brackets. This seems to work anyway.

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, seems to be a version mismatch in the devdependencies not the dependencies that matter. I might look into resolving this but it's fine. :)

# Clean up the temporary files
rm -f "$KEY_FILE" "$CERT_FILE"

echo "Certificate and key have been successfully combined into '$OUTPUT_FILE'."
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just generates a dummy cert to satisfy the need for a cert in the backend Dockerfile.

Copy link
Owner

Choose a reason for hiding this comment

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

Appreciate you going to the effort here to maintain the existing Dockerfile, but the cert shouldn't be needed for local dev, it's only there for the prod version because I deploy to AWS RDS.

If we modify the Dockerfile to look like this (replace three COPY lines with two):

COPY --from=builder /app/target/release/wasi-runner ./
COPY --from=builder /app/*.wasm /app/database_cert*.pem ./

Then it'll copy the database_cert.pem if it's there and ignore it if it's not and you shouldn't need to generate a cert. (If you prefer to use this generate script then that's also fine, happy to accept it, I just think it's unnecessary).

Also... just a quick side note, you may have noticed that the docker build is hella slow. It wasn't written for local dev, so it's not broken down into nice layers that cache well. I imagine rebuilding it each time you make a change takes a looong time. I can look into making it faster if that'd be helpful to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, I removed it as you suggested. Yeah I noticed it is pretty slow too it will be nice to speed that up.

@@ -1,7 +1,4 @@
DROP TABLE IF EXISTS bots;
DROP USER IF EXISTS snippyuser;

CREATE USER snippyuser WITH PASSWORD 'snippy123';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This might disrupt some of your flow but with the containerized version of postgres the user gets created via env variables.

Copy link
Owner

Choose a reason for hiding this comment

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

I have a mild preference to keep snippyuser and the root postgres user separate from each other (so that the permissions for snippyuser can be kept to a minimum), but honestly, either way is fine. :)

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 point, adopted your suggestion.

_ => {
S3Client::new(&shared_config)
}
};
Copy link
Contributor Author

@sennav sennav Jan 21, 2025

Choose a reason for hiding this comment

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

Uses minio for development purposes instead of S3.

@katharosada
Copy link
Owner

Oh, this looks great, thats a big improvement! Thank you so much for contributing this! I'll give it a go on my machine to check it out.

Copy link
Owner

Choose a reason for hiding this comment

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

I've been using yarn so ideally there shouldn't be an npm-style package-lock.json, just the yarn.lock file. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was confused by the client README which mentioned npm, I've changed all to yarn now.

COPY ./ .

RUN npm install
RUN npm run build
Copy link
Owner

Choose a reason for hiding this comment

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

Could we change this to use yarn install and yarn build?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

# Clean up the temporary files
rm -f "$KEY_FILE" "$CERT_FILE"

echo "Certificate and key have been successfully combined into '$OUTPUT_FILE'."
Copy link
Owner

Choose a reason for hiding this comment

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

Appreciate you going to the effort here to maintain the existing Dockerfile, but the cert shouldn't be needed for local dev, it's only there for the prod version because I deploy to AWS RDS.

If we modify the Dockerfile to look like this (replace three COPY lines with two):

COPY --from=builder /app/target/release/wasi-runner ./
COPY --from=builder /app/*.wasm /app/database_cert*.pem ./

Then it'll copy the database_cert.pem if it's there and ignore it if it's not and you shouldn't need to generate a cert. (If you prefer to use this generate script then that's also fine, happy to accept it, I just think it's unnecessary).

Also... just a quick side note, you may have noticed that the docker build is hella slow. It wasn't written for local dev, so it's not broken down into nice layers that cache well. I imagine rebuilding it each time you make a change takes a looong time. I can look into making it faster if that'd be helpful to you.

@@ -1,7 +1,4 @@
DROP TABLE IF EXISTS bots;
DROP USER IF EXISTS snippyuser;

CREATE USER snippyuser WITH PASSWORD 'snippy123';
Copy link
Owner

Choose a reason for hiding this comment

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

I have a mild preference to keep snippyuser and the root postgres user separate from each other (so that the permissions for snippyuser can be kept to a minimum), but honestly, either way is fine. :)

Adds react-svg-pan-zoom to dependencies as it was not being resolved as
a dependency of react-tournament-brackets.
Also improves startup sequence in the docker compose setup.
@katharosada
Copy link
Owner

This is great, I've tried it out locally and it all works for me. :) Definitely need to make that docker build faster though, oof.

@katharosada katharosada merged commit 0ecfc11 into katharosada:main Jan 22, 2025
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