diff --git a/.github/workflows/backend-publish-docker.yml b/.github/workflows/backend-publish-docker.yml new file mode 100644 index 000000000..be9d690a0 --- /dev/null +++ b/.github/workflows/backend-publish-docker.yml @@ -0,0 +1,53 @@ +# +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 + +# 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..eed76d934 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,18 @@ +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/ +CMD ["./exporter"] \ No newline at end of file diff --git a/backend/Makefile b/backend/Makefile index 59a412944..7fb20593c 100644 --- a/backend/Makefile +++ b/backend/Makefile @@ -1,9 +1,8 @@ -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__" all: exporter blobindexer misc ethstore-exporter api rewards-exporter eth1indexer stats user-service notification-sender notification-collector node-jobs-processor signatures @@ -17,43 +16,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