Skip to content

Commit

Permalink
feat: init
Browse files Browse the repository at this point in the history
feat: add workspace

fix: remove ignore file

feat: implement `SignTxAsFeePayer`

fix: go mod tidy

test: add test codes.

feat: add missing implementations

fix: update package name, fix queries

test: updates during test code implementation

test: add test codes.

feat: add missing implementations

fix: update package name, fix queries

feat: add missing implementations

fix: update package name, fix queries

test: update test codes, fix minor errors

test: update test codes, fix minor errors

test: update for test

fix: remove logs

test: add contract reading codes

test: wip

feat: add missing implementations

fix: update package name, fix queries

test: update test codes, fix minor errors

test: update test codes, fix minor errors

test: update for test

fix: remove logs

test: add contract reading codes

test: wip

refactor: update names and cleanup

test: wip

feat: add dockerfile and github workflow

feat: update github action files
  • Loading branch information
nick-bisonai committed Feb 15, 2024
1 parent 1c4d022 commit 091939e
Show file tree
Hide file tree
Showing 39 changed files with 4,647 additions and 55 deletions.
95 changes: 95 additions & 0 deletions .github/workflows/godelegator.image+upload.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Go Delegator Deploy to Amazon ECR

on:
push:
branches:
- master
paths:
- "go-delegator/**"
env:
ecr_url: public.ecr.aws/bisonai/orakl-godelegator

jobs:
prepare:
name: Prepare Build
runs-on: ubuntu-latest

outputs:
tag_date: ${{ steps.tag.outputs.date }}
tag_git_hash: ${{ steps.tag.outputs.git_hash }}
version: ${{ steps.package.outputs.version }}

steps:
- uses: actions/checkout@v3

- name: Get time TAG
id: tag
run: |
echo "date=$(date +'%Y%m%d.%H%M')" >> $GITHUB_OUTPUT
echo "git_hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Get package version
id: package
run: |
version=$(cat "./go-delegator/.version")
echo "version=${version}" >> $GITHUB_OUTPUT
build:
name: Build
runs-on: ubuntu-latest
needs: prepare

permissions:
id-token: write
contents: read

outputs:
tag_date: ${{ steps.tag.outputs.date }}
tag_git_hash: ${{ steps.tag.outputs.git_hash }}

steps:
- uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: "1.21.5"
check-latest: true
cache-dependency-path: |
./go-delegator/go.sum
- name: Run lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
working-directory: go-delegator
skip-pkg-cache: true
skip-build-cache: true
args: --timeout=10m

- name: Run vet
run: |
cd ./go-delegator
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest
go vet
go vet -vettool=$(which shadow)
- name: Docker build orakl-godelegator
run: SERVICE_NAME=orakl-godelegator docker-compose -f docker-compose.build.yaml build

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-region: us-east-1
role-to-assume: ${{ secrets.ROLE_ARN }}

- name: Login to Amazon ECR
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v1
with:
registry-type: public

- name: Publish Image to ECR(delegator)
run: |
docker tag orakl-godelegator ${{ env.ecr_url }}:v${{ needs.prepare.outputs.version }}.${{ needs.prepare.outputs.tag_date }}.${{ needs.prepare.outputs.tag_git_hash }}
docker push ${{ env.ecr_url }}:v${{ needs.prepare.outputs.version }}.${{ needs.prepare.outputs.tag_date }}.${{ needs.prepare.outputs.tag_git_hash }}
68 changes: 68 additions & 0 deletions .github/workflows/godelegator.test+build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: "godelegator: test+build"

on:
push:
branches-ignore:
- "master"
paths:
- "go-delegator/**"

jobs:
core-build:
runs-on: ubuntu-latest
timeout-minutes: 3
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: orakl-test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: "1.21.5"
check-latest: true
cache-dependency-path: |
./go-delegator/go.sum
- name: Install golang-migrate
run: |
curl -L https://github.com/golang-migrate/migrate/releases/download/v4.17.0/migrate.linux-amd64.tar.gz | tar xvz
sudo mv ./migrate /usr/bin
- name: Migrate up
run: |
cd ./go-delegator
migrate -database "postgresql://postgres:postgres@localhost:5432/orakl-test?search_path=public&sslmode=disable" -verbose -path ./migrations up
- name: Install dependencies
run: |
cd ./go-delegator
go mod tidy
- name: Build
run: |
cd ./go-delegator
go build
- name: Insert test fee payer pk
run: |
psql -h postgres -U postgres -d orakl-test <<EOF
SET search_path TO delegator;
INSERT INTO fee_payers ("privateKey") VALUES ('${{ secrets.DELEGATOR_FEEPAYER_PK}}')
ON CONFLICT ("privateKey")
DO NOTHING
RETURNING *;
EOF
- name: Run test
run: |
cd ./go-delegator
go test ./tests -v
env:
DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/orakl-test?search_path=public"
PROVIDER_URL: "https://api.baobab.klaytn.net:8651"
TEST_DELEGATOR_REPORTER_PK: ${{ secrets.TEST_DELEGATOR_REPORTER_PK}}
34 changes: 34 additions & 0 deletions dockerfiles/orakl-godelegator.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM golang:1.21.5-bullseye as builder

RUN apt-get update && apt-get install -y curl

WORKDIR /app

COPY go-delegator go-delegator

WORKDIR /app/go-delegator

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o delegatorbin -ldflags="-w -s" .

# debian:bullseye-slim
FROM debian@sha256:4b48997afc712259da850373fdbc60315316ee72213a4e77fc5a66032d790b2a

RUN apt-get update && apt-get install -y curl

RUN curl -L https://github.com/golang-migrate/migrate/releases/download/v4.17.0/migrate.linux-amd64.tar.gz | tar xvz && \
mv ./migrate /usr/bin

WORKDIR /app

RUN mkdir /app/migrations

COPY --from=builder /app/go-delegator/migrations /app/migrations

COPY --from=builder /app/go-delegator/delegatorbin /usr/bin

CMD sh -c '_DATABASE_URL=$DATABASE_URL; if echo $_DATABASE_URL | grep -q "\?"; then \
_DATABASE_URL="${_DATABASE_URL}&sslmode=disable"; \
else \
_DATABASE_URL="${_DATABASE_URL}?sslmode=disable"; \
fi && \
migrate -database "$_DATABASE_URL" -verbose -path ./migrations up && delegatorbin'
5 changes: 5 additions & 0 deletions go-delegator/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DATABASE_URL=
PROVIDER_URL=
APP_PORT=
TEST_DELEGATOR_REPORTER_PK=
USE_GOOGLE_SECRET_MANAGER=
46 changes: 46 additions & 0 deletions go-delegator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so

# Folders
_obj
_test

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.exe
*.exe~
*.test
*.prof

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# IDE files
.idea/

# Log files
*.log

# Binaries
bin/*

*.dll
*.so
*.dylib

.env
1 change: 1 addition & 0 deletions go-delegator/.version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1
11 changes: 11 additions & 0 deletions go-delegator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Go Delegator

- Go implementation for delegator

## TODOs

[ ] test codes
[ ] github actions
[ ] dockerfile
[ ] local-data-feed integration
[ ] comparison & double check with nodejs delegator
Loading

0 comments on commit 091939e

Please sign in to comment.