Skip to content

Commit

Permalink
Adding option to build ARM based image
Browse files Browse the repository at this point in the history
  • Loading branch information
ajvn authored and matze committed Jul 10, 2024
1 parent 000d30f commit 6953eb5
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Dockerfile.arm
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# --- build image
FROM rust:1.75 AS builder

RUN rustup target add aarch64-unknown-linux-musl && \
apt-get update && \
apt-get install -y musl-tools musl-dev && \
update-ca-certificates

ENV USER=app
ENV UID=10001

RUN adduser \
--disabled-password \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"

WORKDIR /app
COPY . .
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/app/target \
cargo build --release && mv /app/target/release/wastebin /app

FROM scratch

COPY --from=builder /lib/aarch64-linux-gnu/libgcc_s.so.1 /lib/aarch64-linux-gnu/libgcc_s.so.1
COPY --from=builder /lib/aarch64-linux-gnu/libm.so.6 /lib/aarch64-linux-gnu/libm.so.6
COPY --from=builder /lib/aarch64-linux-gnu/libc.so.6 /lib/aarch64-linux-gnu/libc.so.6
COPY --from=builder /lib/ld-linux-aarch64.so.1 /lib/ld-linux-aarch64.so.1
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group

WORKDIR /app
COPY --from=builder /app/wastebin .
USER app:app
CMD ["/app/wastebin"]
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,46 @@ You can also download pre-built, statically compiled [Linux
binaries](https://github.com/matze/wastebin/releases). After extraction run the
contained `wastebin` binary.

### Build a container image

It's possible to build container image using Docker or Podman.

Assuming you're in the root directory of repository:
* Docker
```bash
$ sudo docker build \
-t wastebin:v2.4.3 \
-f Dockerfile .
```
* Podman
```bash
$ podman build \
-t wastebin:v2.4.3 \
-f Dockerfile
```

To cross-compile, make sure that your container engine of choice supports it,
e.g. Docker:
```bash
$ sudo docker buildx ls
NAME/NODE DRIVER/ENDPOINT STATUS BUILDKIT PLATFORMS
default* docker
\_ default \_ default running v0.14.1 linux/amd64, linux/amd64/v2, linux/386, linux/arm64, linux/riscv64, linux/ppc64, linux/ppc64le, linux/s390x, linux/mips64le, linux/mips64, linux/loong64, linux/arm/v7, linux/arm/v6
```

To compile arm64 image on x86_64(amd64) host:
* Docker
```bash
$ sudo docker build --platform linux/arm64 \
-t wastebin:v2.4.3-arm64 \
-f Dockerfile.arm .
```
* Podman
```bash
$ podman build --arch=arm64 \
-t wastebin:v2.4.3-arm64 \
-f Dockerfile.arm
```

### Run a Docker image

Expand Down

0 comments on commit 6953eb5

Please sign in to comment.