Skip to content

Commit

Permalink
Dev environment and prod Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdenio committed Aug 20, 2021
1 parent 2ba4ae3 commit 9a1ddf4
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 1 deletion.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM rust:1.54 AS builder

ARG DATABASE_URL

WORKDIR /usr/src/app

COPY . .

RUN cargo build --release

RUN cargo install diesel_cli --no-default-features --features postgres
RUN diesel migration run

FROM debian:buster AS runner

WORKDIR /usr/src/app

RUN apt-get update -y && apt-get install -y libssl1.1 libpq5

COPY --from=builder /usr/src/app/target/release/haas_api .
COPY --from=builder /usr/src/app/rocket.toml .
COPY --from=builder /usr/src/app/openapi/openapi.yaml ./openapi/openapi.yaml

CMD ["./haas_api"]
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
# api
# Hack as a Service API

## Running locally

1. Install [Docker](https://docker.com) and Docker Compose.
2. Run `docker-compose up -d` to start up your development instance.
3. Run `docker-compose exec main diesel migration run` to update the database (you only need to run this once, unless you modify the database schema)
4. Visit http://localhost:3000

Other commands:

- `docker-compose logs -f main` streams logs from the Rocket app
- `docker-compose exec db psql -U postgres` opens a shell into the PostgreSQL database
- `docker-compose stop` stops the dev environment
13 changes: 13 additions & 0 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM rust:1.54

WORKDIR /usr/src/app

COPY . .

RUN cargo install diesel_cli --no-default-features --features postgres && \
cargo install cargo-watch

# Dummy build to fetch/compile dependencies
RUN cargo build

CMD ["cargo", "watch", "-x", "run"]
21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: "3"
services:
main:
build:
context: .
dockerfile: dev.Dockerfile
volumes:
- .:/usr/src/app
environment:
ROCKET_DATABASES: '{db = {url = "postgres://postgres:postgres@db:5432/postgres"}}'
DATABASE_URL: postgres://postgres:postgres@db:5432/postgres
ports:
- 3000:3000
db:
image: postgres:alpine
environment:
POSTGRES_PASSWORD: postgres
volumes:
- db_volume:/var/lib/postgresql/data
volumes:
db_volume:
1 change: 1 addition & 0 deletions rocket.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[default]
address = "0.0.0.0"
port = 3000

[global.databases]
Expand Down

0 comments on commit 9a1ddf4

Please sign in to comment.