Refactor Docker setup and update API description
- Updated docker-compose.yml to use context and dockerfile for the app service, and removed unnecessary db service configuration. - Modified Dockerfile to use the official Rust nightly image and streamlined the build process with updated working directories and runtime dependencies. - Changed API description in root handler to reflect the correct endpoint for fetching the current hospital.
This commit is contained in:
42
Dockerfile
42
Dockerfile
@@ -1,33 +1,35 @@
|
|||||||
FROM rust:1.76-slim-bullseye as builder
|
# Use the official Rust nightly image as a build environment
|
||||||
|
FROM rustlang/rust:nightly-slim as builder
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
# Install build dependencies
|
||||||
|
RUN apt-get update && apt-get install -y \
|
||||||
|
pkg-config \
|
||||||
|
libssl-dev \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Create a new empty shell project
|
||||||
|
WORKDIR /usr/src/hospitalapi
|
||||||
|
|
||||||
|
# Copy the source code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Build the application
|
# Build the application
|
||||||
RUN cargo build --release
|
RUN cargo build --release
|
||||||
|
|
||||||
# Create a new stage with a minimal image
|
# Use a minimal runtime image
|
||||||
FROM debian:bullseye-slim
|
FROM debian:bookworm-slim
|
||||||
|
|
||||||
WORKDIR /usr/local/bin
|
# Install runtime dependencies
|
||||||
|
RUN apt-get update && apt-get install -y \
|
||||||
# Install necessary runtime dependencies
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
|
libssl3 \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Copy the built binary from the builder stage
|
# Copy the binary from the builder stage
|
||||||
COPY --from=builder /usr/src/app/target/release/hospitalapi .
|
COPY --from=builder /usr/src/hospitalapi/target/release/hospitalapi /usr/local/bin/hospitalapi
|
||||||
|
|
||||||
# Create a directory for the .env file
|
# Set the working directory
|
||||||
RUN mkdir -p /usr/src/app
|
WORKDIR /usr/local/bin
|
||||||
WORKDIR /usr/src/app
|
|
||||||
|
|
||||||
# Copy the .env file
|
|
||||||
COPY .env .
|
|
||||||
|
|
||||||
# Expose the port the app runs on
|
|
||||||
EXPOSE 3000
|
|
||||||
|
|
||||||
# Run the application
|
# Run the application
|
||||||
CMD ["./hospitalapi"]
|
CMD ["hospitalapi"]
|
||||||
@@ -2,30 +2,13 @@ version: '3.8'
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
build: .
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "3000:3000"
|
||||||
depends_on:
|
|
||||||
- db
|
|
||||||
environment:
|
environment:
|
||||||
- DATABASE_URL=postgres://postgres:postgres@db/hospitaldb
|
- HOST=${HOST}
|
||||||
- HOST=0.0.0.0
|
- PORT=${PORT}
|
||||||
- PORT=3000
|
- DATABASE_URL=${DATABASE_URL}
|
||||||
volumes:
|
restart: unless-stopped
|
||||||
- ./.env:/usr/src/app/.env
|
|
||||||
restart: unless-stopped
|
|
||||||
|
|
||||||
db:
|
|
||||||
image: postgres:14
|
|
||||||
environment:
|
|
||||||
- POSTGRES_USER=postgres
|
|
||||||
- POSTGRES_PASSWORD=postgres
|
|
||||||
- POSTGRES_DB=hospitaldb
|
|
||||||
volumes:
|
|
||||||
- postgres_data:/var/lib/postgresql/data
|
|
||||||
ports:
|
|
||||||
- "5432:5432"
|
|
||||||
restart: unless-stopped
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
postgres_data:
|
|
||||||
@@ -12,7 +12,7 @@ pub async fn root_handler() -> Json<ApiInfo> {
|
|||||||
let info: ApiInfo = ApiInfo {
|
let info: ApiInfo = ApiInfo {
|
||||||
name: "HospitalAPI",
|
name: "HospitalAPI",
|
||||||
version: "0.1",
|
version: "0.1",
|
||||||
description: "This API provides you with the current hospital on duty in luxembourg city. Call the /getHospital endpoint.",
|
description: "This API provides you with the current hospital on duty in luxembourg city. Call the /current-hospital endpoint.",
|
||||||
};
|
};
|
||||||
Json(info)
|
Json(info)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user