diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6f314b9..d900789 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -14,28 +14,10 @@ jobs: build: runs-on: ubuntu-latest # Use Ubuntu for building the project - strategy: - matrix: - target: [x86_64-unknown-linux-gnu] - steps: - name: Checkout repository uses: actions/checkout@v4 - - name: Set up Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - target: ${{ matrix.target }} - override: true - - - name: Install cross (for cross-compilation) - run: cargo install cross --version 0.2.5 - - - name: Build project - run: cross build --target ${{ matrix.target }} --release - - uses: docker/login-action@v3 with: registry: ghcr.io diff --git a/Dockerfile b/Dockerfile index bf24a3b..57fba2c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,32 @@ +# Stage 1: Build the Rust binaries FROM docker.io/rust:1-slim-bookworm as cargo-build WORKDIR /src/ # Install dependencies RUN --mount=type=cache,target=/var/cache/apt,sharing=locked apt-get update && \ - apt-get install -y git libssl-dev pkg-config git + apt-get install -y git libssl-dev pkg-config -# Copy the binary from the `cross` build (adjust the path to your binary) -COPY target/x86_64-unknown-linux-gnu/release/data-migration /app/data-migration +# Copy the source code into the container +COPY . . + +# Build the application +RUN --mount=type=cache,target=/usr/local/cargo/registry --mount=type=cache,target=/src/target \ + CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --release + +# Stage 2: Create an intermediate image for dependencies +FROM docker.io/debian:bookworm-slim as intermediate +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked apt-get update && \ + apt-get install -y ca-certificates tini gettext-base && \ + apt-get clean + +# Stage 3: Create the final image +FROM intermediate as final +RUN apt-get update && \ + apt-get install -y build-essential cmake git zlib1g-dev libelf-dev libdw-dev libboost-dev libboost-iostreams-dev libboost-program-options-dev libboost-system-dev libboost-filesystem-dev libunwind-dev libzstd-dev git +COPY --from=cargo-build /src/target/release/data-migration /usr/local/bin/data-migration # Ensure the binary is executable -RUN chmod +x /app/data-migration +RUN chmod +x /usr/local/bin/data-migration -# Set the binary as the entrypoint -ENTRYPOINT ["/app/data-migration"] +# Set the entrypoint for the container +ENTRYPOINT ["/usr/local/bin/data-migration"]