From 6a786b6b15bb98a0efeae50e8cd19d490bd03803 Mon Sep 17 00:00:00 2001 From: peter <1674920+peterbitfly@users.noreply.github.com> Date: Fri, 5 Apr 2024 11:21:25 +0200 Subject: [PATCH 1/4] add backend docker image --- .github/workflows/backend-publish-docker.yml | 54 ++++++++++++++++++++ backend/Dockerfile | 19 +++++++ backend/Makefile | 28 +++++----- 3 files changed, 88 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/backend-publish-docker.yml create mode 100644 backend/Dockerfile diff --git a/.github/workflows/backend-publish-docker.yml b/.github/workflows/backend-publish-docker.yml new file mode 100644 index 000000000..88037fbd4 --- /dev/null +++ b/.github/workflows/backend-publish-docker.yml @@ -0,0 +1,54 @@ +# +name: Backend docker image + +# Configures this workflow to run every time a change is pushed to the branch called `release`. +on: + push: + paths: + - 'backend/**' + branches: + - main + - implement_dashboard_handlers + +# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }}_backend + +# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. +jobs: + build-and-push-image: + runs-on: ubuntu-latest + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + # + steps: + - name: Checkout repository + uses: actions/checkout@v4 + # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. + - name: Build and push Docker image + uses: docker/build-push-action@v5.1.0 + with: + context: "{{defaultContext}}:backend" + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + secrets: | + NPMRC_FILE=${{ secrets.NPMRC_FILE }} diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 000000000..1a78d1af6 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,19 @@ +FROM golang:1.22.0 AS build-env +COPY go.mod go.sum /src/ +WORKDIR /src +RUN go mod download +ADD . /src +ARG target=all +RUN make -B $target + +# final stage +FROM ubuntu:22.04 +RUN apt-get update && apt-get -y upgrade && apt-get install -y --no-install-recommends \ + libssl-dev \ + ca-certificates \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* +WORKDIR /app +COPY --from=build-env /src/bin /app/ +COPY --from=build-env /src/config /app/config +CMD ["./explorer", "--config", "./config/default.config.yml"] \ No newline at end of file diff --git a/backend/Makefile b/backend/Makefile index 59a412944..d3f270349 100644 --- a/backend/Makefile +++ b/backend/Makefile @@ -4,6 +4,8 @@ GITDATE=`TZ=UTC git show -s --date=iso-strict-local --format=%cd HEAD` BUILDDATE=`date -u +"%Y-%m-%dT%H:%M:%S%:z"` PACKAGE=github.com/gobitfly/beaconchain/pkg/commons LDFLAGS="-X ${PACKAGE}/version.Version=${VERSION} -X ${PACKAGE}/version.BuildDate=${BUILDDATE} -X ${PACKAGE}/version.GitCommit=${GITCOMMIT} -X ${PACKAGE}/version.GitDate=${GITDATE} -s -w" +CGO_CFLAGS="-O -D__BLST_PORTABLE__" +CGO_CFLAGS_ALLOW="-O -D__BLST_PORTABLE__" all: exporter blobindexer misc ethstore-exporter api rewards-exporter eth1indexer stats user-service notification-sender notification-collector node-jobs-processor signatures @@ -17,43 +19,43 @@ binaries: mkdir -p bin exporter: binaries - go build --ldflags=${LDFLAGS} -o ./bin/exporter ./cmd/exporter/main.go + CGO_CFLAGS=${CGO_CFLAGS} CGO_CFLAGS_ALLOW=${CGO_CFLAGS_ALLOW} go build --ldflags=${LDFLAGS} -o ./bin/exporter ./cmd/exporter/main.go blobindexer: binaries - go build --ldflags=${LDFLAGS} -o ./bin/blobindexer ./cmd/blobindexer/main.go + CGO_CFLAGS=${CGO_CFLAGS} CGO_CFLAGS_ALLOW=${CGO_CFLAGS_ALLOW} go build --ldflags=${LDFLAGS} -o ./bin/blobindexer ./cmd/blobindexer/main.go misc: binaries - go build --ldflags=${LDFLAGS} -o ./bin/misc ./cmd/misc/main.go + CGO_CFLAGS=${CGO_CFLAGS} CGO_CFLAGS_ALLOW=${CGO_CFLAGS_ALLOW} go build --ldflags=${LDFLAGS} -o ./bin/misc ./cmd/misc/main.go api: binaries - go build --ldflags=${LDFLAGS} -o ./bin/api ./cmd/api/main.go + CGO_CFLAGS=${CGO_CFLAGS} CGO_CFLAGS_ALLOW=${CGO_CFLAGS_ALLOW} go build --ldflags=${LDFLAGS} -o ./bin/api ./cmd/api/main.go ethstore-exporter: - go build --ldflags=${LDFLAGS} -o bin/ethstore-exporter ./cmd/ethstore_exporter/main.go + CGO_CFLAGS=${CGO_CFLAGS} CGO_CFLAGS_ALLOW=${CGO_CFLAGS_ALLOW} go build --ldflags=${LDFLAGS} -o bin/ethstore-exporter ./cmd/ethstore_exporter/main.go rewards-exporter: - go build --ldflags=${LDFLAGS} -o bin/rewards-exporter ./cmd/rewards_exporter/main.go + CGO_CFLAGS=${CGO_CFLAGS} CGO_CFLAGS_ALLOW=${CGO_CFLAGS_ALLOW} go build --ldflags=${LDFLAGS} -o bin/rewards-exporter ./cmd/rewards_exporter/main.go eth1indexer: - go build --ldflags=${LDFLAGS} -o bin/eth1indexer ./cmd/eth1indexer/main.go + CGO_CFLAGS=${CGO_CFLAGS} CGO_CFLAGS_ALLOW=${CGO_CFLAGS_ALLOW} go build --ldflags=${LDFLAGS} -o bin/eth1indexer ./cmd/eth1indexer/main.go stats: - go build --ldflags=${LDFLAGS} -o bin/statistics ./cmd/statistics/main.go + CGO_CFLAGS=${CGO_CFLAGS} CGO_CFLAGS_ALLOW=${CGO_CFLAGS_ALLOW} go build --ldflags=${LDFLAGS} -o bin/statistics ./cmd/statistics/main.go user-service: - go build --ldflags=${LDFLAGS} -o bin/user-service ./cmd/user_service/main.go + CGO_CFLAGS=${CGO_CFLAGS} CGO_CFLAGS_ALLOW=${CGO_CFLAGS_ALLOW} go build --ldflags=${LDFLAGS} -o bin/user-service ./cmd/user_service/main.go notification-sender: - go build --ldflags=${LDFLAGS} -o bin/notification-sender ./cmd/notification_sender/main.go + CGO_CFLAGS=${CGO_CFLAGS} CGO_CFLAGS_ALLOW=${CGO_CFLAGS_ALLOW} go build --ldflags=${LDFLAGS} -o bin/notification-sender ./cmd/notification_sender/main.go notification-collector: - go build --ldflags=${LDFLAGS} -o bin/notification-collector ./cmd/notification_collector/main.go + CGO_CFLAGS=${CGO_CFLAGS} CGO_CFLAGS_ALLOW=${CGO_CFLAGS_ALLOW} go build --ldflags=${LDFLAGS} -o bin/notification-collector ./cmd/notification_collector/main.go node-jobs-processor: - go build --ldflags=${LDFLAGS} -o bin/node-jobs-processor ./cmd/node_jobs_processor/main.go + CGO_CFLAGS=${CGO_CFLAGS} CGO_CFLAGS_ALLOW=${CGO_CFLAGS_ALLOW} go build --ldflags=${LDFLAGS} -o bin/node-jobs-processor ./cmd/node_jobs_processor/main.go signatures: - go build --ldflags=${LDFLAGS} -o bin/signatures cmd/signatures/main.go + CGO_CFLAGS=${CGO_CFLAGS} CGO_CFLAGS_ALLOW=${CGO_CFLAGS_ALLOW} go build --ldflags=${LDFLAGS} -o bin/signatures cmd/signatures/main.go addhooks: git config core.hooksPath hooks \ No newline at end of file From 2f00e18d8bc36ce13397af823e4e34574db22d11 Mon Sep 17 00:00:00 2001 From: peter <1674920+peterbitfly@users.noreply.github.com> Date: Fri, 5 Apr 2024 13:44:33 +0200 Subject: [PATCH 2/4] fix docker built --- backend/Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 1a78d1af6..eed76d934 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -15,5 +15,4 @@ RUN apt-get update && apt-get -y upgrade && apt-get install -y --no-install-reco && rm -rf /var/lib/apt/lists/* WORKDIR /app COPY --from=build-env /src/bin /app/ -COPY --from=build-env /src/config /app/config -CMD ["./explorer", "--config", "./config/default.config.yml"] \ No newline at end of file +CMD ["./exporter"] \ No newline at end of file From 6b212247ea1c2aa9097ed1e1733a2c436b1afc4c Mon Sep 17 00:00:00 2001 From: peter <1674920+peterbitfly@users.noreply.github.com> Date: Fri, 5 Apr 2024 13:54:05 +0200 Subject: [PATCH 3/4] fix makefile --- backend/Makefile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/backend/Makefile b/backend/Makefile index d3f270349..7fb20593c 100644 --- a/backend/Makefile +++ b/backend/Makefile @@ -1,9 +1,6 @@ -GITCOMMIT=`git describe --always` -VERSION=`git describe --always --tags` -GITDATE=`TZ=UTC git show -s --date=iso-strict-local --format=%cd HEAD` BUILDDATE=`date -u +"%Y-%m-%dT%H:%M:%S%:z"` PACKAGE=github.com/gobitfly/beaconchain/pkg/commons -LDFLAGS="-X ${PACKAGE}/version.Version=${VERSION} -X ${PACKAGE}/version.BuildDate=${BUILDDATE} -X ${PACKAGE}/version.GitCommit=${GITCOMMIT} -X ${PACKAGE}/version.GitDate=${GITDATE} -s -w" +LDFLAGS="-X ${PACKAGE}/version.BuildDate=${BUILDDATE} -s -w" CGO_CFLAGS="-O -D__BLST_PORTABLE__" CGO_CFLAGS_ALLOW="-O -D__BLST_PORTABLE__" From cd9cf2109649c69ad295721472a8d61cae0225df Mon Sep 17 00:00:00 2001 From: peter <1674920+peterbitfly@users.noreply.github.com> Date: Fri, 5 Apr 2024 13:55:00 +0200 Subject: [PATCH 4/4] adjust ci --- .github/workflows/backend-publish-docker.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/backend-publish-docker.yml b/.github/workflows/backend-publish-docker.yml index 88037fbd4..be9d690a0 100644 --- a/.github/workflows/backend-publish-docker.yml +++ b/.github/workflows/backend-publish-docker.yml @@ -8,7 +8,6 @@ on: - 'backend/**' branches: - main - - implement_dashboard_handlers # Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. env: