Skip to content

Commit

Permalink
Init new repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ansermino committed Nov 6, 2024
0 parents commit ee7822a
Show file tree
Hide file tree
Showing 35 changed files with 3,448 additions and 0 deletions.
199 changes: 199 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
name: Build docker image

on:
push:
tags:
- "v*"
branches:
- "*"
workflow_dispatch:
inputs:
chain_version:
description: 'version of dummy-blockchain to use (if not specified, will use latest)'
required: false
type: string

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-vanilla:
runs-on: ubuntu-20.04

permissions:
contents: read
packages: write

strategy:
matrix:
go-version: [1.21.x]

outputs:
tags: ${{ steps.meta.outputs.tags }}

steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Set up Go cache
uses: actions/cache@v3
id: cache-go
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Print 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: Build
run: go build -v -ldflags "-X main.version=${{ github.event.ref }} -X main.commit=${{ github.sha }} -X main.date=$(date -u +%Y-%m-%dT%H:%MZ)" -o ./fireacme ./cmd/fireacme

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- 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
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: |
latest=${{ startsWith(github.ref, 'refs/tags/') }}
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

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 chain version
if: ${{ github.event.inputs.chain_version == '' }}
id: chain_version_default
run: |
echo CHAIN_VERSION=latest >> $GITHUB_ENV
- name: Set chain version from input
if: ${{ github.event.inputs.chain_version != '' }}
id: chain_version_input
run: |
echo CHAIN_VERSION=$(echo "${CHAIN_VERSION_INPUT}") >> $GITHUB_ENV
env:
CHAIN_VERSION_INPUT: ${{ github.event.inputs.chain_version }}

- name: Set versions
shell: bash
run: |
docker pull ghcr.io/streamingfast/dummy-blockchain:${{ env.CHAIN_VERSION }}
echo VERSION=$(docker inspect --format='{{index .Config.Labels "org.opencontainers.image.version"}}' 'ghcr.io/streamingfast/dummy-blockchain':${{ env.CHAIN_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: |
CHAIN_VERSION=${{ env.CHAIN_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"
# Those 2 Slack actions are there for informational purposes, additional configuration is required to make them work
# properly if not cloned inside `github.com/streamingfast` organization. You need to set up a proper Slack
# Hook and assign the secrets related to it in GitHub Secrets named `SLACK_WEBHOOK`.
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/[email protected]
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/[email protected]
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 }}```
46 changes: 46 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build and Test

on:
push:
branches:
- master
- develop
pull_request:
branches:
- "**"

jobs:
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
go-version: [1.21.x]
os: [ubuntu-latest, macos-latest]
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Check out code
uses: actions/checkout@v3

- name: Cache Go modules
uses: actions/cache@v3
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run Tests
run: go test -v ./...

26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.idea/
.DS_Store

# To facilitate development, you can use [direnv](https://direnv.net/) to auto-load
# some environment variables. We have in `devel` a shim script called directly `fireacme`
# (that should have been renamed to your specific chain like `fireeth`). This small shim
# compiles the project and then invoke resulting binary. This means that when using this
# .envrc file:
#
# ```
# export PATH="`pwd`/devel:$PATH"
# ```
#
# Each time you enter the project in your terminal (e.g. `cd ~/work/firehose-acme`) and then
# do `firehose start --help`, then it first compiles all the Go source code and then invoke the
# resulting just compiled binary, meaning you are "always" freshly compiled, it's more or less
# equivalent to doing directly `go run ./cmd/fireacme start --help` (which is totally fine).
.envrc*
*.spkg

/fireacme
/build
/dist
/build

firehose-data
26 changes: 26 additions & 0 deletions .sfreleaser
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
global:
owner: streamingfast
project: firehose-acme
binary: fireacme
language: golang
variant: application
sfreleaser-min-version: v0.7.0
release:
pre-build-hooks:
- substreams pack -o "{{ .buildDir }}/substreams-acme-{{ .release.Version }}.spkg" substreams.yaml
upload-extra-assets:
- "{{ .buildDir }}/substreams-acme-{{ .release.Version }}.spkg"

# By default we disable Brew publishing because it's assumed that most owner
# of this repository will not have the a Homebrew tap repository created which
# fails the release.
#
# To enable Brew publishing, create an empty repository `<owner>/homebrew-tap`
# which will hold the Homebrew formula.
#
# If you would like to use a different name than `homebrew-tap`, you can define
# brew-tap-repo: <name> below this.
#
# Once available, you can enable the Brew publishing by removing the `brew-disabled`
# line.
brew-disabled: true
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Next

23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM ubuntu:20.04

RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
apt-get -y install -y \
ca-certificates libssl1.1 vim htop iotop sysstat \
dstat strace lsof curl jq tzdata && \
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 /fireacme /app/fireacme

COPY tools/docker/motd_generic /etc/motd
COPY tools/docker/99-firehose.sh /etc/profile.d/

# On SSH connection, /root/.bashrc is invoked which invokes '/root/.bash_aliases' if it exists,
# 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/fireacme"]
17 changes: 17 additions & 0 deletions Dockerfile.bundle
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ARG CHAIN_VERSION=latest
ARG SF_VERSION=latest

# Here you would actually pull from your own chain image, but for the sake of the demo, we use the dummy-blockchain.
# The idea is that you bring together your chain's binary at the right and the firehose-acme's binary into a single
# image.
FROM ghcr.io/streamingfast/dummy-blockchain:$CHAIN_VERSION as chain

# The 'ghcr.io/streamingfast/firehose-acme' image is the one published by
# Dockerfile found at the root of this project.
FROM ghcr.io/streamingfast/firehose-acme:$SF_VERSION

# Adjusted first element of copy to match the path of the binary in the chain image
COPY --from=chain /app/dummy-blockchain /app/dummy-blockchain

COPY tools/docker/motd_node_manager /etc/motd
COPY tools/docker/scripts/. /usr/local/bin/
Loading

0 comments on commit ee7822a

Please sign in to comment.