-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhancement: Adds runbook for deployment of the refactor platform.
- Loading branch information
1 parent
643f1f9
commit 276c150
Showing
12 changed files
with
874 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
/target | ||
dbml-error.log | ||
|
||
# Mac OS files | ||
.DS_Store | ||
|
||
# workspace files | ||
*.code-workspace | ||
.vscode/ | ||
|
||
# environment files | ||
.env* |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Stage 1: Build Stage | ||
FROM rust:latest AS builder | ||
|
||
# Set the working directory inside the container | ||
WORKDIR /usr/src/app | ||
|
||
# Install necessary packages | ||
RUN apt-get update && apt-get install -y \ | ||
bash \ | ||
build-essential \ | ||
libssl-dev \ | ||
pkg-config \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Install the necessary Rust target for ARM64 (Raspberry Pi 5) | ||
RUN rustup target add aarch64-unknown-linux-gnu | ||
|
||
# Copy the main workspace Cargo.toml and Cargo.lock to define workspace structure | ||
COPY Cargo.toml Cargo.lock ./ | ||
|
||
# Copy each module's Cargo.toml to maintain the workspace structure | ||
COPY ./entity/Cargo.toml ./entity/Cargo.toml | ||
COPY ./entity_api/Cargo.toml ./entity_api/Cargo.toml | ||
COPY ./migration/Cargo.toml ./migration/Cargo.toml | ||
COPY ./service/Cargo.toml ./service/Cargo.toml | ||
COPY ./web/Cargo.toml ./web/Cargo.toml | ||
|
||
# Copy the complete source code into the container's working directory | ||
COPY . . | ||
|
||
# Set the target directory to ensure binaries are placed in a known location | ||
#ENV CARGO_TARGET_DIR=/usr/src/app/target/aarch64-unknown-linux-gnu/release | ||
|
||
# Build the project | ||
RUN cargo build --release --workspace | ||
|
||
# logs the contents of the /usr/src/app directory to the docker build log and outputs them to the console | ||
RUN ls -la /usr/src/app/target/release/ | ||
|
||
RUN file /usr/src/app/target/release/* | ||
|
||
# Stage 2: Runtime Stage | ||
FROM debian:stable-slim AS runtime | ||
|
||
# Install necessary runtime dependencies | ||
RUN apt-get update && apt-get install -y \ | ||
libssl3 \ | ||
libpq5 \ | ||
postgresql-client-15 \ | ||
bash \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Set the working directory | ||
WORKDIR /usr/src/app | ||
|
||
# Copy the compiled binaries from the builder stage | ||
COPY --from=builder /usr/src/app/target/release/refactor_platform_rs /usr/local/bin/refactor_platform_rs | ||
COPY --from=builder /usr/src/app/target/release/migration /usr/local/bin/migration | ||
COPY --from=builder /usr/src/app/target/release/seed_db /usr/local/bin/seed_db | ||
|
||
# Create a non-root user for running the application | ||
RUN useradd -m appuser && \ | ||
chown -R appuser:appuser /usr/src/app /usr/local/bin && \ | ||
chmod +x /usr/local/bin/* | ||
|
||
# Switch to the non-root user | ||
USER appuser | ||
|
||
# Expose the necessary ports | ||
EXPOSE 4000 | ||
|
||
# Default command starts an interactive bash shell | ||
# Set ENTRYPOINT to default to run the Rust binary with arguments | ||
ENTRYPOINT ["/bin/bash", "-c", "/usr/local/bin/refactor_platform_rs -l DEBUG -i \"$SERVICE_INTERFACE\" -p \"$SERVICE_PORT\" -d \"$DATABASE_URL\""] | ||
|
||
# Default CMD allows overriding with custom commands | ||
CMD ["bash"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
services: | ||
# Local PostgreSQL container (used for local development when needed) | ||
postgres: | ||
image: postgres:17 # Use PostgreSQL version 17 | ||
container_name: postgres # Name the container "postgres" | ||
environment: | ||
POSTGRES_USER: ${POSTGRES_USER} # Set PostgreSQL user from environment variable | ||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} # Set PostgreSQL password from environment variable | ||
POSTGRES_DB: ${POSTGRES_DB} # Set PostgreSQL database name from environment variable | ||
ports: | ||
- "${POSTGRES_PORT}:5432" # Map host port to container's PostgreSQL port | ||
volumes: | ||
- postgres_data:/var/lib/postgresql/data # Persist PostgreSQL data | ||
- ./migration/src/setup.sql:/docker-entrypoint-initdb.d/0-setup.sql # Initialize database with setup.sql | ||
- ./migration/src/refactor_platform_rs.sql:/docker-entrypoint-initdb.d/1-refactor_plaform_rs.sql # Initialize with refactor_platform_rs.sql | ||
networks: | ||
- backend_network # Connect to backend_network | ||
|
||
# Rust application that connects to either local or remote PostgreSQL | ||
rust-app: | ||
image: rust-backend # Use the built image | ||
build: | ||
context: . # Build context is current directory | ||
dockerfile: Dockerfile # Use specified Dockerfile | ||
target: runtime # Use runtime target | ||
platform: linux/arm64 # Specify the platform | ||
container_name: rust-app # Name the container "rust-app" | ||
environment: | ||
POSTGRES_USER: ${POSTGRES_USER} # Set PostgreSQL user from environment variable | ||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} # Set PostgreSQL password from environment variable | ||
POSTGRES_DB: ${POSTGRES_DB} # Set PostgreSQL database name from environment variable | ||
POSTGRES_SCHEMA: ${POSTGRES_SCHEMA} # Set PostgreSQL schema from environment variable | ||
POSTGRES_HOST: postgres # Set PostgreSQL host to "postgres" service | ||
POSTGRES_PORT: ${POSTGRES_PORT} # Set PostgreSQL port from environment variable | ||
DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:${POSTGRES_PORT}/${POSTGRES_DB} # Configure database URL | ||
SERVICE_PORT: ${SERVICE_PORT} # Set service port from environment variable | ||
SERVICE_INTERFACE: ${SERVICE_INTERFACE} # Set service interface from environment variable | ||
ports: | ||
- "${SERVICE_PORT}:${SERVICE_PORT}" # Map host port to container's service port | ||
depends_on: | ||
- postgres # Ensure postgres service starts before rust-app | ||
networks: | ||
- backend_network # Connect to backend_network | ||
command: ["sh", "-c", "sleep 5 && /usr/local/bin/refactor_platform_rs"] # Wait for Postgres and run the app | ||
|
||
networks: | ||
backend_network: | ||
driver: bridge # Use bridge network driver | ||
|
||
volumes: | ||
postgres_data: # Define postgres_data volume |
Oops, something went wrong.