-
Notifications
You must be signed in to change notification settings - Fork 10
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
Create Dockerfile #133
Changes from all commits
f5e065f
5ca42d6
ab2ad77
f792277
b44296a
2b366d5
388e577
efdb3a2
bec12bd
4a889be
5c008f6
f757fe8
0133618
fc35cd2
a030bdf
0347f86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 }} |
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 | ||
y4ssi marked this conversation as resolved.
Show resolved
Hide resolved
|
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 | ||
y4ssi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 | ||
y4ssi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
WORKDIR /var/lib/zallet | ||
|
||
ENTRYPOINT ["zallet"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: This can be a reusable workflow. For example: