From d039e4615723b7c07fff415dea7bb4670987f898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederik=20Sch=C3=B6ll?= Date: Wed, 4 Sep 2024 11:47:13 +0200 Subject: [PATCH] add Docker images (#156) * add Docker images * remove branch builds --- .github/workflows/docker.yml | 66 ++++++++++++++++++++++++++++++++++++ Dockerfile | 49 +++++++++++++++++--------- 2 files changed, 99 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..d872c28 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,66 @@ +name: Build docker image + +on: + push: + tags: + - "v*" + branches: + - "dockerbuild" + - "develop" +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + + build: + runs-on: ubuntu-22.04 + + permissions: + contents: read + packages: write + + outputs: + tags: ${{ steps.meta.outputs.tags }} + + steps: + - uses: actions/checkout@v4 + + - name: Branch name + id: extract_branch + shell: bash + run: | + echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT + echo "release_train=$(echo ${GITHUB_REF#refs/heads/release/})" >> $GITHUB_OUTPUT + echo "core_version=$(grep 'github.com/streamingfast/firehose-core' go.mod | cut -d' ' -f2)" >> $GITHUB_OUTPUT + + - name: Log in to the Container registry + uses: docker/login-action@v3 + 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@v5 + 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@v6 + with: + context: . + push: true + build-args: | + VERSION=${{ github.event.ref }} + COREVERSION=${{ steps.extract_branch.outputs.core_version }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index bbed09f..ecf52f1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,41 @@ -# syntax=docker/dockerfile:1.2 +ARG COREVERSION="latest" -FROM ubuntu:20.04 +FROM golang:1.22-alpine as build +WORKDIR /app -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/* +COPY go.mod go.sum ./ +RUN go mod download -RUN rm /etc/localtime && ln -snf /usr/share/zoneinfo/America/Montreal /etc/localtime && dpkg-reconfigure -f noninteractive tzdata +COPY . ./ -RUN mkdir /tmp/wasmer-install && cd /tmp/wasmer-install && \ - curl -L https://github.com/wasmerio/wasmer/releases/download/2.3.0/wasmer-linux-amd64.tar.gz | tar xzf - && \ - mv lib/libwasmer.a lib/libwasmer.so /usr/lib/ && cd / && rm -rf /tmp/wasmer-install +# to get buildinfo in golang +RUN apk add git +ARG VERSION="dev" +RUN go build -v -ldflags "-X main.version=${VERSION}" ./cmd/fireantelope -ADD /fireantelope /app/fireantelope +#### -COPY tools/fireantelope/motd_generic /etc/ -COPY tools/fireantelope/motd_node_manager /etc/ -COPY tools/fireantelope/99-firehose.sh /etc/profile.d/ -COPY tools/fireantelope/scripts/* /usr/local/bin +FROM ghcr.io/streamingfast/firehose-core:${COREVERSION} as core + +#### + +FROM alpine:3 + +ENV PATH "$PATH:/app" + +#COPY tools/fireeth/motd_generic /etc/motd +#COPY tools/fireeth/99-fireeth.sh /etc/profile.d/ +#RUN echo ". /etc/profile.d/99-fireeth.sh" > /root/.bash_aliases + +RUN apk --no-cache add \ + ca-certificates htop iotop sysstat \ + strace lsof curl jq tzdata bash + +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 + +WORKDIR /app + +COPY --from=build /app/fireantelope /app/fireantelope +COPY --from=core /app/firecore /app/firecore ENTRYPOINT ["/app/fireantelope"]