diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d03f68d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +/target +/**/target diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2ef78b5..38c753f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,7 +12,7 @@ on: jobs: ci: env: - RUST_BACKTRACE: 1 + RUST_BACKTRACE: 1 runs-on: ubuntu-latest strategy: matrix: @@ -36,6 +36,52 @@ jobs: - run: cargo test --workspace --verbose + # Code from here: https://docs.github.com/en/actions/publishing-packages/publishing-docker-images + # TODO: Add a step to publish the image to the Docker Hub + # TODO: Build multiple images for different architectures, see this: https://docs.docker.com/build/ci/github-actions/multi-platform/ + # But follow this documentation would slow down the CI/CD pipeline, so it's better to use a matrix strategy + image: + concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + name: Build and push Docker image + if: | + github.event_name == 'push' && ( + github.event.ref == 'refs/heads/main' || + startsWith(github.event.ref, 'refs/tags/') + ) + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + attestations: write + steps: + - name: Check out the repo + uses: actions/checkout@v4 + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=ref,event=tag + type=raw,value=latest,enable={{is_default_branch}} + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + # Code mutably borrowed from https://github.com/EmbarkStudios/cargo-deny/, thanks Embark! release: name: Release diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3cd59e5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM rust:slim AS build + +COPY . /src +RUN cargo install --path /src --locked + +FROM debian:stable-slim + +COPY --from=build /usr/local/cargo/bin/cargo-machete /usr/local/bin + +WORKDIR /src +ENTRYPOINT ["cargo-machete"] \ No newline at end of file diff --git a/README.md b/README.md index fa5ca8d..95a3f8d 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ build status matrix chat supported rustc stable + dependency status

@@ -78,6 +79,16 @@ flag, which will call `cargo metadata --all-features` to find final dependency names, more accurate dependencies per build type, etc. ⚠ This may modify the `Cargo.lock` files in your projects. +## Docker Image + +A docker image for cargo machete. + +For instance, run `cargo-machete` in the `$(pwd)` directory using: + +``` +docker run -v $(pwd):/src ghcr.io/bnjbvr/cargo-machete:latest +``` + ## Cargo Machete Action A github action for cargo machete.