Skip to content

Commit

Permalink
Action to publish docker image (#121)
Browse files Browse the repository at this point in the history
Fixes #93

I have already tested the code of this Pull Request in my own namespace. For details, please see this URL: https://github.com/DCjanus/cargo-machete/pkgs/container/cargo-machete
  • Loading branch information
DCjanus authored May 31, 2024
1 parent 797aee6 commit 5b91043
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
/**/target
48 changes: 47 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
jobs:
ci:
env:
RUST_BACKTRACE: 1
RUST_BACKTRACE: 1
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<a href="https://github.com/bnjbvr/cargo-machete/actions?query=workflow%3ARust"><img src="https://github.com/bnjbvr/cargo-machete/workflows/Rust/badge.svg" alt="build status" /></a>
<a href="https://matrix.to/#/#cargo-machete:delire.party"><img src="https://img.shields.io/badge/matrix-join_chat-brightgreen.svg" alt="matrix chat" /></a>
<img src="https://img.shields.io/badge/rustc-stable+-green.svg" alt="supported rustc stable" />
<a href="https://deps.rs/repo/github/bnjbvr/cargo-machete"><img src="https://deps.rs/repo/github/bnjbvr/cargo-machete/status.svg" alt="dependency status"/></a>
</p>
</div>

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 5b91043

Please sign in to comment.