diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..342ee83 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +target/ +Dockerfile diff --git a/.gitignore b/.gitignore index 1fcf09e..230f12b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ **/*.rs.bk .idea config.toml + +# Remove Secrets +secrets/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4ba3602 --- /dev/null +++ b/Dockerfile @@ -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 + +# 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"] + diff --git a/Dockerfile.prod b/Dockerfile.prod new file mode 100644 index 0000000..8866819 --- /dev/null +++ b/Dockerfile.prod @@ -0,0 +1,10 @@ +FROM rust:1.36 + +WORKDIR /app/spamwatch-api + +COPY ./ /app/spamwatch-api + +RUN cargo build --release + +CMD ["cargo", "run"] + diff --git a/README.md b/README.md new file mode 100644 index 0000000..d350292 --- /dev/null +++ b/README.md @@ -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] +``` + diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000..e75dbdd --- /dev/null +++ b/docker-compose.prod.yml @@ -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' + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..41872ba --- /dev/null +++ b/docker-compose.yml @@ -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 + diff --git a/example.config.toml b/example.config.toml index c06f536..233dc66 100644 --- a/example.config.toml +++ b/example.config.toml @@ -5,6 +5,13 @@ masterid = 777000 [database] host = "127.0.0.1" +port = 5432 password = "password" username = "SpamWatchAPI" name = "SpamWatchAPI" + +[server] +# this is required for docker containers, to be available from +# bridge, for any exposed port +host = "0.0.0.0" +port = 6345