From 8c232b6759a1d9321d58e2b4cae6fafd65d8a5f5 Mon Sep 17 00:00:00 2001 From: Ben Bierens <39762930+benbierens@users.noreply.github.com> Date: Mon, 19 Jun 2023 08:28:27 +0200 Subject: [PATCH] Docker multiarch debug (#447) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Uses correct string for marketplace address * first steps towards support for arm64 * Applies multiarch ubuntu dockerfile as codex-dockerfile. * Add `--simulate-proof-failures` env variable, update docker-compose to point to slimmed image * Add image to CI, and update startCodex.sh * Sets up separate docker build for arm * Update arm64 arm of docker ci * [docker] modify startCodex.sh - include overridden node name in log output if specified in test - quote `—log-level` value so that multiple log levels can be specified - ensure any CLI parameter env vars are passed through to the codex binary, instead of conditionally including them - add `—persistence` - add `—validator` * fixes load and push for amd docker build --------- Co-authored-by: Eric Mastro --- .github/workflows/docker.yml | 100 +++++++++++++++++++++++++++++++---- docker/README.md | 16 ++++++ docker/codex.Dockerfile | 16 +++--- docker/docker-compose.yaml | 84 ++++++----------------------- docker/startCodex.sh | 43 ++++++++++++--- 5 files changed, 170 insertions(+), 89 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index d73b81ea..ad31c3c6 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -9,35 +9,117 @@ on: workflow_dispatch: jobs: - docker: + docker-amd64: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 + - name: Docker meta id: meta uses: docker/metadata-action@v4 with: - images: thatbenbierens/nim-codex + images: thatbenbierens/nim-codex-amd64 tags: | type=semver,pattern={{version}} type=sha - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + - name: Login to Docker Hub if: github.event_name != 'pull_request' uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push + + - name: Build and export to Docker + id: build uses: docker/build-push-action@v4 with: context: . file: docker/codex.Dockerfile - platforms: linux/amd64,linux/arm64,linux/arm/v7 - push: ${{ github.event_name != 'pull_request' }} + platforms: linux/amd64 + load: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Minify docker image + uses: kitabisa/docker-slim-action@v1 + env: + DSLIM_HTTP_PROBE: false + with: + target: ${{ steps.meta.outputs.tags }} + overwrite: true + + - name: Show slim report + run: echo "${{ steps.slim.outputs.report }}" + + - name: Push to Docker registry + if: github.event_name != 'pull_request' + id: push + uses: docker/build-push-action@v4 + with: + context: . + file: docker/codex.Dockerfile + platforms: linux/amd64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + docker-arm64: + runs-on: buildjet-4vcpu-ubuntu-2204-arm + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: thatbenbierens/nim-codex-arm64 + tags: | + type=semver,pattern={{version}} + type=sha + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and export to Docker + id: build + uses: docker/build-push-action@v4 + with: + context: . + file: docker/codex.Dockerfile + platforms: linux/arm64 + load: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Minify docker image + uses: kitabisa/docker-slim-action@v1 + env: + DSLIM_HTTP_PROBE: false + with: + target: ${{ steps.meta.outputs.tags }} + overwrite: true + + - name: Show slim report + run: echo "${{ steps.slim.outputs.report }}" + + - name: Push to Docker registry + if: github.event_name != 'pull_request' + id: push + uses: docker/build-push-action@v4 + with: + context: . + file: docker/codex.Dockerfile + platforms: linux/arm64 + push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/docker/README.md b/docker/README.md index da37a9ec..603c6e39 100644 --- a/docker/README.md +++ b/docker/README.md @@ -32,9 +32,15 @@ Codex docker image supports the following environment variables: - ETH_PROVIDER - ETH_ACCOUNT - ETH_DEPLOYMENT +- SIMULATE_PROOF_FAILURES +- VALIDATOR +- PERSISTENCE +- CODEX_NODENAME(†) (*) These variables have default values in the docker image that are different from Codex's standard default values. +(†) CODEX_NODENAME is used for logging purposes only in the docker image + All environment variables are optional and will default to Codex's CLI default values. # Constants @@ -46,3 +52,13 @@ To get the IP address of a container within a network: Find container Id: `docker ps` Open terminal in container: `docker exec -it sh` Get IP addresses: `ifconfig` + +# Slim +1. Build the image using `docker build -t status-im/codexsetup:latest -f codex.Dockerfile ..` +2. The docker image can then be minifed using [slim](https://github.com/slimtoolkit/slim). Install slim on your path and then run: +```shell +slim # brings up interactive prompt +>>> build --target status-im/codexsetup --http-probe-off true +``` +3. This should output an image with name `status-im/codexsetup.slim` +4. We can then bring up the image using `docker-compose up -d`. \ No newline at end of file diff --git a/docker/codex.Dockerfile b/docker/codex.Dockerfile index cf1f30c9..b50ce90d 100644 --- a/docker/codex.Dockerfile +++ b/docker/codex.Dockerfile @@ -1,14 +1,18 @@ -FROM nimlang/nim:1.6.10-alpine AS builder +FROM ubuntu:lunar-20230415 AS builder +RUN apt-get update && apt-get install -y git cmake curl make bash lcov build-essential nim +RUN echo 'export NIMBLE_DIR="${HOME}/.nimble"' >> "${HOME}/.bash_env" +RUN echo 'export PATH="${NIMBLE_DIR}/bin:${PATH}"' >> "${HOME}/.bash_env" + WORKDIR /src -RUN apk update && apk add git cmake curl make git bash linux-headers COPY . . RUN make clean RUN make -j4 update RUN make -j4 NIM_PARAMS="-d:disableMarchNative -d:codex_enable_api_debug_peers=true" -FROM alpine:3.17.2 -WORKDIR /root/ -RUN apk add --no-cache openssl libstdc++ libgcc libgomp +FROM ubuntu:lunar-20230415 +WORKDIR /root +RUN apt-get update && apt-get install -y libgomp1 bash COPY --from=builder /src/build/codex ./ COPY --from=builder /src/docker/startCodex.sh ./ -CMD ["sh", "startCodex.sh"] +RUN chmod +x ./startCodex.sh +CMD ["/bin/bash", "-l", "-c", "./startCodex.sh"] diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 76c74e8c..643682a2 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -1,77 +1,27 @@ services: codex-node1: - image: clustertest-nim-codex - build: - context: ../. - dockerfile: docker/codex.Dockerfile + image: status-im/codexsetup.slim:latest ports: - 8080:8080 # Available environment variables: - # environment: - # - LOG_LEVEL=TRACE - # - METRICS_ADDR=0.0.0.0 - # - METRICS_PORT=9090 - # - NAT_IP=2.3.4.5 - # - API_PORT=8080 - # - DISC_IP=3.4.5.6 - # - DISC_PORT=8765 - # - NET_PRIVKEY=privkey - # - BOOTSTRAP_SPR=bootstrap_record - # - MAX_PEERS=123 - # - AGENT_STRING=agent_string - # - STORAGE_QUOTA=123456789 - # - BLOCK_TTL=23456 - # - CACHE_SIZE=6543 - # - ETH_PROVIDER=eth - # - ETH_ACCOUNT=account - # - ETH_DEPLOYMENT=deploy - volumes: - - ./hostdatadir/node1:/datadir - networks: - - primary - - # Example with metrics enabled. - codex-node2: - image: clustertest-nim-codex - ports: - - 8081:8080 - - 9090:9090 environment: + - LOG_LEVEL=TRACE - METRICS_ADDR=0.0.0.0 - METRICS_PORT=9090 - volumes: - - ./hostdatadir/node2:/datadir - depends_on: - - codex-node1 - networks: - - primary - - secondary + - NAT_IP=2.3.4.5 + - API_PORT=8080 + - DISC_IP=3.4.5.6 + - DISC_PORT=8765 + - NET_PRIVKEY=privkey + - BOOTSTRAP_SPR=bootstrap_record + - MAX_PEERS=123 + - AGENT_STRING=agent_string + - STORAGE_QUOTA=123456789 + - BLOCK_TTL=23456 + - CACHE_SIZE=6543 + - ETH_PROVIDER=eth + - ETH_ACCOUNT=account + - ETH_MARKETPLACE_ADDRESS=0x59b670e9fA9D0A427751Af201D676719a970857b + - SIMULATE_PROOF_FAILURES=2 - codex-node3: - image: clustertest-nim-codex - ports: - - 8082:8080 - volumes: - - ./hostdatadir/node3:/datadir - depends_on: - - codex-node1 - networks: - - secondary - prometheus: - image: prom/prometheus:v2.30.3 - ports: - - 9000:9090 - volumes: - - ./prometheus:/etc/prometheus - - ./prometheus-data:/prometheus - command: --web.enable-lifecycle --config.file=/etc/prometheus/prometheus.yml - networks: - - primary - - secondary - -networks: - primary: - name: primary - secondary: - name: secondary diff --git a/docker/startCodex.sh b/docker/startCodex.sh index 0352bac5..90c13cc6 100644 --- a/docker/startCodex.sh +++ b/docker/startCodex.sh @@ -1,4 +1,8 @@ -echo "Starting Codex..." +NAME="" +if [ -n "$CODEX_NODENAME" ]; then + NAME=" '$CODEX_NODENAME'" +fi +echo "Starting Codex node$NAME" args="" @@ -32,7 +36,7 @@ fi # Log level if [ -n "$LOG_LEVEL" ]; then echo "Log level: $LOG_LEVEL" - args="$args --log-level=$LOG_LEVEL" + args="$args --log-level=\"$LOG_LEVEL\"" fi # Metrics @@ -115,10 +119,35 @@ if [ -n "$ETH_PROVIDER" ] && [ -n "$ETH_ACCOUNT" ] && [ -n "$ETH_MARKETPLACE_ADD args="$args --eth-account=$ETH_ACCOUNT" # args="$args --validator" - # Remove this as soon as CLI option is available: - echo "{\"contracts\": { \"Marketplace\": { \"address\": \""$ACCOUNTSTR"\" } } }" > /root/marketplace_address.json - args="$args --eth-deployment=/root/marketplace_address.json" +if [ -n "$ETH_ACCOUNT" ]; then + echo "Ethereum account: $ETH_ACCOUNT" + args="$args --eth-account=$ETH_ACCOUNT" fi -echo "./root/codex $args" -sh -c "/root/codex $args" +if [ -n "$ETH_MARKETPLACE_ADDRESS" ]; then + # Remove this as soon as CLI option is available: + echo "{\"contracts\": { \"Marketplace\": { \"address\": \""$ETH_MARKETPLACE_ADDRESS"\" } } }" > /root/marketplace_address.json + args="$args --eth-deployment=/root/marketplace_address.json" +fi + +if [ -n "$SIMULATE_PROOF_FAILURES" ]; then + echo "Simulate proof failures: $SIMULATE_PROOF_FAILURES" + args="$args --simulate-proof-failures=$SIMULATE_PROOF_FAILURES" +fi + +if [ "$PERSISTENCE" = "true" ] || [ "$PERSISTENCE" = "1" ]; then + echo "Persistence enabled" + args="$args --persistence" +else + echo "Persistence disabled" +fi + +if [ "$VALIDATOR" = "true" ] || [ "$VALIDATOR" = "1" ]; then + echo "Validator enabled" + args="$args --validator" +else + echo "Validator disabled" +fi + +echo "./codex $args" +/bin/bash -l -c "./codex $args"