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

Unstable #6

Merged
merged 2 commits into from
Nov 26, 2024
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
104 changes: 12 additions & 92 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ env:
jobs:
# Extract the VERSION which is either `latest` or `vX.Y.Z`, and the VERSION_SUFFIX
# which is either empty or `-unstable`.
#
# It would be nice if the arch didn't get spliced into the version between `latest` and
# `unstable`, but for now we keep the two parts of the version separate for backwards
# compatibility.
extract-version:
runs-on: ubuntu-22.04
steps:
Expand All @@ -43,14 +39,14 @@ jobs:
outputs:
VERSION: ${{ env.VERSION }}
VERSION_SUFFIX: ${{ env.VERSION_SUFFIX }}
build-docker-single-arch:
name: build-docker-${{ matrix.binary }}-${{ matrix.cpu_arch }}${{ matrix.features.version_suffix }}

build-docker:
name: build-docker-${{ matrix.binary }}
# Use self-hosted runners only on the sigp repo.
runs-on: ${{ github.repository == 'sigp/anchor' && fromJson('["self-hosted", "linux", "release"]') || 'ubuntu-22.04' }}
strategy:
matrix:
binary: [anchor]
cpu_arch: [aarch64, x86_64]
binary: [anchor]
include:
- profile: maxperf

Expand All @@ -69,7 +65,7 @@ jobs:
with:
url: https://vault.sigp.io
method: github
githubToken: ${{ secrets.VAULT_TOKEN }}
githubToken: ${{ secrets.GITHUB_TOKEN }}
secrets: |
spesi_kv/data/gh_wf_testing DOCKER_USERNAME ;
spesi_kv/data/gh_wf_testing DOCKER_PASSWORD
Expand All @@ -78,101 +74,25 @@ jobs:
run: |
echo "${DOCKER_PASSWORD}" | docker login --username ${DOCKER_USERNAME} --password-stdin

- name: Sets env vars for Anchor
if: startsWith(matrix.binary, 'anchor')
run: |
echo "CROSS_FEATURES=gnosis,spec-minimal,slasher-lmdb,jemalloc" >> $GITHUB_ENV

- name: Set `make` command for anchor
if: startsWith(matrix.binary, 'anchor')
run: |
echo "MAKE_CMD=build-${{ matrix.cpu_arch }}" >> $GITHUB_ENV

- name: Set `make` command for lcli
if: startsWith(matrix.binary, 'lcli')
- name: Build binary
run: |
echo "MAKE_CMD=build-lcli-${{ matrix.cpu_arch }}" >> $GITHUB_ENV

- name: Cross build binaries
run: |
cargo install cross
env CROSS_PROFILE=${{ matrix.profile }} make ${{ env.MAKE_CMD }}
make

- name: Make bin dir
run: mkdir ./bin

- name: Move cross-built binary into Docker scope
run: mv ./target/${{ matrix.cpu_arch }}-unknown-linux-gnu/${{ matrix.profile }}/${{ matrix.binary }} ./bin

- name: Map aarch64 to arm64 short arch
if: startsWith(matrix.cpu_arch, 'aarch64')
run: echo "SHORT_ARCH=arm64" >> $GITHUB_ENV

- name: Map x86_64 to amd64 short arch
if: startsWith(matrix.cpu_arch, 'x86_64')
run: echo "SHORT_ARCH=amd64" >> $GITHUB_ENV;

- name: Install QEMU
if: env.SELF_HOSTED_RUNNERS == 'false'
run: sudo apt-get update && sudo apt-get install -y qemu-user-static
- name: Move built binary into Docker scope
run: mv ./target/release/${{ matrix.binary }} ./bin

- name: Set up Docker Buildx
if: env.SELF_HOSTED_RUNNERS == 'false'
uses: docker/setup-buildx-action@v3

- name: Build and push (Anchor)
if: startsWith(matrix.binary, 'anchor')
- name: Build and push
uses: docker/build-push-action@v5
with:
file: ./Dockerfile.cross
file: ./Dockerfile
context: .
platforms: linux/${{ env.SHORT_ARCH }}
push: true
tags: |
${{ github.repository_owner}}/${{ matrix.binary }}:${{ env.VERSION }}-${{ env.SHORT_ARCH }}${{ env.VERSION_SUFFIX }}

- name: Build and push (lcli)
if: startsWith(matrix.binary, 'lcli')
uses: docker/build-push-action@v5
with:
file: ./lcli/Dockerfile.cross
context: .
platforms: linux/${{ env.SHORT_ARCH }}
push: true
tags: |
${{ github.repository_owner}}/${{ matrix.binary }}:${{ env.VERSION }}-${{ env.SHORT_ARCH }}${{ env.VERSION_SUFFIX }}

build-docker-multiarch:
name: build-docker-${{ matrix.binary }}-multiarch
runs-on: ubuntu-22.04
strategy:
matrix:
binary: [anchor,
lcli]
needs: [build-docker-single-arch, extract-version]
env:
VERSION: ${{ needs.extract-version.outputs.VERSION }}
VERSION_SUFFIX: ${{ needs.extract-version.outputs.VERSION_SUFFIX }}
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Retrieve Docker credentials from Vault
uses: hashicorp/vault-action@v2
with:
url: https://vault.sigp.io
method: github
githubToken: ${{ secrets.GITHUB_TOKEN }}
secrets: |
spesi_kv/data/gh_wf_testing DOCKER_USERNAME ;
spesi_kv/data/gh_wf_testing DOCKER_PASSWORD

- name: Dockerhub login
run: |
echo "${DOCKER_PASSWORD}" | docker login --username ${DOCKER_USERNAME} --password-stdin

- name: Create and push multiarch manifests
run: |
docker buildx imagetools create -t ${{ github.repository_owner}}/${{ matrix.binary }}:${VERSION}${VERSION_SUFFIX} \
${{ github.repository_owner}}/${{ matrix.binary }}:${VERSION}-arm64${VERSION_SUFFIX} \
${{ github.repository_owner}}/${{ matrix.binary }}:${VERSION}-amd64${VERSION_SUFFIX};
${{ github.repository_owner}}/${{ matrix.binary }}:${{ env.VERSION }}${{ env.VERSION_SUFFIX }}
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ clap = { version = "4.5.15", features = ["derive", "wrap_help"]}
discv5 = "0.8.0"
dirs = "5.0.1"
either = "1.13.0"
futures = "0.3.30"
futures = "0.3.31"
tower-http = {version = "0.6", features = ["cors"] }
hyper = "1.4"
parking_lot = "0.12"
Expand Down
18 changes: 18 additions & 0 deletions anchor/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM rust:1.78.0-bullseye AS builder
RUN apt-get update && apt-get -y upgrade && apt-get install -y cmake libclang-dev
COPY . lighthouse
ARG FEATURES
ARG PROFILE=release
ARG CARGO_USE_GIT_CLI=true
ENV FEATURES=$FEATURES
ENV PROFILE=$PROFILE
ENV CARGO_NET_GIT_FETCH_WITH_CLI=$CARGO_USE_GIT_CLI
RUN cd lighthouse && make

FROM ubuntu:22.04
RUN apt-get update && apt-get -y upgrade && apt-get install -y --no-install-recommends \
libssl-dev \
ca-certificates \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/local/cargo/bin/lighthouse /usr/local/bin/lighthouse
10 changes: 10 additions & 0 deletions anchor/Dockerfile.cross
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This image is meant to enable cross-architecture builds.
# It assumes the lighthouse binary has already been
# compiled for `$TARGETPLATFORM` and moved to `./bin`.
FROM --platform=$TARGETPLATFORM ubuntu:22.04
RUN apt-get update && apt-get install -y --no-install-recommends \
libssl-dev \
ca-certificates \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
COPY ./bin/anchor /usr/local/bin/anchor