Skip to content

Commit

Permalink
feat: Publish to Dockerhub on every merge to develop and release (#1158)
Browse files Browse the repository at this point in the history
  • Loading branch information
yohanelly95 authored Oct 23, 2023
1 parent 211182d commit 768f265
Show file tree
Hide file tree
Showing 12 changed files with 246 additions and 41 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
&& go install github.com/ory/go-acc@v0.2.7 \
&& go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.2
- name: Run make setup
- name: Run make setup for mainnet
run: make setup
- name: Run gofmt
run: |
Expand Down Expand Up @@ -238,8 +238,9 @@ jobs:
run: echo "::set-output name=tag_name::${GITHUB_REF#refs/tags/}"

- name: Build and push Docker image
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
file: ./Dockerfile.mainnet
context: .
platforms: linux/amd64,linux/arm64/v8
push: true
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ jobs:
go install github.com/ory/go-acc@v0.2.7
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.2
- name: Run make setup
run: make setup
- name: Run make setup for testnet
run: make setup-testnet
- name: Run gofmt
run: |
gofmt
Expand Down Expand Up @@ -87,8 +87,9 @@ jobs:
id: sha
run: echo "::set-output name=short::$(git rev-parse --short HEAD)"
- name: Build and push Docker image
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
file: ./Dockerfile.testnet
context: .
platforms: linux/amd64,linux/arm64/v8
push: true
Expand Down
96 changes: 96 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: CI/CD Release Pipeline
on:
push:
branches:
- "release/*"

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: true
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "18"
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.21
- name: Cache npm modules
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Cache Go dependencies
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install Dependencies
run: |
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install -y npm ethereum
npm install
go get -d github.com/ethereum/go-ethereum@v1.12.2
go install github.com/ethereum/go-ethereum/cmd/abigen@v1.12.2
go install github.com/mattn/goveralls@v0.0.11
go install github.com/ory/go-acc@v0.2.7
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.2
- name: Run make setup for mainnet
run: make setup
- name: Run gofmt
run: |
gofmt
- name: Run golangci-lint
run: |
golangci-lint run -v --timeout 5m
- name: Execute test case
run: |
go-acc ./... --ignore razor/accounts/mocks --ignore razor/cmd/mocks --ignore razor/utils/mocks --ignore pkg --ignore razor/path/mocks --output coverage.txt
- name: Run benchmarks
run: |
go test ./... -bench=. -run=^#
- name: Publish Coverage to Coveralls.io
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: goveralls -coverprofile=coverage.txt -service=github
- uses: bissolli/gh-action-persist-workspace@v1
with:
action: persist

push-docker-build:
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get short SHA
id: sha
run: echo "::set-output name=short::$(git rev-parse --short HEAD)"
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
file: ./Dockerfile.mainnet
context: .
platforms: linux/amd64,linux/arm64/v8
push: true
tags: razornetwork/razor-go:${{ steps.sha.outputs.short }}
File renamed without changes.
27 changes: 27 additions & 0 deletions Dockerfile.testnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM golang:1.21.1-alpine AS go
FROM ethereum/client-go:alltools-v1.12.2 AS ethereum

FROM node:18.18.0-alpine AS builder

COPY --from=ethereum /usr/local/bin/abigen /usr/local/bin/
COPY --from=go /usr/local/go/ /usr/local/go/

## Attaching current dir to workdir
WORKDIR /app
COPY . /app

## Install and Cleanup

RUN PATH="/usr/local/go/bin:${PATH}" \
&& apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python \
&& apk add --update make gcc musl musl-dev g++ libc-dev bash linux-headers \
&& apk add --no-cache jq \
&& npm install \
&& npm run build-noargs-testnet \
&& cp build/bin/razor /usr/local/bin/


FROM alpine:latest
RUN apk add --update bash
COPY --from=builder /usr/local/bin/razor /usr/local/bin/
ENTRYPOINT [ "razor" ]
35 changes: 30 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,43 @@ SHELL = /bin/bash
BIN_DIR = ./build/bin
RAZOR = ${BIN_DIR}/razor

all: fetch_bindings install_razor set_config
all: update_chainId fetch_bindings install_razor set_config
build: install_razor set_config
build-noargs: fetch_bindings install_razor
setup: fetch_bindings
build-noargs: update_chainId fetch_bindings install_razor
setup: update_chainId fetch_bindings

all-testnet: update_chainId_testnet fetch_bindings_testnet install_razor set_config
build-noargs-testnet: update_chainId_testnet fetch_bindings_testnet install_razor
setup-testnet: update_chainId_testnet fetch_bindings_testnet

fetch_bindings:
@echo "Installing contract dependencies..."
@echo ""
@${SHELL} generate-bindings.sh
@${SHELL} generate-bindings.sh mainnet
@echo "Contract bindings generated...."
@echo ""

fetch_bindings_testnet:
@echo "Installing contract dependencies..."
@echo ""
@${SHELL} generate-bindings.sh testnet
@echo "Contract bindings generated...."
@echo ""

update_chainId:
@echo "Update chainId..."
@echo ""
@${SHELL} update-chainId.sh mainnet
@echo "ChainId updated to mainnet...."
@echo ""

update_chainId_testnet:
@echo "Update chainId..."
@echo ""
@${SHELL} update-chainId.sh testnet
@echo "ChainId updated to testnet...."
@echo ""

install_razor:
@echo "Installing razor node...."
${GO} build -ldflags "-s -w" -o ./build/bin/razor main.go
Expand All @@ -25,4 +50,4 @@ set_config:
@echo "Setup initial config"
@${SHELL} config.sh
@echo ""
@echo "Razor node is set up and ready to use"
@echo "Razor node is set up and ready to use"
12 changes: 12 additions & 0 deletions addresses/mainnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Governance": "0xAc40E8dA38B5a381008059a38bb9bf45f0D3C4e2",
"BlockManager": "0x11aB70d78f1Dd2c3F967180d8A64858Db03A0aBa",
"CollectionManager": "0x367962d1462C568A0dDd0e2448311469451bF5a3",
"StakeManager": "0xe0bC695203d9C9f379bcdE9260B9F71B64B85298",
"RewardManager": "0x301779E4c95f951D2E17B4c3EdDC717551df2EBb",
"VoteManager": "0x641BAD0641eB5B94B19568C0a22a55AEbDAF1870",
"Delegator": "0xC74745eA5a3fac1864FAcd8f48d72C21A4ab883D",
"RAZOR": "0xcbf70914Fae03B3acB91E953De60CfDAaCA8145f",
"StakedTokenFactory": "0xEffA78888Dc1b6033286E5dF9b170bc5223178AB",
"RandomNoManager": "0xC6eF45F5Add040800D30FE6dEe01b4EBC4BfC467"
}
12 changes: 12 additions & 0 deletions addresses/testnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Governance": "0xD2A74B7A962FFc85827da0124A4278e731D15464",
"BlockManager": "0x096e44B0d8b68376C8Efe40F28C3857951f03069",
"CollectionManager": "0x3b76eB8c0282dAf531D7C507E4f3143A9A9c38b1",
"StakeManager": "0x9f55a2C6C1F1Be8B01562cEae2df2F22931C7a46",
"RewardManager": "0x07875369943951b1Af9c37f4ea137dcED9d9181d",
"VoteManager": "0x11995b74D6d07a6Edc05653a71F3e8B3354caBF0",
"Delegator": "0xe295863DF95AaAeC66E7de11D3aD0C35698d0fE9",
"RAZOR": "0x4500E10fEb89e46E9fb642D0c62b1a761278155D",
"StakedTokenFactory": "0xe20e11687F269fE9e356da92C4B15aBF98BbC9ff",
"RandomNoManager": "0x31463bC4D5E67Bca623fFc6152D253Ea17216fA9"
}
4 changes: 3 additions & 1 deletion generate-bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -e -o pipefail

mkdir -p ./pkg/bindings

network=$1

generate_binding() {
contract=$(echo $1 | awk '{print $1}')
go_source=$(echo $1 | awk '{print $2}')
Expand Down Expand Up @@ -34,4 +36,4 @@ do
generate_binding "$c"
done

bash generate-contracts.sh
bash generate-contracts.sh $network
22 changes: 16 additions & 6 deletions generate-contracts.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
#!/bin/bash

echo "Copying addresses.json to core/contracts.go"
touch core/contracts.go

echo "package core" > core/contracts.go
printf "\n" >> core/contracts.go

network=$1
addresses_path=""

if [[ "$network" == "mainnet" ]]; then
addresses_path="addresses/mainnet.json"
elif [[ "$network" == "testnet" ]]; then
addresses_path="addresses/testnet.json"
else
echo "Invalid network environment specified. Please use 'mainnet' or 'testnet'."
exit 1
fi

echo "Copying $addresses_path to core/contracts.go"

generate_contract_address() {
jsonFileKey=$(echo $1 | awk '{print $1}')
jsonFileKey="."$jsonFileKey
goContractKey=$(echo $1 | awk '{print $2}')
varDeclaration="var $goContractKey ="
contractAddress=$(cat addresses.json | jq $jsonFileKey)
contractAddress=$(cat $addresses_path | jq $jsonFileKey)
echo "$varDeclaration $contractAddress" >> core/contracts.go
}

Expand All @@ -26,6 +38,4 @@ contract_addresses_list=(
for c in "${contract_addresses_list[@]}"
do
generate_contract_address "$c"
done


done
50 changes: 26 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
{
"name": "razor-go",
"version": "v1.0.0",
"description": "Official node for running stakers in Golang.",
"main": "index.js",
"scripts": {
"setup": "make setup",
"build": "make build",
"build-all": "make all",
"build-noargs": "make build-noargs",
"test": "go test ./... -v"
},
"repository": {
"type": "git",
"url": "https://github.com/razor-network/razor-go"
},
"author": "Razor Network",
"license": "ISC",
"bugs": {
"url": "https://github.com/razor-network/razor-go/issues"
},
"homepage": "https://github.com/razor-network/razor-go#readme",
"dependencies": {
"@razor-network/contracts": "v1.0.2"
"name": "razor-go",
"version": "v1.1.0",
"description": "Official node for running stakers in Golang.",
"main": "index.js",
"scripts": {
"setup": "make setup",
"build": "make build",
"build-all": "make all",
"build-noargs": "make build-noargs",
"build-noargs-testnet": "make build-noargs-testnet",
"test": "go test ./... -v"
},
"repository": {
"type": "git",
"url": "https://github.com/razor-network/razor-go"
},
"author": "Razor Network",
"license": "ISC",
"bugs": {
"url": "https://github.com/razor-network/razor-go/issues"
},
"homepage": "https://github.com/razor-network/razor-go#readme",
"dependencies": {
"@razor-network/contracts": "v1.0.2"
}
}
}
17 changes: 17 additions & 0 deletions update-chainId.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# Define the ChainId value based on the network argument
NETWORK=$1
CHAINID=""

if [[ "$NETWORK" == "mainnet" ]]; then
CHAINID="0x109B4597"
elif [[ "$NETWORK" == "testnet" ]]; then
CHAINID="0x5A79C44E"
else
echo "Invalid network specified. Please choose 'mainnet' or 'testnet'."
exit 1
fi

sed -i "s/var ChainId = big.NewInt(0x[a-fA-F0-9]*)/var ChainId = big.NewInt($CHAINID)/" core/constants.go

0 comments on commit 768f265

Please sign in to comment.