Skip to content

Create Dockerfile #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Before the docker CLI sends the context to the docker daemon, it looks for a file
# named .dockerignore in the root directory of the context. If this file exists, the
# CLI modifies the context to exclude files and directories that match patterns in it.
#
# You may want to specify which files to include in the context, rather than which
# to exclude. To achieve this, specify * as the first pattern, followed by one or
# more ! exception patterns.
#
# https://docs.docker.com/engine/reference/builder/#dockerignore-file

# Exclude everything:
#
*

# Now un-exclude required files and folders:
#
!.cargo
!*.toml
!*.lock
!zallet
46 changes: 46 additions & 0 deletions .github/workflows/build-and-push-docker-hub.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build and Push Docker Image to Docker Hub

on:
push:
tags:
- "v*.*.*"
workflow_dispatch:

permissions: {}

jobs:
set_env:
name: Create version tag
runs-on: ubuntu-latest
outputs:
tags: ${{ steps.version_step.outputs.tags }}
env:
VERSION: ${{ github.ref_name }}
SHA: ${{ github.sha }}
steps:
- id: version_step
run: |
set -Eeuo pipefail
IFS=$'\n\t'

if [[ "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-rc-[0-9]+)?$ ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need to be updated to support whatever pre-release scheme we end up using for the early Zallet alpha/beta/whatever, but it is sufficient for now.

echo "Valid version: $VERSION"
echo "tags=latest,$VERSION,$SHA" >> "$GITHUB_OUTPUT"
else
echo "Invalid ref_name format: $VERSION" >&2
exit 1
fi

build_push:
uses: zcash/.github/.github/workflows/build-and-push-docker-hub.yaml@main
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this doing? It looks recursive to me which makes no sense. Is this actually pulling from the zcash/zcash repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is the template we're using in Zcash and across several of our other repositories. - Just realized I missed updating a path — just fixed it now.

needs: set_env
with:
image_name: zallet
image_tags: ${{ needs.set_env.outputs.tags }}
dockerfile: Dockerfile
context: .
build-args: ""
secrets:
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub_password: ${{ secrets.DOCKERHUB_PASSWORD }}
dockerhub_registry: ${{ secrets.DOCKERHUB_REGISTRY }}
26 changes: 26 additions & 0 deletions .github/workflows/test-docker-container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build and Run Docker Container

on:
pull_request:
push:
branches: main

permissions: {}

jobs:
build_and_run:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Build Docker image
run: |
docker build -t zallet .

- name: Run command inside Docker container
run: |
docker run --rm zallet -h
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# syntax=docker/dockerfile:1
# --- Stage 1: Build with Rust --- (amd64) (RUST version: 1.86.0)
FROM rust:1.86.0-slim@sha256:57d415bbd61ce11e2d5f73de068103c7bd9f3188dc132c97cef4a8f62989e944 AS builder

WORKDIR /app

RUN apt-get update && \
apt-get install -y --no-install-recommends \
clang \
libclang-dev \
pkg-config \
git && \
rm -rf /var/lib/apt/lists/*

COPY --link . .

# Build the zallet binary
# Leverage a cache mount to ${CARGO_HOME} for downloaded dependencies,
# and a cache mount to ${CARGO_TARGET_DIR} for compiled dependencies.
RUN --mount=type=bind,source=zallet,target=zallet \
--mount=type=bind,source=Cargo.toml,target=Cargo.toml \
--mount=type=bind,source=Cargo.lock,target=Cargo.lock \
--mount=type=cache,target=/app/.cargo \
--mount=type=cache,target=/app/target/ \
cargo build --locked --release --package zallet --bin zallet && \
cp /app/target/release/zallet /usr/local/bin/


# --- Stage 2: Minimal runtime with distroless ---
FROM gcr.io/distroless/cc AS runtime

COPY --link --from=builder /usr/local/bin/zallet /usr/local/bin/

# USER nonroot (UID 65532) — for K8s, use runAsUser: 65532
USER nonroot

WORKDIR /var/lib/zallet

ENTRYPOINT ["zallet"]
Loading