Skip to content

Commit

Permalink
chore: update tokio to version 1.41.0 corrects binary location error …
Browse files Browse the repository at this point in the history
…so build succeeds
  • Loading branch information
lmcdonough committed Nov 7, 2024
1 parent c3dcabe commit bdaaa99
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 59 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 41 additions & 56 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,84 +1,69 @@
# Stage 1: Build Stage
FROM rust:latest AS builder

# Install necessary packages
RUN apt-get update && apt-get install -y bash build-essential && rm -rf /var/lib/apt/lists/*

# # Set the target for cross-compilation
# ENV CARGO_BUILD_TARGET=x86_64-unknown-linux-gnu

# # Install the necessary Rust target
# RUN rustup target add $CARGO_BUILD_TARGET

# Set the working directory inside the container
WORKDIR /usr/src/app

# Copy the root Cargo.toml and Cargo.lock to resolve dependencies
# Install necessary packages
RUN apt-get update && apt-get install -y \
bash \
build-essential \
libssl-dev \
pkg-config \
&& rm -rf /var/lib/apt/lists/*

# Copy the main workspace Cargo.toml and Cargo.lock to define workspace structure
# this is necessary to build all workspace members including seed_db
COPY Cargo.toml Cargo.lock ./

# Copy each crate's Cargo.toml for efficient caching
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 each module's Cargo.toml to maintain the workspace structure
# This ensures dependencies for each submodule are tracked accurately
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

# Create a dummy main.rs file for the root crate to build dependencies
RUN mkdir src && echo "fn main() {}" > src/main.rs
# Copy the complete source code into the container's working directory
# is includes the main src directory and the source files for each submodule
COPY . .

# Create dummy entry points for each sub-crate
# Use main.rs for binary crates and lib.rs for library crates
RUN mkdir -p entity/src && echo "// Dummy lib.rs for entity" > entity/src/lib.rs && \
mkdir -p entity_api/src && echo "// Dummy lib.rs for entity_api" > entity_api/src/lib.rs && \
mkdir -p service/src && echo "// Dummy lib.rs for service" > service/src/lib.rs && \
mkdir -p migration/src && echo "// Dummy lib.rs for migration" > migration/src/lib.rs && \
mkdir -p web/src && echo "fn main() {}" > web/src/lib.rs
# Set the target directory to ensure binaries are placed in a known location
# This helps Docker locate the binaries consistently
ENV CARGO_TARGET_DIR=/usr/src/app/target/release

# Build dependencies and cache them
RUN cargo build --release

# Remove dummy files to allow actual source code to be copied
RUN rm -f src/main.rs \
entity/src/lib.rs \
entity_api/src/lib.rs \
service/src/lib.rs \
migration/src/lib.rs \
web/src/main.rs

# Copy the full source code into the container
COPY . .

# Build the application in release mode for the specified target
RUN cargo build --release

# Stage 2: Runtime Stage
FROM debian:buster-slim

# Install necessary runtime dependencies
RUN apt-get update && apt-get install -y libssl1.1 libpq5 bash && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y \
libssl1.1 \
libpq5 \
bash \
&& rm -rf /var/lib/apt/lists/*

# Set the working directory
WORKDIR /app
WORKDIR /usr/src/app

# Copy the compiled binaries from the builder stage
COPY --from=builder /usr/src/app/target/release/refactor_platform_rs /app/
COPY --from=builder /usr/src/app/target/release/migration /app/
COPY --from=builder /usr/src/app/target/release/seed_db /app/
COPY --from=builder /usr/src/app/target/release/entity /app/
COPY --from=builder /usr/src/app/target/release/entity_api /app/
COPY --from=builder /usr/src/app/target/release/service /app/
COPY --from=builder /usr/src/app/target/release/web /app/

# Copy the rebuild_db.sh script
COPY scripts/rebuild_db.sh /app/scripts/rebuild_db.sh

# Ensure the script is executable
RUN chmod +x /app/scripts/rebuild_db.sh
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 /app && \
chmod +x /app/refactor_platform_rs /app/migration /app/seed_db /app/web /app/scripts/rebuild_db.sh
chown -R appuser:appuser /usr/src/app /usr/local/bin && \
chmod +x /usr/local/bin/*

# Copy the rebuild_db.sh script
COPY scripts/rebuild_db.sh /usr/src/app/scripts/rebuild_db.sh

# Ensure the script is executable and owned by appuser
RUN chmod +x /usr/src/app/scripts/rebuild_db.sh && \
chown appuser:appuser /usr/src/app/scripts/rebuild_db.sh

# Switch to the non-root user
USER appuser
Expand Down
2 changes: 1 addition & 1 deletion web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ features = [
"runtime-tokio-native-tls",
"sea-orm-internal",
"sqlx-postgres",
"with-uuid"
"with-uuid",
]

[features]
Expand Down

0 comments on commit bdaaa99

Please sign in to comment.