diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 39c83d2..3c15ace 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,4 +1,3 @@ ---- name: Build docker image on: @@ -6,16 +5,20 @@ on: tags: - "v*" branches: - - "master" - - "develop" - - "release/v*" + - "*" + workflow_dispatch: + inputs: + thegarii_version: + description: 'version of thegarii to use (if not specified, will use latest)' + required: false + type: string env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} jobs: - build: + build-vanilla: runs-on: ubuntu-20.04 permissions: @@ -31,12 +34,14 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Set up Go uses: actions/setup-go@v2 with: go-version: ${{ matrix.go-version }} - - uses: actions/cache@v3 + - name: Set up Go cache + uses: actions/cache@v3 id: cache-go with: path: | @@ -46,18 +51,7 @@ jobs: restore-keys: | ${{ runner.os }}-go- - - uses: actions/cache@v3 - id: cache-rust - with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - target/ - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - - name: Branch name + - name: Print branch name id: extract_branch shell: bash run: | @@ -81,8 +75,7 @@ jobs: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=ref,event=tag - type=sha,prefix=,enable=${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/heads/release/v') }} - type=raw,enable=${{ github.ref == 'refs/heads/master' }},value=master + type=sha,prefix=,enable=true type=raw,enable=${{ github.ref == 'refs/heads/develop' }},value=develop type=raw,enable=${{ startsWith(github.ref, 'refs/heads/release/v') }},value=${{ steps.extract_branch.outputs.release_train }} flavor: | @@ -96,15 +89,108 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - # slack-notifications: - # needs: [build] - # runs-on: ubuntu-20.04 - # steps: - # - name: Slack notification - # env: - # SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} - # uses: Ilshidur/action-slack@2.0.2 - # with: - # args: | - # :done: *${{ github.repository }}* Success building docker image from ${{ github.ref_type }} _${{ github.ref_name }}_ (${{ github.actor }}) :sparkling_heart: ```${{ join(needs.build-vanilla.outputs.tags, ' ') }}``` + build-bundle: + needs: build-vanilla + runs-on: ubuntu-20.04 + if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }} + + permissions: + contents: read + packages: write + + outputs: + image: ${{ steps.print.outputs.image }} + + steps: + - name: Log in to the Container registry + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Branch name + id: extract_branch + shell: bash + run: | + echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" + echo "##[set-output name=release_train;]$(echo ${GITHUB_REF#refs/heads/release/})" + + - name: Set default thegarii version + if: ${{ github.event.inputs.thegarii_version == '' }} + id: thegarii_version_default + run: | + echo THEGARII_VERSION=latest >> $GITHUB_ENV + + - name: Set thegarii version from input + if: ${{ github.event.inputs.thegarii_version != '' }} + id: thegarii_version_input + run: | + echo THEGARII_VERSION=$(echo "${THEGARII_VERSION_INPUT}") >> $GITHUB_ENV + env: + THEGARII_VERSION_INPUT: ${{ github.event.inputs.thegarii_version }} + + - name: Set versions + shell: bash + run: | + docker pull ghcr.io/streamingfast/thegarii:${{ env.THEGARII_VERSION }} + echo VERSION=$(docker inspect --format='{{index .Config.Labels "org.opencontainers.image.version"}}' 'ghcr.io/streamingfast/thegarii':${{ env.THEGARII_VERSION }}) >> $GITHUB_ENV + echo SF_VERSION=$(echo "${{ needs.build-vanilla.outputs.tags }}" | grep -Ev "(develop)" | head -n 1 |cut -d: -f2) >> $GITHUB_ENV + + - name: Generate docker tags/labels from github build context + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=tag,suffix=-${{ env.VERSION }} + type=sha,prefix=,suffix=-${{ env.VERSION }},enable=true + type=raw,prefix=,suffix=-${{ env.VERSION }},enable=${{ github.ref == 'refs/heads/develop' }},value=develop + type=raw,prefix=,suffix=-${{ env.VERSION }},enable=${{ startsWith(github.ref, 'refs/heads/release/v') }},value=${{ steps.extract_branch.outputs.release_train }} + flavor: latest=false + + - name: Build and push Docker image + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + file: ./Dockerfile.bundle + build-args: | + THEGARII_VERSION=${{ env.THEGARII_VERSION }} + SF_VERSION=${{ env.SF_VERSION }} + + - id: print + run: | + OUT="${{ steps.meta.outputs.tags }}" + OUT="${OUT//'%'/'%25'}" + OUT="${OUT//$'\n'/'%0A'}" + OUT="${OUT//$'\r'/'%0D'}" + echo "::set-output name=image::$OUT" + + slack-notifications-vanilla: + if: ${{ !startsWith(github.ref, 'refs/tags/') && github.event_name != 'workflow_dispatch' }} + needs: [build-vanilla] + runs-on: ubuntu-20.04 + steps: + - name: Slack notification + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + uses: Ilshidur/action-slack@2.0.2 + with: + args: | + :done: *${{ github.repository }}* Success building docker image from ${{ github.ref_type }} _${{ github.ref_name }}_ (${{ github.actor }}) :sparkling_heart: ```${{ join(needs.build-vanilla.outputs.tags, ' ') }}``` + slack-notifications: + if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }} + needs: [build-vanilla, build-bundle] + runs-on: ubuntu-20.04 + steps: + - name: Slack notification + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + uses: Ilshidur/action-slack@2.0.2 + with: + args: | + :done: *${{ github.repository }}* Success building docker images from ${{ github.ref_type }} _${{ github.ref_name }}_ (${{ github.actor }}) :sparkling_heart: ```${{ join(needs.build-vanilla.outputs.tags, ' ') }} + ${{ needs.build-bundle.outputs.image }}``` diff --git a/Dockerfile b/Dockerfile index 2e1ecdb..20fcd0a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,3 @@ -# syntax=docker/dockerfile:1.2 - -# TODO: Move that to `thegarii` repo so we can pull it? -# thegarii builder -FROM rust:bullseye as thegarii-builder -ENV CARGO_NET_GIT_FETCH_WITH_CLI=true -RUN --mount=type=cache,target=/var/cache/apk \ - --mount=type=cache,target=/home/rust/.cargo \ - rustup component add rustfmt \ - && git clone https://github.com/streamingfast/thegarii \ - && cd thegarii \ - && cargo build --release \ - && cp target/release/thegarii /home/rust/ - FROM ubuntu:20.04 RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ @@ -21,12 +7,17 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ rm -rf /var/cache/apt /var/lib/apt/lists/* RUN rm /etc/localtime && ln -snf /usr/share/zoneinfo/America/Montreal /etc/localtime && dpkg-reconfigure -f noninteractive tzdata +RUN mkdir -p /app/ && curl -Lo /app/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v0.4.12/grpc_health_probe-linux-amd64 && chmod +x /app/grpc_health_probe ADD /firearweave /app/firearweave -COPY --from=thegarii-builder /home/rust/thegarii /app/thegarii -# TODO: Add back later -# COPY tools/sfeth/motd_generic /etc/ -# COPY tools/sfeth/99-sfeth-generic.sh /etc/profile.d/ +COPY tools/firearweave/motd_generic /etc/motd +COPY tools/firearweave/99-firehose.sh /etc/profile.d/ + +# On SSH connection, /root/.bashrc is invoked which invokes '/root/.bash_aliases' if existing, +# so we hijack the file to "execute" our specialized bash script +RUN echo ". /etc/profile.d/99-firehose.sh" > /root/.bash_aliases + +ENV PATH "$PATH:/app" ENTRYPOINT ["/app/firearweave"] diff --git a/Dockerfile.bundle b/Dockerfile.bundle new file mode 100644 index 0000000..ec6be36 --- /dev/null +++ b/Dockerfile.bundle @@ -0,0 +1,10 @@ +ARG THEGARII_VERSION=latest +ARG SF_VERSION=latest + +FROM ghcr.io/streamingfast/thegarii:$THEGARII_VERSION as chain +FROM ghcr.io/streamingfast/firehose-arweave:$SF_VERSION + +COPY --from=chain /app/thegarii /app/thegarii + +COPY tools/firearweave/motd_node_manager /etc/motd +COPY tools/firearweave/scripts/. /usr/local/bin/ diff --git a/tools/fireacme/99-firehose-arweave.sh b/tools/fireacme/99-firehose-arweave.sh deleted file mode 100644 index 027ffde..0000000 --- a/tools/fireacme/99-firehose-arweave.sh +++ /dev/null @@ -1,18 +0,0 @@ -## -# This is place inside `/etc/profile.d/99-firehose-arweave.sh` -# on built system an executed to provide message to use when they -# connect on the box. -export PATH=$PATH:/app - -# If we are in a "node-manager" image, display special scripts motd# -# -# *Note* Our (i.e. firehose-acme) Reader data directory is at the root -# `/data` mount point. Inside it, the `dummmy-blockchain` binary -# itself creates a `data` subfolder. This is why we have `/data/data` -# here as the path to check if we are inside a Node Manager instance -# or a pure process (i.e. without Node Manager) -if [[ -d /data/data ]]; then - cat /etc/motd_node_manager -else - cat /etc/motd_generic -fi diff --git a/tools/fireacme/scripts/acme-rpc-head-block b/tools/fireacme/scripts/acme-rpc-head-block deleted file mode 100755 index be89a19..0000000 --- a/tools/fireacme/scripts/acme-rpc-head-block +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -port=${RPC_PORT:-3030} - -finality="optimistic" -if [[ $# -gt 0 ]]; then - finality="$1" -fi - -if [[ "$finality" != "final" && "$finality" != "optimistic" ]]; then - echo "Finality parameter should be either 'final' or 'optimistic', got '$finality'" - exit 1 -fi - -# This need to be adapted to the protocol being instrumented, this is an example taken from NEAR integration -# which uses JSON-RPC to query data from the RPC node itself. -curl -sS -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":"1","method":"block","params":{"finality":"'"$finality"'"}}' "http://localhost:$port" | jq . diff --git a/tools/firearweave/99-firehose.sh b/tools/firearweave/99-firehose.sh new file mode 100644 index 0000000..490932e --- /dev/null +++ b/tools/firearweave/99-firehose.sh @@ -0,0 +1,7 @@ +## +# This is place inside `/etc/profile.d/99-firehose-arweave.sh` +# on built system an executed to provide message to use when they +# connect on the box. +export PATH=$PATH:/app + +cat /etc/motd diff --git a/tools/fireacme/motd_generic b/tools/firearweave/motd_generic similarity index 100% rename from tools/fireacme/motd_generic rename to tools/firearweave/motd_generic diff --git a/tools/fireacme/motd_node_manager b/tools/firearweave/motd_node_manager similarity index 100% rename from tools/fireacme/motd_node_manager rename to tools/firearweave/motd_node_manager diff --git a/tools/fireacme/scripts/acme-command b/tools/firearweave/scripts/arweave-command similarity index 100% rename from tools/fireacme/scripts/acme-command rename to tools/firearweave/scripts/arweave-command diff --git a/tools/fireacme/scripts/acme-debug-firehose-logs-30s b/tools/firearweave/scripts/arweave-debug-firehose-logs-30s similarity index 100% rename from tools/fireacme/scripts/acme-debug-firehose-logs-30s rename to tools/firearweave/scripts/arweave-debug-firehose-logs-30s diff --git a/tools/fireacme/scripts/acme-is-running b/tools/firearweave/scripts/arweave-is-running similarity index 100% rename from tools/fireacme/scripts/acme-is-running rename to tools/firearweave/scripts/arweave-is-running diff --git a/tools/fireacme/scripts/acme-maintenance b/tools/firearweave/scripts/arweave-maintenance similarity index 100% rename from tools/fireacme/scripts/acme-maintenance rename to tools/firearweave/scripts/arweave-maintenance diff --git a/tools/fireacme/scripts/acme-resume b/tools/firearweave/scripts/arweave-resume similarity index 100% rename from tools/fireacme/scripts/acme-resume rename to tools/firearweave/scripts/arweave-resume