Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Container Images] Changes to integrate us with heighliner #519

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/container-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# name: Create and Push Container Image (heighliner)

# on:
# push:
# tags:
# - "**"
# branches:
# - "**"

# jobs:
# build-and-push-image:
# runs-on: ubuntu-latest
# permissions:
# contents: read
# packages: write

# steps:
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v2

# - name: Log in to the Container registry
# uses: docker/login-action@v2
# with:
# registry: ghcr.io
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}

# - name: Build and push Docker image
# uses: strangelove-ventures/[email protected]
# with:
# chain: pocket-network
# dockerfile: cosmos
# platform: linux/arm64,linux/amd64
# pre-build: |
# make -d heighliner_pre_build
# build-target: |
# make -d heighliner_build
# binaries: |
# - /go/bin/poktrolld
2 changes: 1 addition & 1 deletion .github/workflows/label-actions.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Label Actions'
name: "Label Actions"

on:
issues:
Expand Down
17 changes: 6 additions & 11 deletions .github/workflows/main-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,18 @@ jobs:
build-push-container:
runs-on: ubuntu-latest
steps:
- name: install ignite
# TODO_TECHDEBT: upgrade to the latest Ignite (the latest at the moment of creating a note is 0.28). Need to downgrade to fix CI pipelines. Might be done in scope of #240.
run: |
# curl https://get.ignite.com/cli! | bash
wget https://github.com/ignite/cli/releases/download/v28.2.0/ignite_28.2.0_linux_amd64.tar.gz
tar -xzf ignite_28.2.0_linux_amd64.tar.gz
sudo mv ignite /usr/local/bin/ignite
ignite version

- uses: actions/checkout@v3
with:
fetch-depth: "0" # Per https://github.com/ignite/cli/issues/1674#issuecomment-1144619147

- name: install ignite
run: |
make ignite_install

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.21.6"
go-version: "1.22.2"

- name: Install CI dependencies
run: make install_ci_deps
Expand All @@ -54,7 +49,7 @@ jobs:
images: |
ghcr.io/pokt-network/poktrolld
tags: |
type=ref,event=branch
type=ref,event=branch,suffix=-dev
type=ref,event=pr
type=sha
type=sha,format=long
Expand Down
94 changes: 94 additions & 0 deletions .github/workflows/release-artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Release artifacts

# Currently disabled, but ready to implement a CI job to add binaries to GitHub releases.
on:
push:
branches: ["dk-heighliner"]
# pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true

jobs:
release-artifacts:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: "0" # Per https://github.com/ignite/cli/issues/1674#issuecomment-1144619147
- name: install ignite
run: |
make ignite_install

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.22.2"

- name: Install CI dependencies
run: make install_ci_deps

- name: Generate protobufs
run: make proto_regen

- name: Generate mocks
run: make go_mockgen

- name: Build binaries
run: make ignite_release

- name: Unarchive linux binaries for Docker to consume
run: make ignite_release_extract_binaries

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker Metadata action
id: meta
uses: docker/metadata-action@v5
env:
DOCKER_METADATA_PR_HEAD_SHA: "true"
with:
images: |
ghcr.io/pokt-network/poktrolld
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=ref,event=tag,suffix=-prod
type=sha,suffix=-prod
type=sha,format=long,suffix=-prod

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
file: Dockerfile.release
cache-from: type=gha
cache-to: type=gha,mode=max
context: .

# TODO(@okdas): when we have proper releases, we can remove this and use binaries built by releases instead.
# But for now, attach them to commits so we/community can access them
- name: Add binaries to commit
uses: actions/upload-artifact@v4
with:
name: poktrolld
path: release/

# TODO(@okdas): use for releases (also change the "on" part at the top so it only tgirrered for tags/releases)
# - name: Add release and publish binaries
# uses: softprops/action-gh-release@v1
# with:
# files: |
# release/*
3 changes: 1 addition & 2 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,4 @@ jobs:
reporter: github-check
level: warning
locale: "US"

# TODO_IMPROVE: Enforce using k.Logger() when logging in the `x/` directory code.
# TODO_IMPROVE: Enforce using k.Logger() when logging in the `x/` directory code.
15 changes: 5 additions & 10 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,18 @@ jobs:
go-test:
runs-on: ubuntu-latest
steps:
- name: install ignite
# TODO_TECHDEBT: upgrade to the latest Ignite (the latest at the moment of creating a note is 0.28). Need to downgrade to fix CI pipelines. Might be done in scope of #240.
run: |
# curl https://get.ignite.com/cli! | bash
wget https://github.com/ignite/cli/releases/download/v28.2.0/ignite_28.2.0_linux_amd64.tar.gz
tar -xzf ignite_28.2.0_linux_amd64.tar.gz
sudo mv ignite /usr/local/bin/ignite
ignite version

- uses: actions/checkout@v3
with:
fetch-depth: "0" # Per https://github.com/ignite/cli/issues/1674#issuecomment-1144619147

- name: install ignite
run: |
make ignite_install

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.21.6"
go-version: "1.22.2"

- name: Install CI dependencies
run: make install_ci_deps
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ api/poktroll/**/*.go-E

# Relase artifacts produced by `ignite chain build --release`
release
release_binaries

# Only keep one go module in our codebase
go.work.sum
Expand All @@ -92,4 +93,4 @@ summary.html
shannon_appgate_config.yaml
shannon_app_config.yaml

gentx-*.json
gentx-*.json
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Run `asdf plugin add golang` and `asdf install` to install the dependencies,
# and `asdf current` to switch to the versions of dependencies listed below
golang 1.21.6
go 1.21.6
golang 1.22.2
go 1.22.2
2 changes: 1 addition & 1 deletion Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This Dockerfile is used to build container image for development purposes.
# It intentionally contains no security features, ships with code and troubleshooting tools.

FROM golang:1.21.6 as base
FROM golang:1.22.2 as base

RUN apt update && \
apt-get install -y \
Expand Down
13 changes: 13 additions & 0 deletions Dockerfile.release
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This Dockerfile is used to build container image for production workloads.
# It relies on the binaries produced by `ignite_release` and `ignite_release_extract_binaries` make targets.
FROM alpine:3.19
ARG TARGETARCH

# Use `1025` G/UID so users can switch between this and `heighliner` image without a need to chown the files.
RUN addgroup --gid 1025 -S pocket && adduser --uid 1025 -S pocket -G pocket

COPY --chown=pocket:pocket release_binaries/poktroll_linux_$TARGETARCH /bin/poktrolld

USER pocket

ENTRYPOINT ["poktrolld"]
93 changes: 88 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,45 @@ SUPPLIER_MODULE_ADDRESS = pokt1j40dzzmn6cn9kxku7a5tjnud6hv37vesr5ccaa
GATEWAY_MODULE_ADDRESS = pokt1f6j7u6875p2cvyrgjr0d2uecyzah0kget9vlpl
SERVICE_MODULE_ADDRESS = pokt1nhmtqf4gcmpxu0p6e53hpgtwj0llmsqpxtumcf

# Detect operating system
OS := $(shell uname -s)
# Detect operating system and arch
OS := $(shell uname -s | tr A-Z a-z)
ARCH := $(shell uname -m)
ifeq ($(ARCH),x86_64)
ARCH := amd64
endif
ifeq ($(ARCH),aarch64)
ARCH := arm64
endif

# Set default commands, will potentially be overridden on macOS
SED := sed
GREP := grep

BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
COMMIT := $(shell git log -1 --format='%H')

# don't override user values
ifeq (,$(VERSION))
# Remove 'v' prefix from git tag and assign to VERSION
VERSION := $(shell git describe --tags 2>/dev/null | sed 's/^v//')
# if VERSION is empty, then populate it with branch's name and raw commit hash
ifeq (,$(VERSION))
VERSION := $(BRANCH)-$(COMMIT)
endif
endif


ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=Poktroll \
-X github.com/cosmos/cosmos-sdk/version.AppName=poktrolld \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X github.com/cosmos/cosmos-sdk/version.BuildTags= \
-X github.com/pokt-network/poktroll/cmd/poktrolld/cmd.ChainID=$(CHAIN_ID)
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))

# macOS-specific adjustments
ifeq ($(OS),Darwin)
ifeq ($(OS),darwin)
# Check for gsed and ggrep, suggest installation with Homebrew if not found
FOUND_GSED := $(shell command -v gsed)
FOUND_GGREP := $(shell command -v ggrep)
Expand Down Expand Up @@ -234,14 +264,13 @@ proto_fix_self_import: ## TODO_TECHDEBT(@bryanchriswhite): Add a proper explanat
@for dir in $(wildcard ./api/poktroll/*/); do \
module=$$(basename $$dir); \
echo "Further processing module $$module"; \
$(GREP) -lRP '\s+'$$module' "github.com/pokt-network/poktroll/api/poktroll/'$$module'"' ./api/poktroll/$$module | while read -r file; do \
$(GREP) -lRE '[[:space:]]+'$$module' "github.com/pokt-network/poktroll/api/poktroll/'$$module'"' $$dir | while read -r file; do \
echo "Modifying file: $$file"; \
$(SED) -i -E 's,^[[:space:]]+'$$module'[[:space:]]+"github.com/pokt-network/poktroll/api/poktroll/'$$module'",,' "$$file"; \
$(SED) -i 's,'$$module'\.,,g' "$$file"; \
done; \
done


.PHONY: proto_clean
proto_clean: ## Delete existing .pb.go or .pb.gw.go files
find . \( -name "*.pb.go" -o -name "*.pb.gw.go" \) | xargs --no-run-if-empty rm
Expand Down Expand Up @@ -809,6 +838,60 @@ trigger_ci: ## Trigger the CI pipeline by submitting an empty commit; See https:
git commit --allow-empty -m "Empty commit"
git push

.PHONY: install
install: ## Build and install the binary
go install -mod readonly -tags "" -ldflags "$(ldflags)" ./cmd/poktrolld

.PHONY: ignite_install
ignite_install: ## Install ignite. Used by CI and heighliner.
# Determine if sudo is available and use it if it is
if command -v sudo &>/dev/null; then \
SUDO="sudo"; \
else \
SUDO=""; \
fi; \
echo "Downloading Ignite CLI..."; \
wget https://github.com/ignite/cli/releases/download/v28.3.0/ignite_28.3.0_$(OS)_$(ARCH).tar.gz; \
echo "Extracting Ignite CLI..."; \
tar -xzf ignite_28.3.0_$(OS)_$(ARCH).tar.gz; \
echo "Moving Ignite CLI to /usr/local/bin..."; \
$$SUDO mv ignite /usr/local/bin/ignite; \
echo "Cleaning up..."; \
rm ignite_28.3.0_$(OS)_$(ARCH).tar.gz; \
ignite version

.PHONY: heighliner_pre_build
heighliner_pre_build: # Steps to execute during pre-build phase in heighliner. Having this step here makes it so we don't need to submit a PR on their side if we want to change something.
apk add gcompat
go install github.com/bufbuild/buf/cmd/[email protected]
make ignite_install
make proto_regen

.PHONY: heighliner_build
heighliner_build: # Steps to execute during pre-build phase in heighliner. Having this step here makes it so we don't need to submit a PR on their side if we want to change something.
make install

# .PHONY: heighliner_use_prebuilt_binaries
# heighliner_use_prebuilt_binaries: # Uses binaries prebuilt by ignite
# apk add gcompat
# go install github.com/bufbuild/buf/cmd/[email protected]
# make ignite_install
# make proto_regen

.PHONY: ignite_release
ignite_release: ## Builds production binaries
ignite chain build --release -t linux:amd64 -t linux:arm64 -t darwin:amd64 -t darwin:arm64

.PHONY: ignite_release_extract_binaries
ignite_release_extract_binaries: ## Extracts binaries from the release archives
mkdir -p release_binaries

for archive in release/*.tar.gz; do \
binary_name=$$(basename "$$archive" .tar.gz); \
tar -zxvf "$$archive" -C release_binaries "poktrolld"; \
mv release_binaries/poktrolld "release_binaries/$$binary_name"; \
done

#####################
### Documentation ###
#####################
Expand Down
2 changes: 1 addition & 1 deletion Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ local_resource(
docker_build_with_restart(
"poktrolld",
".",
dockerfile_contents="""FROM golang:1.21.6
dockerfile_contents="""FROM golang:1.22.2
RUN apt-get -q update && apt-get install -qyy curl jq less
RUN go install github.com/go-delve/delve/cmd/dlv@latest
COPY bin/poktrolld /usr/local/bin/poktrolld
Expand Down
Loading
Loading