Skip to content
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

feat: add dockerfile #191

Merged
merged 16 commits into from
Jan 9, 2025
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.github/
.git/
.gitignore
adr/
assets/
benches/
ci/
coverage_report/
doc/
target/

Dockerfile
.dockerignore
63 changes: 63 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Create and publish a Docker image

on:
push:
branches:
- 'main'
tags:
- 'v*'
pull_request:
branches:
- 'main'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
# Only run on original PRs, not forks
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
tags: |
type=sha,enable=false
type=ref,event=branch,enable=true
type=ref,event=pr,enable=true
type=semver,pattern={{version}},enable=true

- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM rust:1.83-slim-bookworm AS builder

WORKDIR /usr/src/myapp

RUN apt-get update && \
apt-get install -y --no-install-recommends \
curl \
git \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
cargo install just

COPY justfile .

RUN just install-deps

ENV PATH="/root/.sp1/bin:$PATH"

COPY . .

RUN just build

EXPOSE 8080

FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y --no-install-recommends libssl3 && apt-get clean && rm -rf /var/lib/apt/lists/*

COPY --from=builder /usr/src/myapp/target/release/prism-cli /usr/local/bin/prism-cli

ENTRYPOINT ["prism-cli"]

23 changes: 19 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ DOCKER_COMPOSE_FILE := "ci/docker-compose.yml"
# Helper function to use correct docker compose command
docker_compose_cmd := if `uname -s` == "Linux" { "docker compose" } else { "docker-compose" }

# Check if running as root by examining the effective user ID
is_root := if `id -u` == "0" { "true" } else { "false" }

celestia-up:
#!/usr/bin/env bash
set -euo pipefail
Expand Down Expand Up @@ -129,8 +132,13 @@ install-deps:
for package in build-essential pkg-config libssl-dev libclang-dev clang; do \
if ! dpkg -s $package > /dev/null 2>&1; then \
echo "Installing $package..."; \
sudo apt update; \
sudo apt install $package -y; \
if {{is_root}}; then \
apt update; \
apt install $package -y; \
else \
sudo apt update; \
sudo apt install $package -y; \
fi; \
else \
echo "$package is already installed."; \
fi; \
Expand All @@ -147,8 +155,13 @@ install-deps:
fi; \
brew install redis; \
elif [ "$OS" = "Linux" ]; then \
sudo apt update; \
sudo apt install redis-server -y; \
if {{is_root}}; then \
apt update; \
apt install redis-server -y; \
else \
sudo apt update; \
sudo apt install redis-server -y; \
fi; \
fi; \
echo "Redis installation complete!"; \
else \
Expand Down Expand Up @@ -182,4 +195,6 @@ install-deps:
fi; \
done

source ~/.bashrc || source ~/.bash_profile || source ~/.zshrc

echo "All dependencies installed successfully!"
Loading