-
Notifications
You must be signed in to change notification settings - Fork 30
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
Allow setting UI and API ports via env var #7
Conversation
On my machine, running with rootless docker the default values (not copying .env.sample to .env) results in the following output:
|
Running on this branch with the following values for my .env file results in the following:
Abridged output from yew-ui (last few lines):
Abridged output from actix-api (last few lines):
|
@darioalessandro let me know if you'd like the Postgres port parametrized as well. Wasn't as big a priority for me because it wasn't running on a privileged port, but might as well since I did the actix API port and that wasn't running on anything privileged either. |
const ACTIX_PORT: &str = std::env!("ACTIX_PORT"); | ||
const UI_PORT: &str = std::env!("TRUNK_SERVE_PORT"); | ||
const UI_HOST: &str = std::env!("TRUNK_SERVE_HOST"); | ||
const AFTER_LOGIN_URL: &'static str = concat!("http://localhost:", std::env!("TRUNK_SERVE_PORT")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I felt kinda iffy about this line (specifically having to repeat the same std::env expression on lines 29 and 31), but it was the most concise-looking way I found to append TRUNK_SERVE_PORT to a string slice after a brief bit of googling. Let me know if there's a better way or if you prefer the accepted answer from that stack overflow post, I'm still very much a Rust newbie.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imo this is fine.
- ACTIX_PORT=8080 | ||
- TRUNK_SERVE_PORT=80 | ||
- ACTIX_PORT=${ACTIX_PORT:-8080} | ||
- TRUNK_SERVE_PORT=${TRUNK_SERVE_PORT:-80} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@resnickmicah this is awesome!!
I did not know you could provide defaults like this!!!
ports: | ||
- "80:80" | ||
- "${TRUNK_SERVE_PORT:-80}:${TRUNK_SERVE_PORT:-80}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yaaaaas!!
- RUST_LOG=info | ||
- PG_URL=postgres://postgres:docker@postgres:5432/actix-api-db?sslmode=disable | ||
ports: | ||
- "8080:8080" | ||
- "${ACTIX_PORT:-8080}:${ACTIX_PORT:-8080}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat!!
const ACTIX_PORT: &str = std::env!("ACTIX_PORT"); | ||
const UI_PORT: &str = std::env!("TRUNK_SERVE_PORT"); | ||
const UI_HOST: &str = std::env!("TRUNK_SERVE_HOST"); | ||
const AFTER_LOGIN_URL: &'static str = concat!("http://localhost:", std::env!("TRUNK_SERVE_PORT")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imo this is fine.
Make sure the UI and API respect any values set for
ACTIX_PORT
andTRUNK_SERVE_PORT
. Have these values default to ACTIX_PORT=8080 and TRUNK_SERVE_PORT=80 in the absence of any .env file.