From 981dcc5a91f5c3066caa4494fa1acfda106949b1 Mon Sep 17 00:00:00 2001 From: Nikolay Eskov Date: Thu, 30 Apr 2026 15:21:31 +0300 Subject: [PATCH 1/5] Add new build targets to 'Makefile'. --- Makefile | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 5abdb78e..3153fa64 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,9 @@ clean: rm -r build/ build: - @go build -o build/nodemon -ldflags="-X 'nodemon/internal.version=$(VERSION)'" ./cmd/nodemon + @go build -o build/native/nodemon -ldflags="-X 'nodemon/internal.version=$(VERSION)'" ./cmd/nodemon + @go build -o build/native/nodemon-telegram -ldflags="-X 'nodemon/internal.version=$(VERSION)'" ./cmd/bots/telegram + @go build -o build/native/nodemon-discord -ldflags="-X 'nodemon/internal.version=$(VERSION)'" ./cmd/bots/discord gotest: go test -cover -race -covermode=atomic ./... @@ -29,9 +31,24 @@ gotest: mod-clean: go mod tidy -build-bots-linux-amd64: +build-bots-linux-amd64: build-nodemon-telegram-linux-amd64 build-nodemon-discord-linux-amd64 + +build-nodemon-telegram-linux-amd64: @CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/linux-amd64/nodemon-telegram -ldflags="-X 'nodemon/internal.version=$(VERSION)'" ./cmd/bots/telegram + +build-nodemon-discord-linux-amd64: @CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/linux-amd64/nodemon-discord -ldflags="-X 'nodemon/internal.version=$(VERSION)'" ./cmd/bots/discord +build-bots-linux-arm64: build-nodemon-telegram-linux-arm64 build-nodemon-discord-linux-arm64 + +build-nodemon-telegram-linux-arm64: + @CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o build/linux-arm64/nodemon-telegram -ldflags="-X 'nodemon/internal.version=$(VERSION)'" ./cmd/bots/telegram + +build-nodemon-discord-linux-arm64: + @CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o build/linux-arm64/nodemon-discord -ldflags="-X 'nodemon/internal.version=$(VERSION)'" ./cmd/bots/discord + +build-nodemon-linux-arm64: + @CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o build/linux-arm64/nodemon -ldflags="-X 'nodemon/internal.version=$(VERSION)'" ./cmd/nodemon + build-nodemon-linux-amd64: @CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/linux-amd64/nodemon -ldflags="-X 'nodemon/internal.version=$(VERSION)'" ./cmd/nodemon From 2295d45ceeedb8c3229c712527c65b56069db758 Mon Sep 17 00:00:00 2001 From: Nikolay Eskov Date: Thu, 30 Apr 2026 16:22:04 +0300 Subject: [PATCH 2/5] Add universal 'Dockerfile' for all binares in the repository. --- Dockerfile | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..df490df0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,56 @@ +FROM golang:1.26-alpine3.22@sha256:07e91d24f6330432729082bb580983181809e0a48f0f38ecde26868d4568c6ac AS builder +ARG DIR=/app +WORKDIR ${DIR} + +ARG APP=nodemon +ARG TARGETOS +ARG TARGETARCH + +RUN apk add --no-cache make git +# disable cgo for go build +ENV CGO_ENABLED=0 + +COPY go.mod . +COPY go.sum . + +RUN go mod download + +# Copy the .git directory and restore the worktree, also handle current possible changes in go.mod and go.sum +COPY .git .git +RUN git restore --source=HEAD --worktree . +COPY go.mod . +COPY go.sum . + +# Copy the necessary files for building and override the restored worktree +COPY Makefile . +COPY cmd . +COPY pkg . +COPY internal internal + +RUN make build-$APP-$TARGETOS-$TARGETARCH + +FROM alpine:3.23@sha256:5b10f432ef3da1b8d4c7eb6c487f2f5a8f096bc91145e68878dd4a5019afde11 +ARG DIR=/app +ENV TZ=Etc/UTC \ + APP_USER=appuser + +ARG APP=nodemon +ARG TARGETOS +ARG TARGETARCH + +STOPSIGNAL SIGINT + +RUN addgroup -S $APP_USER \ + && adduser -S $APP_USER -G $APP_USER + +RUN apk add --no-cache bind-tools + +USER $APP_USER +WORKDIR ${DIR} +# Considered as a default HTTP API Port, NATS embedded server port +EXPOSE 8080 +EXPOSE 4222 + +COPY --from=builder ${DIR}/build/$TARGETOS-$TARGETARCH/$APP ${DIR}/$APP + +ENTRYPOINT ["./$APP"] From c8d949ab7836046ed36459c1f2fb171a58e40853 Mon Sep 17 00:00:00 2001 From: Nikolay Eskov Date: Thu, 30 Apr 2026 16:50:51 +0300 Subject: [PATCH 3/5] Add new publich to GHCR workflow. --- .github/workflows/publish-to-ghcr.yml | 109 ++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 .github/workflows/publish-to-ghcr.yml diff --git a/.github/workflows/publish-to-ghcr.yml b/.github/workflows/publish-to-ghcr.yml new file mode 100644 index 00000000..d3a478cf --- /dev/null +++ b/.github/workflows/publish-to-ghcr.yml @@ -0,0 +1,109 @@ +name: Publish Docker Image to GitHub Container Registry +run-name: Publish branch ${{ github.ref_name }} to tag ${{ inputs.dockerTag }} + +on: + workflow_dispatch: + inputs: + dockerTag: + description: 'Docker Tag' + required: true + type: string + default: 'latest' + container: + type: choice + description: 'Container to build and publish.' + required: true + options: + - nodemon + - nodemon-telegram + - nodemon-discord + workflow_call: + inputs: + dockerTag: + description: 'Docker Tag' + required: true + type: string + default: 'latest' + container: + type: string + description: 'Container to build and publish (nodemon, nodemon-telegram, nodemon-discord).' + required: true + default: 'nodemon' + +env: + IMAGE_TAG: ${{ inputs.dockerTag }} + IMAGE_ARG_APP: ${{ inputs.container }} + IMAGE_NAME: |- + ghcr.io/${{ github.repository }}${{ + case( + inputs.container, + 'nodemon', '', + 'nodemon-telegram', '-telegram', + 'nodemon-discord', '-discord', + '' + ) + }} + +permissions: { } + +jobs: + build: + name: Build and Push Docker Image to GitHub Container Registry + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + attestations: write + id-token: write + steps: + - name: Check inputs + env: + IMAGE_ARG_APP: ${{ env.IMAGE_ARG_APP }} + IMAGE_TAG: ${{ env.IMAGE_TAG }} + run: | + echo "IMAGE_TAG" | grep -E '^[a-zA-Z0-9._-]+$' || exit 1 # check if the docker tag is valid + echo "$IMAGE_ARG_APP" | grep -E '^(nodemon|nodemon-telegram|nodemon-discord)$' || exit 1 # check if the container name is valid + + - name: Check out code into the Go module directory + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v5 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Login to GitHub Container Registry + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker BuildX + uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 + + - name: Docker Metadata + id: meta + uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0 + with: + images: ${{ env.IMAGE_NAME }} + flavor: latest=false + tags: | + type=sha + type=raw,value=${{ env.IMAGE_TAG }} + labels: | + org.opencontainers.image.source=https://github.com/${{ github.repository }} + org.opencontainers.image.licenses=MIT + org.opencontainers.image.description="Nodemonitoring and alerting tools for Waves Nodes" + + - name: Build and Push Docker Image + uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v5 + id: push + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + pull: true + build-args: 'APP=${{ env.IMAGE_ARG_APP }}' + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max From 7946d8ed96c4c4a47eaca826860a3fb0ecbfdec2 Mon Sep 17 00:00:00 2001 From: Nikolay Eskov Date: Thu, 30 Apr 2026 17:13:56 +0300 Subject: [PATCH 4/5] Update .github/workflows/publish-to-ghcr.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/publish-to-ghcr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-to-ghcr.yml b/.github/workflows/publish-to-ghcr.yml index d3a478cf..03c00efa 100644 --- a/.github/workflows/publish-to-ghcr.yml +++ b/.github/workflows/publish-to-ghcr.yml @@ -61,7 +61,7 @@ jobs: IMAGE_ARG_APP: ${{ env.IMAGE_ARG_APP }} IMAGE_TAG: ${{ env.IMAGE_TAG }} run: | - echo "IMAGE_TAG" | grep -E '^[a-zA-Z0-9._-]+$' || exit 1 # check if the docker tag is valid + echo "$IMAGE_TAG" | grep -E '^[a-zA-Z0-9._-]+$' || exit 1 # check if the docker tag is valid echo "$IMAGE_ARG_APP" | grep -E '^(nodemon|nodemon-telegram|nodemon-discord)$' || exit 1 # check if the container name is valid - name: Check out code into the Go module directory From 86e1b1eb1f53284b7e9e99327975b20e939dd37e Mon Sep 17 00:00:00 2001 From: Nikolay Eskov Date: Thu, 30 Apr 2026 17:20:50 +0300 Subject: [PATCH 5/5] Fixed copilot issue. --- .github/workflows/publish-to-ghcr.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish-to-ghcr.yml b/.github/workflows/publish-to-ghcr.yml index 03c00efa..76614638 100644 --- a/.github/workflows/publish-to-ghcr.yml +++ b/.github/workflows/publish-to-ghcr.yml @@ -36,10 +36,9 @@ env: IMAGE_NAME: |- ghcr.io/${{ github.repository }}${{ case( - inputs.container, - 'nodemon', '', - 'nodemon-telegram', '-telegram', - 'nodemon-discord', '-discord', + inputs.container == 'nodemon', '', + inputs.container == 'nodemon-telegram', '-telegram', + inputs.container == 'nodemon-discord', '-discord', '' ) }}