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(docker): add dockerfile and workflow #348

Merged
merged 5 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
60 changes: 60 additions & 0 deletions .github/workflows/ci-docker-hub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Build and Push to Docker Hub

on:
workflow_dispatch:
push:
tags:
- '*'

jobs:
# Build and upload the geth binary
build_and_push:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5

- name: Set build arguments
run: |
echo "REPOSITORY_URI=${{ vars.REPOSITORY_URI }}" >> $GITHUB_ENV
echo "COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "VERSION=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
echo "BUILDNUM=${{ github.run_number }}" >> $GITHUB_ENV

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-

- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Dockerize the geth and bootnode binary
env:
DOCKER_BUILDKIT: 1
run: |
docker buildx create --use
docker buildx build \
--platform linux/amd64,linux/arm64,linux/arm64/v8 \
--build-arg BUILDNUM=$BUILDNUM \
--build-arg COMMIT=$COMMIT \
--build-arg VERSION=$VERSION \
-t $REPOSITORY_URI:latest \
-t $REPOSITORY_URI:$COMMIT \
-t $REPOSITORY_URI:$VERSION \
--cache-from=type=local,src=/tmp/.buildx-cache \
--cache-to=type=local,dest=/tmp/.buildx-cache \
--push \
-f ./Dockerfile \
.
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Support setting various labels on the final image
ARG COMMIT=""
ARG VERSION=""
ARG BUILDNUM=""

# Build Geth in a stock Go builder container
FROM golang:1.22-alpine as builder

# Set the Current Working Directory inside the container
WORKDIR /story

# Copy go.mod and go.sum files
COPY go.mod go.sum ./

# Download all dependencies. Dependencies are cached if the go.mod and go.sum files are not changed
RUN go mod download

ADD . /story/
RUN go build -o story ./client

# Pull Geth into a second stage deploy alpine container
FROM alpine:latest

RUN apk add --no-cache ca-certificates
COPY --from=builder /story/story /usr/local/bin/

EXPOSE 8545 8546 30303 30303/udp
Copy link
Contributor

Choose a reason for hiding this comment

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

these ports seem to be the port of geth? maybe we need to expose the ports used by story

Copy link
Contributor

Choose a reason for hiding this comment

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

It could be. On CL side, 26656 for p2p and 26657 for rpc. In addition, 1317 (by default) for API should be opened for providing API service.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed expose port. Thanks!


WORKDIR /root/.story/story
ENTRYPOINT ["/bin/sh", "-c", "story init --network $NETWORK && exec story run \"$@\"", "--"]

# Add some metadata labels to help programmatic image consumption
ARG COMMIT=""
ARG VERSION=""
ARG BUILDNUM=""

LABEL commit="$COMMIT" version="$VERSION" buildnum="$BUILDNUM" network="$NETWORK"
Loading