Skip to content

Commit

Permalink
[CI] Build container images (#107)
Browse files Browse the repository at this point in the history
* wip - need info from GitHub CI

* build image as a part of main ci

* troublshoot w/o test

* should be a cp here

* wip

* more label control

* install directly from github

* use wget

* rerun ci

* troubleshoot

* more information

* it was git context

* kill previous run if a new commit is pushed

* this should work

* remove buildlog

* resolve conflicts

* perform the tests as well

* we will be allright withoug keeping the bin dir

* bring back ignite version

* also build on mai

* refine label actions

* Update .github/workflows/go.yml

Co-authored-by: Daniel Olshansky <[email protected]>

* add requested changes

* pocketd has been replaced with poktrolld

* only change the binary name for now, take care of other pocketd instances later

* Update .github/label-actions.yml

Co-authored-by: Daniel Olshansky <[email protected]>

* rename pocketd with poktrolld where necessary

* typofix

* also use poktrolld for e2e tests

---------

Co-authored-by: Daniel Olshansky <[email protected]>
  • Loading branch information
okdas and Olshansk committed Nov 7, 2023
1 parent d204d14 commit 21edfe7
Show file tree
Hide file tree
Showing 16 changed files with 171 additions and 29 deletions.
35 changes: 35 additions & 0 deletions .github/label-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# When `devnet-e2e-test` is added, also assign `devnet` to the PR.
devnet-e2e-test:
prs:
comment: The CI will now also run the e2e tests on devnet, which increases the time it takes to complete all CI checks.
label:
- devnet

# When `devnet-e2e-test` is removed, also delete `devnet` from the PR.
-devnet-e2e-test:
prs:
unlabel:
- devnet

# When `devnet` is added, also assign `push-image` to the PR.
devnet:
prs:
label:
- push-image

# When `devnet` is removed, also delete `devnet-e2e-test` from the PR.
-devnet:
prs:
unlabel:
- devnet-e2e-test

# Let the developer know that they need to push another commit after attaching the label to PR.
push-image:
prs:
comment: The image is going to be pushed after the next commit. If you want to run an e2e test, it is necessary to push another commit. You can use `make trigger_ci` to push an empty commit.

# When `push-image` is removed, also delete `devnet` from the PR.
-push-image:
prs:
unlabel:
- devnet
54 changes: 53 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ on:
branches: ["main"]
pull_request:

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

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: install ignite
# If this step fails due to ignite.com failing, see #116 for a temporary workaround
run: |
curl https://get.ignite.com/cli! | bash
ignite version
Expand All @@ -39,7 +44,54 @@ jobs:
run: make go_lint

- name: Build
run: ignite chain build --debug --skip-proto
run: ignite chain build -v --debug --skip-proto

- name: Test
run: make go_test

- name: Set up Docker Buildx
if: (github.ref == 'refs/heads/main') || (contains(github.event.pull_request.labels.*.name, 'push-image'))
uses: docker/setup-buildx-action@v3

- name: Docker Metadata action
if: (github.ref == 'refs/heads/main') || (contains(github.event.pull_request.labels.*.name, 'push-image'))
id: meta
uses: docker/metadata-action@v5
env:
DOCKER_METADATA_PR_HEAD_SHA: "true"
with:
images: |
ghcr.io/pokt-network/pocketd
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha
type=sha,format=long
- name: Login to GitHub Container Registry
if: (github.ref == 'refs/heads/main') || (contains(github.event.pull_request.labels.*.name, 'push-image'))
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Copy binary to inside of the Docker context
if: (github.ref == 'refs/heads/main') || (contains(github.event.pull_request.labels.*.name, 'push-image'))
run: |
mkdir -p ./bin # Make sure the bin directory exists
cp $(go env GOPATH)/bin/poktrolld ./bin # Copy the binary to the repo's bin directory
- name: Build and push Docker image
if: (github.ref == 'refs/heads/main') || (contains(github.event.pull_request.labels.*.name, 'push-image'))
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# NB: Uncomment below if arm64 build is needed; arm64 builds are off by default because build times are significant.
platforms: linux/amd64 #,linux/arm64
file: Dockerfile.dev
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
21 changes: 21 additions & 0 deletions .github/workflows/label-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'Label Actions'

on:
issues:
types: [labeled, unlabeled]
pull_request_target:
types: [labeled, unlabeled]
discussion:
types: [labeled, unlabeled]

permissions:
contents: read
issues: write
pull-requests: write
discussions: write

jobs:
action:
runs-on: ubuntu-latest
steps:
- uses: dessant/label-actions@v3
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ go.work

# Don't commit binaries
bin
!bin/.keep

# Before we provision the localnet, `ignite` creates the accounts, genesis, etc. for us
# As many of the files are dynamic, we only preserve the config files in git history.
Expand Down Expand Up @@ -57,4 +56,7 @@ ts-client/
**/*_mock.go

# Localnet config
localnet_config.yaml
localnet_config.yaml

# Relase artifacts produced by `ignite chain build --release`
release
23 changes: 23 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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.20 as base

RUN apt update && \
apt-get install -y \
ca-certificates \
curl jq make

# enable faster module downloading.
ENV GOPROXY https://proxy.golang.org

COPY . /poktroll

WORKDIR /poktroll

RUN mv /poktroll/bin/poktrolld /usr/bin/poktrolld

EXPOSE 8545
EXPOSE 8546

ENTRYPOINT ["ignite"]
37 changes: 23 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ todo_this_commit: ## List all the TODOs needed to be done in this commit

.PHONY: gateway_list
gateway_list: ## List all the staked gateways
pocketd --home=$(POCKETD_HOME) q gateway list-gateway --node $(POCKET_NODE)
poktrolld --home=$(POCKETD_HOME) q gateway list-gateway --node $(POCKET_NODE)

.PHONY: gateway_stake
gateway_stake: ## Stake tokens for the gateway specified (must specify the gateway env var)
pocketd --home=$(POCKETD_HOME) tx gateway stake-gateway 1000upokt --keyring-backend test --from $(GATEWAY) --node $(POCKET_NODE)
poktrolld --home=$(POCKETD_HOME) tx gateway stake-gateway 1000upokt --keyring-backend test --from $(GATEWAY) --node $(POCKET_NODE)

.PHONY: gateway1_stake
gateway1_stake: ## Stake gateway1
Expand All @@ -251,7 +251,7 @@ gateway3_stake: ## Stake gateway3

.PHONY: gateway_unstake
gateway_unstake: ## Unstake an gateway (must specify the GATEWAY env var)
pocketd --home=$(POCKETD_HOME) tx gateway unstake-gateway --keyring-backend test --from $(GATEWAY) --node $(POCKET_NODE)
poktrolld --home=$(POCKETD_HOME) tx gateway unstake-gateway --keyring-backend test --from $(GATEWAY) --node $(POCKET_NODE)

.PHONY: gateway1_unstake
gateway1_unstake: ## Unstake gateway1
Expand All @@ -271,11 +271,11 @@ gateway3_unstake: ## Unstake gateway3

.PHONY: app_list
app_list: ## List all the staked applications
pocketd --home=$(POCKETD_HOME) q application list-application --node $(POCKET_NODE)
poktrolld --home=$(POCKETD_HOME) q application list-application --node $(POCKET_NODE)

.PHONY: app_stake
app_stake: ## Stake tokens for the application specified (must specify the APP and SERVICES env vars)
pocketd --home=$(POCKETD_HOME) tx application stake-application 1000upokt $(SERVICES) --keyring-backend test --from $(APP) --node $(POCKET_NODE)
poktrolld --home=$(POCKETD_HOME) tx application stake-application 1000upokt $(SERVICES) --keyring-backend test --from $(APP) --node $(POCKET_NODE)

.PHONY: app1_stake
app1_stake: ## Stake app1
Expand All @@ -291,7 +291,7 @@ app3_stake: ## Stake app3

.PHONY: app_unstake
app_unstake: ## Unstake an application (must specify the APP env var)
pocketd --home=$(POCKETD_HOME) tx application unstake-application --keyring-backend test --from $(APP) --node $(POCKET_NODE)
poktrolld --home=$(POCKETD_HOME) tx application unstake-application --keyring-backend test --from $(APP) --node $(POCKET_NODE)

.PHONY: app1_unstake
app1_unstake: ## Unstake app1
Expand All @@ -307,7 +307,7 @@ app3_unstake: ## Unstake app3

.PHONY: app_delegate
app_delegate: ## Delegate trust to a gateway (must specify the APP and GATEWAY_ADDR env vars). Requires the app to be staked
pocketd --home=$(POCKETD_HOME) tx application delegate-to-gateway $(GATEWAY_ADDR) --keyring-backend test --from $(APP) --node $(POCKET_NODE)
poktrolld --home=$(POCKETD_HOME) tx application delegate-to-gateway $(GATEWAY_ADDR) --keyring-backend test --from $(APP) --node $(POCKET_NODE)

.PHONY: app1_delegate_gateway1
app1_delegate_gateway1: ## Delegate trust to gateway1
Expand All @@ -323,7 +323,7 @@ app3_delegate_gateway3: ## Delegate trust to gateway3

.PHONY: app_undelegate
app_undelegate: ## Undelegate trust to a gateway (must specify the APP and GATEWAY_ADDR env vars). Requires the app to be staked
pocketd --home=$(POCKETD_HOME) tx application undelegate-from-gateway $(GATEWAY_ADDR) --keyring-backend test --from $(APP) --node $(POCKET_NODE)
poktrolld --home=$(POCKETD_HOME) tx application undelegate-from-gateway $(GATEWAY_ADDR) --keyring-backend test --from $(APP) --node $(POCKET_NODE)

.PHONY: app1_undelegate_gateway1
app1_undelegate_gateway1: ## Undelegate trust to gateway1
Expand All @@ -343,13 +343,13 @@ app3_undelegate_gateway3: ## Undelegate trust to gateway3

.PHONY: supplier_list
supplier_list: ## List all the staked supplier
pocketd --home=$(POCKETD_HOME) q supplier list-supplier --node $(POCKET_NODE)
poktrolld --home=$(POCKETD_HOME) q supplier list-supplier --node $(POCKET_NODE)

# TODO(@Olshansk, @okdas): Add more services (in addition to anvil) for apps and suppliers to stake for.
# TODO_TECHDEBT: svc1, svc2 and svc3 below are only in place to make GetSession testable
.PHONY: supplier_stake
supplier_stake: ## Stake tokens for the supplier specified (must specify the APP env var)
pocketd --home=$(POCKETD_HOME) tx supplier stake-supplier 1000upokt "$(SERVICES)" --keyring-backend test --from $(SUPPLIER) --node $(POCKET_NODE)
poktrolld --home=$(POCKETD_HOME) tx supplier stake-supplier 1000upokt "$(SERVICES)" --keyring-backend test --from $(SUPPLIER) --node $(POCKET_NODE)

.PHONY: supplier1_stake
supplier1_stake: ## Stake supplier1
Expand All @@ -365,7 +365,7 @@ supplier3_stake: ## Stake supplier3

.PHONY: supplier_unstake
supplier_unstake: ## Unstake an supplier (must specify the SUPPLIER env var)
pocketd --home=$(POCKETD_HOME) tx supplier unstake-supplier --keyring-backend test --from $(SUPPLIER) --node $(POCKET_NODE)
poktrolld --home=$(POCKETD_HOME) tx supplier unstake-supplier --keyring-backend test --from $(SUPPLIER) --node $(POCKET_NODE)

.PHONY: supplier1_unstake
supplier1_unstake: ## Unstake supplier1
Expand All @@ -386,10 +386,10 @@ supplier3_unstake: ## Unstake supplier3
.PHONY: acc_balance_query
acc_balance_query: ## Query the balance of the account specified (make acc_balance_query ACC=pokt...)
@echo "~~~ Balances ~~~"
pocketd --home=$(POCKETD_HOME) q bank balances $(ACC) --node $(POCKET_NODE)
poktrolld --home=$(POCKETD_HOME) q bank balances $(ACC) --node $(POCKET_NODE)
@echo "~~~ Spendable Balances ~~~"
@echo "Querying spendable balance for $(ACC)"
pocketd --home=$(POCKETD_HOME) q bank spendable-balances $(ACC) --node $(POCKET_NODE)
poktrolld --home=$(POCKETD_HOME) q bank spendable-balances $(ACC) --node $(POCKET_NODE)

.PHONY: acc_balance_query_module_app
acc_balance_query_module_app: ## Query the balance of the network level "application" module
Expand All @@ -405,7 +405,7 @@ acc_balance_query_app1: ## Query the balance of app1

.PHONY: acc_balance_total_supply
acc_balance_total_supply: ## Query the total supply of the network
pocketd --home=$(POCKETD_HOME) q bank total --node $(POCKET_NODE)
poktrolld --home=$(POCKETD_HOME) q bank total --node $(POCKET_NODE)

######################
### Ignite Helpers ###
Expand All @@ -415,6 +415,15 @@ acc_balance_total_supply: ## Query the total supply of the network
ignite_acc_list: ## List all the accounts in LocalNet
ignite account list --keyring-dir=$(POCKETD_HOME) --keyring-backend test --address-prefix $(POCKET_ADDR_PREFIX)

##################
### CI Helpers ###
##################

.PHONY: trigger_ci
trigger_ci: ## Trigger the CI pipeline by submitting an empty commit; See https://github.com/pokt-network/pocket/issues/900 for details
git commit --allow-empty -m "Empty commit"
git push

#####################
### Documentation ###
#####################
Expand Down
6 changes: 3 additions & 3 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ docker_build_with_restart(
dockerfile_contents="""FROM golang:1.20.8
RUN apt-get -q update && apt-get install -qyy curl jq
RUN go install github.com/go-delve/delve/cmd/dlv@latest
COPY bin/pocketd /usr/local/bin/pocketd
COPY bin/poktrolld /usr/local/bin/pocketd
WORKDIR /
""",
only=["./bin/pocketd"],
only=["./bin/poktrolld"],
entrypoint=["/bin/sh", "/scripts/pocket.sh"],
live_update=[sync("bin/pocketd", "/usr/local/bin/pocketd")],
live_update=[sync("bin/poktrolld", "/usr/local/bin/pocketd")],
)

# Run celestia and anvil nodes
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (p *pocketdBin) RunCommandOnHost(rpcUrl string, args ...string) (*commandRe
func (p *pocketdBin) runCmd(args ...string) (*commandResult, error) {
base := []string{"--home", defaultHome}
args = append(base, args...)
cmd := exec.Command("pocketd", args...)
cmd := exec.Command("poktrolld", args...)
r := &commandResult{}
out, err := cmd.Output()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/application/client/cli/tx_delegate_to_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ that delegates authority to the gateway specified to sign relays requests for th
act on the behalf of the application during a session.
Example:
$ pocketd --home=$(POCKETD_HOME) tx application delegate-to-gateway $(GATEWAY_ADDR) --keyring-backend test --from $(APP) --node $(POCKET_NODE)`,
$ poktrolld --home=$(POCKETD_HOME) tx application delegate-to-gateway $(GATEWAY_ADDR) --keyring-backend test --from $(APP) --node $(POCKET_NODE)`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
gatewayAddress := args[0]
Expand Down
2 changes: 1 addition & 1 deletion x/application/client/cli/tx_stake_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func CmdStakeApplication() *cobra.Command {
will stake the tokens and serviceIds and associate them with the application specified by the 'from' address.
Example:
$ pocketd --home=$(POCKETD_HOME) tx application stake-application 1000upokt svc1,svc2,svc3 --keyring-backend test --from $(APP) --node $(POCKET_NODE)`,
$ poktrolld --home=$(POCKETD_HOME) tx application stake-application 1000upokt svc1,svc2,svc3 --keyring-backend test --from $(APP) --node $(POCKET_NODE)`,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
stakeString := args[0]
Expand Down
2 changes: 1 addition & 1 deletion x/application/client/cli/tx_undelegate_from_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ that removes the authority from the gateway specified to sign relays requests fo
act on the behalf of the application during a session.
Example:
$ pocketd --home=$(POCKETD_HOME) tx application undelegate-from-gateway $(GATEWAY_ADDR) --keyring-backend test --from $(APP) --node $(POCKET_NODE)`,
$ poktrolld --home=$(POCKETD_HOME) tx application undelegate-from-gateway $(GATEWAY_ADDR) --keyring-backend test --from $(APP) --node $(POCKET_NODE)`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
gatewayAddress := args[0]
Expand Down
2 changes: 1 addition & 1 deletion x/application/client/cli/tx_unstake_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func CmdUnstakeApplication() *cobra.Command {
the application specified by the 'from' address.
Example:
$ pocketd --home=$(POCKETD_HOME) tx application unstake-application --keyring-backend test --from $(APP) --node $(POCKET_NODE)`,
$ poktrolld --home=$(POCKETD_HOME) tx application unstake-application --keyring-backend test --from $(APP) --node $(POCKET_NODE)`,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) (err error) {

Expand Down
2 changes: 1 addition & 1 deletion x/gateway/client/cli/tx_stake_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func CmdStakeGateway() *cobra.Command {
Long: `Stake a gateway with the provided parameters. This is a broadcast operation that
will stake the tokens and associate them with the gateway specified by the 'from' address.
Example:
$ pocketd --home=$(POCKETD_HOME) tx gateway stake-gateway 1000upokt --keyring-backend test --from $(GATEWAY) --node $(POCKET_NODE)`,
$ poktrolld --home=$(POCKETD_HOME) tx gateway stake-gateway 1000upokt --keyring-backend test --from $(GATEWAY) --node $(POCKET_NODE)`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientTxContext(cmd)
Expand Down
2 changes: 1 addition & 1 deletion x/gateway/client/cli/tx_unstake_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func CmdUnstakeGateway() *cobra.Command {
Long: `Unstake a gateway. This is a broadcast operation that will unstake the gateway specified by the 'from' address.
Example:
$ pocketd --home=$(POCKETD_HOME) tx gateway unstake-gateway --keyring-backend test --from $(GATEWAY) --node $(POCKET_NODE)`,
$ poktrolld --home=$(POCKETD_HOME) tx gateway unstake-gateway --keyring-backend test --from $(GATEWAY) --node $(POCKET_NODE)`,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, _ []string) (err error) {
clientCtx, err := client.GetClientTxContext(cmd)
Expand Down
2 changes: 1 addition & 1 deletion x/supplier/client/cli/tx_stake_supplier.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ of comma separated values of the form 'service;url' where 'service' is the servi
For example, an application that stakes for 'anvil' could be matched with a supplier staking for 'anvil;http://anvil:8547'.
Example:
$ pocketd --home=$(POCKETD_HOME) tx supplier stake-supplier 1000upokt anvil;http://anvil:8547 --keyring-backend test --from $(APP) --node $(POCKET_NODE)`,
$ poktrolld --home=$(POCKETD_HOME) tx supplier stake-supplier 1000upokt anvil;http://anvil:8547 --keyring-backend test --from $(APP) --node $(POCKET_NODE)`,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
stakeString := args[0]
Expand Down
2 changes: 1 addition & 1 deletion x/supplier/client/cli/tx_unstake_supplier.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func CmdUnstakeSupplier() *cobra.Command {
Long: `Unstake an supplier with the provided parameters. This is a broadcast operation that will unstake the supplier specified by the 'from' address.
Example:
$ pocketd --home=$(POCKETD_HOME) tx supplier unstake-supplier --keyring-backend test --from $(SUPPLIER) --node $(POCKET_NODE)`,
$ poktrolld --home=$(POCKETD_HOME) tx supplier unstake-supplier --keyring-backend test --from $(SUPPLIER) --node $(POCKET_NODE)`,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) (err error) {

Expand Down

0 comments on commit 21edfe7

Please sign in to comment.