Skip to content

Commit 027bc36

Browse files
author
Steve Manuel
committed
dev: support DEV_DOCKER env var and document usage
1 parent 9689eed commit 027bc36

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

.env.sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Toggle for server configuration in development when using Docker.
2+
export DEV_DOCKER=1
3+
14
# Location of the *postgres* database. For example, if you have created a
25
# blank database locally named `cargo_registry`, this would be
36
# `postgres://postgres@localhost/cargo_registry`.

docs/CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,9 @@ one go:
512512
docker-compose up -d
513513
```
514514
515+
> **Note:** set `DEV_DOCKER=1` in a `.env` or `docker-compose.override.yml`
516+
file when working with Docker in development.
517+
515518
The Compose file is filled out with a sane set of defaults that should Just
516519
Work™ out of the box without any modification. Individual settings can be
517520
overridden by creating a `docker-compose.override.yml` with the updated config.
@@ -525,8 +528,12 @@ services:
525528
environment:
526529
GH_CLIENT_ID: blahblah_ID
527530
GH_CLIENT_SECRET: blahblah_secret
531+
DEV_DOCKER: 1
528532
```
529533

534+
These environment variables can also be defined in a local `.env` file, see `.env.sample`
535+
for various configuration options.
536+
530537
#### Accessing services
531538

532539
By default, the services will be exposed on their normal ports:

src/bin/server.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
6060

6161
let heroku = dotenv::var("HEROKU").is_ok();
6262
let fastboot = dotenv::var("USE_FASTBOOT").is_ok();
63+
let dev_docker = dotenv::var("DEV_DOCKER").is_ok();
6364

65+
let ip = if dev_docker {
66+
[0, 0, 0, 0]
67+
} else {
68+
[127, 0, 0, 1]
69+
};
6470
let port = if heroku {
6571
8888
6672
} else {
@@ -103,7 +109,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
103109
async move { Service::from_blocking(handler, addr) }
104110
});
105111

106-
let addr = ([0, 0, 0, 0], port).into();
112+
let addr = (ip, port).into();
107113
#[allow(clippy::async_yields_async)]
108114
let server = rt.block_on(async { hyper::Server::bind(&addr).serve(make_service) });
109115

0 commit comments

Comments
 (0)