-
Notifications
You must be signed in to change notification settings - Fork 7
[Feat] Easy setup for Postgre on Linux with Docker #2
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| target/ | ||
| Dockerfile |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,6 @@ | |
| **/*.rs.bk | ||
| .idea | ||
| config.toml | ||
|
|
||
| # Remove Secrets | ||
| secrets/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # This is dev version to make the Cargo builds fast and should re-build and run the whole | ||
| # app everytime the container is restarted, as Rust doesn't has a proper way of hot reloading | ||
|
|
||
| # Keeping Rust to it's latest version for having the latest Rust Dependency. | ||
| # Once async/await is introduced, we can hard-code the version. | ||
| FROM rust:latest | ||
|
|
||
| WORKDIR /app/spamwatch-api | ||
|
|
||
| COPY . /app/spamwatch-api | ||
|
|
||
phoenisx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # This will cache the library builds, which will ultimately help in | ||
| # re-running our apps faster. | ||
| RUN cargo build | ||
|
|
||
| ENV RUST_BACKTRACE 1 | ||
|
|
||
| CMD ["cargo", "run"] | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you have two Dockerfiles? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, to separate out deployment logics for production and dev builds. Having two separate ways of deployment, helps you manage separate concerns. For eg, in production build, you can remove the source code (atleast for Rust, as you will get a compiled binary, to reduce the docker image size), that got copied earlier. Also, it helps to keep different rust versions, till the dev is properly tested and can be deployed to Production. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also check this - https://users.rust-lang.org/t/why-does-cargo-build-not-optimise-by-default/4150 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still not sure I like it... there has to be a cleaner way to do this...make an env var or something and a script? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can understand your concern, and keeping things DRY, but if docker commands varies (like for dev and prod), we need separate Not sure if env vars can be used in images (as in used in Docker Commands), but even if they did, they will make Docker images in-consistent. What I can think of is, Docker itself acts as an environment specific deployment strategy (just like envs). Each Environment having it's own set of deployment instructions, unless some environments have to be deployed with the exact same build, (like staging/prod can have a single Docker file). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose. Also |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| FROM rust:1.36 | ||
|
|
||
| WORKDIR /app/spamwatch-api | ||
|
|
||
| COPY ./ /app/spamwatch-api | ||
|
|
||
| RUN cargo build --release | ||
|
|
||
| CMD ["cargo", "run"] | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # SpamWatchAPI | ||
|
|
||
| API server for SpamWatch | ||
|
|
||
| ## Running via Docker | ||
|
|
||
| Before running `docker-compose` please make sure you have added: | ||
| * Postgres password in `/secrets/.postgres-passwd` | ||
| * Create `config.toml` from `example.config.toml`. | ||
| - Do change the hostname for [database] config to `host = "postgres"` | ||
|
|
||
| ``` | ||
| docker-compose up [-d] | ||
| ``` | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| version: "3.7" | ||
|
|
||
| secrets: | ||
| postgres_passwd: | ||
| file: ./secrets/.postgres-passwd | ||
|
|
||
| services: | ||
| postgres: | ||
| image: postgres:11.4-alpine | ||
| # for production we don't need to expose ports | ||
| - '5432' | ||
| secrets: | ||
| - postgres_passwd | ||
| environment: | ||
| POSTGRES_USER: SpamWatchAPI | ||
| POSTGRES_DB: SpamWatchAPI | ||
| POSTGRES_PASSWORD_FILE: /run/secrets/postgres_passwd | ||
| api: | ||
| build: | ||
| context: ./ | ||
| dockerfile: Dockerfile | ||
| ports: | ||
| - '6345:6345' | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| version: "3.7" | ||
|
|
||
| secrets: | ||
| postgres_passwd: | ||
| file: ./secrets/.postgres-passwd | ||
|
|
||
| services: | ||
| postgres: | ||
| image: postgres:11.4-alpine | ||
| # for production we can remove this exposed ports, as it helps in security | ||
| # while debugging for db in prod, should be done via a client container. | ||
| ports: | ||
| - '5432:5432' | ||
| secrets: | ||
| - postgres_passwd | ||
| environment: | ||
| POSTGRES_USER: SpamWatchAPI | ||
| POSTGRES_DB: SpamWatchAPI | ||
| POSTGRES_PASSWORD_FILE: /run/secrets/postgres_passwd | ||
| api: | ||
| build: | ||
| context: ./ | ||
| dockerfile: Dockerfile | ||
| depends_on: | ||
| - postgres | ||
| ports: | ||
| - '6345:6345' | ||
| volumes: | ||
| - ${PWD}:/app/spamwatch-api | ||
|
|
Uh oh!
There was an error while loading. Please reload this page.