Skip to content

Commit c108626

Browse files
Steve ManuelTurbo87
authored andcommitted
dev: support DEV_DOCKER env var and document usage
1 parent 8c8e8dd commit c108626

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
@@ -513,6 +513,9 @@ one go:
513513
docker-compose up -d
514514
```
515515
516+
> **Note:** set `DEV_DOCKER=1` in a `.env` or `docker-compose.override.yml`
517+
file when working with Docker in development.
518+
516519
The Compose file is filled out with a sane set of defaults that should Just
517520
Work™ out of the box without any modification. Individual settings can be
518521
overridden by creating a `docker-compose.override.yml` with the updated config.
@@ -526,8 +529,12 @@ services:
526529
environment:
527530
GH_CLIENT_ID: blahblah_ID
528531
GH_CLIENT_SECRET: blahblah_secret
532+
DEV_DOCKER: 1
529533
```
530534

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

533540
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)