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

[WIP] Kamal deployment #1192

Draft
wants to merge 28 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f8b6f48
feat: add Kamal deployment support
yinho999 Jan 19, 2025
bcd0f87
Merge branch 'master' into kamal-deployment
yinho999 Jan 19, 2025
fbb3502
Merge branch 'master' into kamal-deployment
yinho999 Jan 19, 2025
e6bdeb0
Added test for postgres, sqlite without/with background queue with redis
yinho999 Jan 19, 2025
af50d5f
Added binding 0.0.0.0 to development.yaml
yinho999 Jan 19, 2025
328ccae
removed duplicated dockerfile
yinho999 Jan 20, 2025
60fca18
Merge branch 'master' into kamal-deployment
yinho999 Jan 25, 2025
db6cdfd
feat: add .dockerignore and improve deployment file generation
yinho999 Jan 25, 2025
04a1c4c
style: reorganize imports across multiple files
yinho999 Jan 25, 2025
a75bd59
style: reformat doc comments and reorganize imports
yinho999 Jan 25, 2025
2ec6d2a
feat: backup existing deployment files before generation
yinho999 Jan 26, 2025
e04c8b5
feat: add default development.yaml config to deployment tests
yinho999 Jan 26, 2025
efbd6cc
Merge branch 'master' into kamal-deployment
yinho999 Jan 26, 2025
e124196
style: improve code formatting and readability
yinho999 Jan 26, 2025
b974128
refactor: extract scaffold kind determination into separate function
yinho999 Jan 26, 2025
8b3c713
feat: add Kamal deployment support
yinho999 Jan 26, 2025
c35d27f
Merge branch 'master' into kamal-deployment
yinho999 Jan 26, 2025
5852120
refactor: update server binding configuration in deployment templates
yinho999 Jan 26, 2025
2604d33
Merge remote-tracking branch 'origin/kamal-deployment' into kamal-dep…
yinho999 Jan 26, 2025
52240c7
Merge branch 'master' into kamal-deployment
yinho999 Jan 27, 2025
0f98eb6
Merge branch 'master' into kamal-deployment
yinho999 Feb 1, 2025
c9bb3e6
refactor: restructure Kamal deployment configuration and improve code…
yinho999 Feb 1, 2025
f87081d
style: improve code formatting and organization
yinho999 Feb 1, 2025
6b9ead9
test: add Kamal deployment generation test
yinho999 Feb 1, 2025
d2767af
style: improve code organization and line wrapping
yinho999 Feb 1, 2025
c6fb232
fix: update Kamal secrets directory path to use dot prefix
yinho999 Feb 2, 2025
64f02e7
feat: add Kamal deployment support for Rails applications
yinho999 Feb 2, 2025
8eb8897
Merge branch 'master' into kamal-deployment
yinho999 Feb 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added binding 0.0.0.0 to development.yaml
yinho999 committed Jan 19, 2025
commit af50d5ff64dfa46585c559af4918176475a93f67
6 changes: 6 additions & 0 deletions loco-gen/src/templates/deployment/kamal/docker.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
to: "Dockerfile"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we not using the same docker template that we already have?

I don't think we need to hold two docker templates

Copy link
Contributor Author

@yinho999 yinho999 Jan 20, 2025

Choose a reason for hiding this comment

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

The current docker template has a different purpose than the one kamal one. As I can see the current dockerfile does not include sea orm and seems to be just compiling the binaries without running it. Not sure if I merge them or leave them separated.

Copy link
Contributor

Choose a reason for hiding this comment

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

The question is, why should SeaORM be included in this docker file.

Copy link
Contributor

Choose a reason for hiding this comment

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

We are using sea-orm-cli for generating entities. Why would you need to generate entities inside the Dockerfile?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My current dockerfile for kamal setup is serving the server within the container instead of just compiling, which requires database connection like sqlite or postgres. Therefore SeaOrm is kinda required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wait sea orm cli is not required for database connection? Okay I will remove it

Copy link
Contributor

Choose a reason for hiding this comment

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

Please check if you can use the current docker file and not create a new one

skip_exists: true
message: "Dockerfile generated successfully."

injections:
- into: config/development.yaml
after: " port: 5150"
content: " # Expose Server on all interfaces\n binding: 0.0.0.0"

---

FROM rust:1.84-slim as builder
84 changes: 77 additions & 7 deletions loco-gen/tests/templates/deployment.rs
Original file line number Diff line number Diff line change
@@ -197,7 +197,20 @@ fn can_generate_kamal_sqlite_without_background_queue() {
background_queue: false,
};

let tree_fs = tree_fs::TreeBuilder::default().drop(true).create().unwrap();
let tree_fs = tree_fs::TreeBuilder::default()
.drop(true)
.add(
"config/development.yaml",
r#"# Web server configuration
server:
# Port on which the server will listen. the server binding is 0.0.0.0:{PORT}
port: 5150
# The UI hostname or IP address that mailers will point to.
host: http://localhost
"#,
)
.create()
.unwrap();
let rrgen = RRgen::with_working_dir(&tree_fs.root);

let gen_result = generate(
@@ -217,6 +230,12 @@ fn can_generate_kamal_sqlite_without_background_queue() {
"
);

assert_snapshot!(
"inject[development.yaml]",
fs::read_to_string(tree_fs.root.join("config").join("development.yaml"))
.expect("development.yaml missing")
);

// Assert the generated Dockerfile content
assert_snapshot!(
"generate[kamal_dockerfile_sqlite]",
@@ -256,7 +275,20 @@ fn can_generate_kamal_sqlite_with_background_queue() {
background_queue: true,
};

let tree_fs = tree_fs::TreeBuilder::default().drop(true).create().unwrap();
let tree_fs = tree_fs::TreeBuilder::default()
.drop(true)
.add(
"config/development.yaml",
r#"# Web server configuration
server:
# Port on which the server will listen. the server binding is 0.0.0.0:{PORT}
port: 5150
# The UI hostname or IP address that mailers will point to.
host: http://localhost
"#,
)
.create()
.unwrap();
let rrgen = RRgen::with_working_dir(&tree_fs.root);

let gen_result = generate(
@@ -275,7 +307,11 @@ fn can_generate_kamal_sqlite_with_background_queue() {
* Secrets file generated successfully.
"
);

assert_snapshot!(
"inject[development.yaml]",
fs::read_to_string(tree_fs.root.join("config").join("development.yaml"))
.expect("development.yaml missing")
);
// Assert the generated Dockerfile content
assert_snapshot!(
"generate[kamal_dockerfile_sqlite_with_background_queue]",
@@ -315,7 +351,20 @@ fn can_generate_kamal_postgres_without_background_queue() {
background_queue: false,
};

let tree_fs = tree_fs::TreeBuilder::default().drop(true).create().unwrap();
let tree_fs = tree_fs::TreeBuilder::default()
.drop(true)
.add(
"config/development.yaml",
r#"# Web server configuration
server:
# Port on which the server will listen. the server binding is 0.0.0.0:{PORT}
port: 5150
# The UI hostname or IP address that mailers will point to.
host: http://localhost
"#,
)
.create()
.unwrap();
let rrgen = RRgen::with_working_dir(&tree_fs.root);

let gen_result = generate(
@@ -334,7 +383,11 @@ fn can_generate_kamal_postgres_without_background_queue() {
* Secrets file generated successfully.
"
);

assert_snapshot!(
"inject[development.yaml]",
fs::read_to_string(tree_fs.root.join("config").join("development.yaml"))
.expect("development.yaml missing")
);
// Assert the generated Dockerfile content
assert_snapshot!(
"generate[kamal_dockerfile_postgres_without_background_queue]",
@@ -374,7 +427,20 @@ fn can_generate_kamal_postgres_with_background_queue() {
background_queue: true,
};

let tree_fs = tree_fs::TreeBuilder::default().drop(true).create().unwrap();
let tree_fs = tree_fs::TreeBuilder::default()
.drop(true)
.add(
"config/development.yaml",
r#"# Web server configuration
server:
# Port on which the server will listen. the server binding is 0.0.0.0:{PORT}
port: 5150
# The UI hostname or IP address that mailers will point to.
host: http://localhost
"#,
)
.create()
.unwrap();
let rrgen = RRgen::with_working_dir(&tree_fs.root);

let gen_result = generate(
@@ -393,7 +459,11 @@ fn can_generate_kamal_postgres_with_background_queue() {
* Secrets file generated successfully.
"
);

assert_snapshot!(
"inject[development.yaml]",
fs::read_to_string(tree_fs.root.join("config").join("development.yaml"))
.expect("development.yaml missing")
);
// Assert the generated Dockerfile content
assert_snapshot!(
"generate[kamal_dockerfile_postgres_with_background_queue]",
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
source: loco-gen/tests/templates/deployment.rs
expression: "fs::read_to_string(tree_fs.root.join(\".kamal\").join(\"secrets\")).expect(\"secrets file missing\")"
---
# Secrets defined here are available for reference under registry/password, env/secret, builder/secrets,
# and accessories/*/env/secret in config/deploy.yml. All secrets should be pulled from either
# password manager, ENV, or a file. DO NOT ENTER RAW CREDENTIALS HERE! This file needs to be safe for git.

# Option 1: Read secrets from the environment
KAMAL_REGISTRY_PASSWORD=$KAMAL_REGISTRY_PASSWORD

# Option 2: Read secrets via a command
# RAILS_MASTER_KEY=$(cat config/master.key)

# Option 3: Read secrets via kamal secrets helpers
# These will handle logging in and fetching the secrets in as few calls as possible
# There are adapters for 1Password, LastPass + Bitwarden
#
# SECRETS=$(kamal secrets fetch --adapter 1password --account my-account --from MyVault/MyItem KAMAL_REGISTRY_PASSWORD RAILS_MASTER_KEY)
# KAMAL_REGISTRY_PASSWORD=$(kamal secrets extract KAMAL_REGISTRY_PASSWORD $SECRETS)
# RAILS_MASTER_KEY=$(kamal secrets extract RAILS_MASTER_KEY $SECRETS)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: loco-gen/tests/templates/deployment.rs
expression: "fs::read_to_string(tree_fs.root.join(\"config\").join(\"development.yaml\")).expect(\"development.yaml missing\")"
---
# Web server configuration
server:
# Port on which the server will listen. the server binding is 0.0.0.0:{PORT}
port: 5150
# Expose Server on all interfaces
binding: 0.0.0.0
# The UI hostname or IP address that mailers will point to.
host: http://localhost