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: workflow to build docker image #1

Draft
wants to merge 5 commits into
base: optimism
Choose a base branch
from
Draft
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
59 changes: 59 additions & 0 deletions .github/workflows/build-and-push-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Build and Push Op-geth

on:
push:
branches:
- optimism
workflow_dispatch: # Allows manual triggering

env:
REGISTRY: "registry.digitalocean.com/sigil"
DEPLOYMENT_NAME: op-geth
CONTAINER_NAME: op-geth

jobs:
build-and-deploy:
runs-on: ubuntu-latest

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

- name: Build container image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: false
tags: ${{ env.REGISTRY }}/${{ env.CONTAINER_NAME }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}

- name: Log in to DO Container Registry
run: doctl registry login --expiry-seconds 1200

- name: Push image to DO Container Registry
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: |
${{ env.REGISTRY }}/${{ env.CONTAINER_NAME }}:${{ github.sha }}
${{ env.REGISTRY }}/${{ env.CONTAINER_NAME }}:latest

- name: Save DigitalOcean kubeconfig
run: doctl kubernetes cluster kubeconfig save ${{ secrets.CLUSTER_NAME }}

- name: Update deployment image
run: |
kubectl set image statefulset/${DEPLOYMENT_NAME} ${CONTAINER_NAME}=${REGISTRY}/${CONTAINER_NAME}:${GITHUB_SHA}

- name: Verify deployment
run: |
kubectl rollout status statefulset/${DEPLOYMENT_NAME}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ profile.cov
# VS Code
.vscode

# so accidents don't happen
jwt.txt
datadir/

# dashboard
/dashboard/assets/flow-typed
/dashboard/assets/node_modules
Expand Down
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# 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.23-alpine AS builder
Expand All @@ -13,6 +12,7 @@ COPY go.mod /go-ethereum/
COPY go.sum /go-ethereum/
RUN cd /go-ethereum && go mod download

# copies all files (including genesis.json) to the builder stage
ADD . /go-ethereum
RUN cd /go-ethereum && go run build/ci.go install -static ./cmd/geth

Expand All @@ -22,12 +22,14 @@ FROM alpine:latest
RUN apk add --no-cache ca-certificates
COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/

# Copy genesis.json - this will fail if file doesn't exist
COPY --from=builder /go-ethereum/genesis.json /usr/local/bin/genesis.json

EXPOSE 8545 8546 30303 30303/udp
ENTRYPOINT ["geth"]

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

LABEL commit="$COMMIT" version="$VERSION" buildnum="$BUILDNUM"
LABEL commit="$COMMIT" version="$VERSION"
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,22 @@ Do not forget `--http.addr 0.0.0.0`, if you want to access RPC from other contai
and/or hosts. By default, `geth` binds to the local interface and RPC endpoints are not
accessible from the outside.

#### Docker image Building

Images are built automatically through the github action, but can be manually generated with

```bash
docker build \
--build-arg COMMIT=$(git rev-parse HEAD) \
--build-arg VERSION=$(git describe --tags --abbrev=0) \
-t op-geth:latest \
.
```

The `Dockerfile` requires a `genesis.json` in the project root. `genesis.json`
is generated in the rollup node, `op-node`. Read more about it in the
[op stack tutorial](https://docs.optimism.io/builders/chain-operators/tutorials/create-l2-rollup).

### Programmatically interfacing `geth` nodes

As a developer, sooner rather than later you'll want to start interacting with `geth` and the
Expand Down
Loading