From bd756a8c8fae7b7ba0e8e34246522e6c811d7012 Mon Sep 17 00:00:00 2001 From: John Cairns Date: Sat, 9 Sep 2023 09:04:39 -0500 Subject: [PATCH] initial container and build --- .dockerignore | 4 + .github/workflows/ci-image.yml | 41 ++++++++ .github/workflows/ghcr-image.yml | 64 ++++++++++++ CHANGELOG.md | 3 + Dockerfile | 167 +++++++++++++++++++++++++++++++ LICENSE | 29 ++++++ build.sh | 15 +++ 7 files changed, 323 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/ci-image.yml create mode 100644 .github/workflows/ghcr-image.yml create mode 100644 CHANGELOG.md create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 build.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3d9bec6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +build.sh +README.md +LICENSE +CHANGELOG.md diff --git a/.github/workflows/ci-image.yml b/.github/workflows/ci-image.yml new file mode 100644 index 0000000..461c119 --- /dev/null +++ b/.github/workflows/ci-image.yml @@ -0,0 +1,41 @@ +name: Build Image CI + +on: + workflow_dispatch: + pull_request: + branches: + - main + push: + branches: + - "*" + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - + name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - + name: Build + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64 + push: false + build-args: | + VERSION=latest diff --git a/.github/workflows/ghcr-image.yml b/.github/workflows/ghcr-image.yml new file mode 100644 index 0000000..ee8d80f --- /dev/null +++ b/.github/workflows/ghcr-image.yml @@ -0,0 +1,64 @@ +name: Deploy Image CI + +on: + push: + tags: + - "*" + +concurrency: + group: "docker-image" + cancel-in-progress: true + +env: + DOCKER_BUILDKIT: "1" + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - + name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - + name: Generate repository name + run: | + echo "REPOSITORY_PATH=$( echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]' )" >> ${GITHUB_ENV} + echo "REPOSITORY_SHA=$( echo ${GITHUB_SHA} | cut -c 1-7 )" >> ${GITHUB_ENV} + - + name: Build and Push + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64 + push: true + build-args: | + VERSION=${{ github.ref_name }} + tags: | + ghcr.io/${{ env.REPOSITORY_PATH }}:v${{ github.ref_name }} + ghcr.io/${{ env.REPOSITORY_PATH }}:${{ env.REPOSITORY_SHA }} + ghcr.io/${{ env.REPOSITORY_PATH }}:latest + - + name: GitHub Release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + draft: false + prerelease: false + tag_name: ${{ github.ref_name }} + release_name: v${{ github.ref_name }} + body_path: CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..7b41e4c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +1.0.0 (2023-09-08) + +* fork from collectivexyz/foundry diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fc0d3e0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,167 @@ +FROM debian:stable-slim as go-builder +# defined from build kit +# DOCKER_BUILDKIT=1 docker build . -t ... +ARG TARGETARCH + +RUN export DEBIAN_FRONTEND=noninteractive && \ + apt update && \ + apt install -y -q --no-install-recommends \ + git curl gnupg2 build-essential coreutils \ + openssl libssl-dev pkg-config \ + ca-certificates apt-transport-https \ + python3 && \ + apt clean && \ + rm -rf /var/lib/apt/lists/* + +## Go Lang +ARG GO_VERSION=1.21.1 +ADD https://go.dev/dl/go${GO_VERSION}.linux-$TARGETARCH.tar.gz /go-ethereum/go${GO_VERSION}.linux-$TARGETARCH.tar.gz +RUN echo 'SHA256 of this go source package...' +RUN cat /go-ethereum/go${GO_VERSION}.linux-$TARGETARCH.tar.gz | sha256sum +RUN tar -C /usr/local -xzf /go-ethereum/go${GO_VERSION}.linux-$TARGETARCH.tar.gz +ENV PATH=$PATH:/usr/local/go/bin +RUN go version + +## Go Ethereum +WORKDIR /go-ethereum +ARG ETH_VERSION=1.12.2 +ADD https://github.com/ethereum/go-ethereum/archive/refs/tags/v${ETH_VERSION}.tar.gz /go-ethereum/go-ethereum-${ETH_VERSION}.tar.gz +RUN echo 'SHA256 of this go-ethereum package...' +RUN cat /go-ethereum/go-ethereum-${ETH_VERSION}.tar.gz | sha256sum +RUN tar -zxf go-ethereum-${ETH_VERSION}.tar.gz -C /go-ethereum +WORKDIR /go-ethereum/go-ethereum-${ETH_VERSION} +RUN go mod download +RUN go run build/ci.go install + +FROM debian:stable-slim as foundry-builder +# defined from build kit +# DOCKER_BUILDKIT=1 docker build . -t ... +ARG TARGETARCH +ARG MAXIMUM_THREADS=2 + +RUN export DEBIAN_FRONTEND=noninteractive && \ + apt update && \ + apt install -y -q --no-install-recommends \ + git curl gnupg2 build-essential \ + linux-headers-${TARGETARCH} libc6-dev \ + openssl libssl-dev pkg-config \ + ca-certificates apt-transport-https \ + python3 && \ + apt clean && \ + rm -rf /var/lib/apt/lists/* + +RUN useradd --create-home -s /bin/bash xmtp +RUN usermod -a -G sudo xmtp +RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers + + +WORKDIR /rustup +## Rust +ADD https://sh.rustup.rs /rustup/rustup.sh +RUN chmod 755 /rustup/rustup.sh + +ENV USER=xmtp +USER xmtp +RUN /rustup/rustup.sh -y --default-toolchain stable --profile minimal + +## Foundry +WORKDIR /build + +# latest https://github.com/foundry-rs/foundry +ENV PATH=$PATH:~xmtp/.cargo/bin +RUN git clone https://github.com/foundry-rs/foundry + +WORKDIR /build/foundry +RUN git pull && LATEST_TAG=$(git describe --tags --abbrev=0) || LATEST_TAG=master && \ + echo "building tag ${LATEST_TAG}" && \ + git -c advice.detachedHead=false checkout nightly && \ + . $HOME/.cargo/env && \ + THREAD_NUMBER=$(cat /proc/cpuinfo | grep -c ^processor) && \ + MAX_THREADS=$(( THREAD_NUMBER > ${MAXIMUM_THREADS} ? ${MAXIMUM_THREADS} : THREAD_NUMBER )) && \ + echo "building with ${MAX_THREADS} threads" && \ + cargo build --jobs ${MAX_THREADS} --release && \ + objdump -j .comment -s target/release/forge && \ + strip target/release/forge && \ + strip target/release/cast && \ + strip target/release/anvil && \ + strip target/release/chisel + +RUN git rev-parse HEAD > /build/foundry_commit_sha256 + +FROM debian:stable-slim as node18-slim + +RUN export DEBIAN_FRONTEND=noninteractive && \ + apt update && \ + apt install -y -q --no-install-recommends \ + build-essential git gnupg2 curl \ + ca-certificates apt-transport-https && \ + apt clean && \ + rm -rf /var/lib/apt/lists/* + +RUN mkdir -p /usr/local/nvm +ENV NVM_DIR=/usr/local/nvm + +ENV NODE_VERSION=v18.17.1 + +ADD https://raw.githubusercontent.com/creationix/nvm/master/install.sh /usr/local/etc/nvm/install.sh +RUN bash /usr/local/etc/nvm/install.sh && \ + bash -c ". $NVM_DIR/nvm.sh && nvm install $NODE_VERSION && nvm alias default $NODE_VERSION && nvm use default" + +ENV NVM_NODE_PATH ${NVM_DIR}/versions/node/${NODE_VERSION} +ENV NODE_PATH ${NVM_NODE_PATH}/lib/node_modules +ENV PATH ${NVM_NODE_PATH}/bin:$PATH + +RUN npm install npm -g +RUN npm install yarn -g + +FROM node18-slim +ARG TARGETARCH + +RUN export DEBIAN_FRONTEND=noninteractive && \ + apt update && \ + apt install -y -q --no-install-recommends \ + libz3-dev z3 build-essential \ + ca-certificates apt-transport-https \ + sudo ripgrep procps \ + python3 python3-pip python3-dev && \ + apt clean && \ + rm -rf /var/lib/apt/lists/* + +RUN echo "building platform $(uname -m)" + +RUN useradd --create-home -s /bin/bash xmtp +RUN usermod -a -G sudo xmtp +RUN echo '%xmtp ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers + +# SOLC +COPY --from=ghcr.io/jac18281828/solc:latest /usr/local/bin/solc /usr/local/bin +COPY --from=ghcr.io/jac18281828/solc:latest /usr/local/bin/yul-phaser /usr/local/bin +RUN solc --version + +## Rust +COPY --chown=xmtp:xmtp --from=foundry-builder /home/xmtp/.cargo /home/xmtp/.cargo + +# GO LANG +COPY --from=go-builder /usr/local/go /usr/local/go + +## GO Ethereum Binaries +ARG ETH_VERSION=1.12.2 +COPY --from=go-builder /go-ethereum/go-ethereum-${ETH_VERSION}/build/bin /usr/local/bin + +# Foundry +COPY --from=foundry-builder /build/foundry_commit_sha256 /usr/local/etc/foundry_commit_sha256 +COPY --from=foundry-builder /build/foundry/target/release/forge /usr/local/bin/forge +COPY --from=foundry-builder /build/foundry/target/release/cast /usr/local/bin/cast +COPY --from=foundry-builder /build/foundry/target/release/anvil /usr/local/bin/anvil +COPY --from=foundry-builder /build/foundry/target/release/chisel /usr/local/bin/chisel + +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name="foundry" \ + org.label-schema.description="Foundry RS Development Container" \ + org.label-schema.url="https://github.com/xmtp/foundry" \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url="git@github.com:xmtp/foundry.git" \ + org.label-schema.vendor="XMTP Labs" \ + org.label-schema.version=$VERSION \ + org.label-schema.schema-version="1.0" \ + org.opencontainers.image.description="Foundry and Ethereum Development Container for Visual Studio Code" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5bae569 --- /dev/null +++ b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2023, XMTP +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..540401c --- /dev/null +++ b/build.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +# install a local version of this image - useful on arm64 where there are currently no public +# distributions + +VERSION=$(git rev-parse HEAD | cut -c 1-8) + +PROJECT=xmtp/$(basename ${PWD}) + +# cross platform okay: +# --platform=amd64 or arm64 +DOCKER_BUILDKIT=1 docker build --progress plain . -t ${PROJECT}:${VERSION} \ + --build-arg VERSION=${VERSION} --build-arg MAXIMUM_THREADS=2 && \ + docker tag ${PROJECT}:${VERSION} ${PROJECT}:latest && \ + docker tag ${PROJECT}:${VERSION} ghcr.io/${PROJECT}:latest