Skip to content

Commit

Permalink
feat(docker): add Docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Sep 11, 2024
1 parent cb5585d commit 95f3ffa
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 2 deletions.
14 changes: 14 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Directories
/.git/
/.github/
/target/
/website/

# Files
.editorconfig
.gitignore
*.md
codecov.yml
Dockerfile
LICENSE*
rustfmt.toml
87 changes: 87 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Docker

on:
push:
branches:
- main
tags:
- "v*.*.*"
pull_request:
branches:
- main
schedule:
- cron: "0 0 * * 0"

jobs:
docker:
name: Build and Push
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
orhunp/binsider
ghcr.io/${{ github.repository_owner }}/binsider
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=sha
type=raw,value=latest
type=semver,pattern={{version}}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: orhunp
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v6
with:
context: ./
file: ./Dockerfile
platforms: linux/amd64
builder: ${{ steps.buildx.outputs.name }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
sbom: true
provenance: true
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Scan the image
uses: anchore/sbom-action@v0
with:
image: ghcr.io/${{ github.repository_owner }}/binsider

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM rust:1.81-slim-bullseye as builder

Check warning on line 1 in Dockerfile

View workflow job for this annotation

GitHub Actions / Build and Push

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/
WORKDIR /src
COPY Cargo.toml Cargo.toml
COPY Cargo.lock Cargo.lock
RUN mkdir src/ && echo "fn main() {println!(\"failed to build\")}" > src/main.rs
RUN cargo build --release
RUN rm -f target/release/deps/binsider*
COPY . .
RUN cargo build --locked --release
RUN mkdir -p build-out/
RUN cp target/release/binsider build-out/

FROM debian:bullseye-slim as runner

Check warning on line 13 in Dockerfile

View workflow job for this annotation

GitHub Actions / Build and Push

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/
WORKDIR /app
COPY --from=builder /src/build-out/binsider .
USER 1000:1000
ENTRYPOINT ["./binsider"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ cargo install binsider
```

> [!NOTE]
> See the other [installation methods](https://binsider.dev/installation/crates-io/) 📦
> See the other [installation methods](https://binsider.dev/installation/other/) 📦
After the installation, you are pretty much set! 💯

Expand Down
22 changes: 22 additions & 0 deletions website/src/content/docs/installation/docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: Docker images
sidebar:
order: 6
---

Docker images are available at:

- [Docker Hub](https://hub.docker.com/r/orhunp/binsider)
- [GitHub Container Registry](https://github.com/orhun/binsider/pkgs/container/binsider)

You can use the following command to run the latest version of `binsider` in a container:

```bash
docker run --rm -it "orhunp/binsider:${TAG:-latest}"
```

To analyze a custom binary via mounting a volume:

```bash
docker run --rm -it -v "custom:/app/custom:rw" "orhunp/binsider:${TAG:-latest}" custom
```
2 changes: 1 addition & 1 deletion website/src/content/docs/installation/other.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Other methods
sidebar:
order: 6
order: 7
---

[![Packaging status](https://repology.org/badge/vertical-allrepos/binsider.svg)](https://repology.org/project/binsider/versions)
Expand Down

0 comments on commit 95f3ffa

Please sign in to comment.