Skip to content

Commit

Permalink
refactoring; support new non-merklized issuer contract
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-korotya committed Mar 1, 2024
1 parent 108080a commit 98d14d7
Show file tree
Hide file tree
Showing 105 changed files with 3,709 additions and 5,630 deletions.
17 changes: 17 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.git
.github

.dockerignore
.gitignore
docker-compose.yaml

build
tests


.golangci.yml
README.md
first-run.sh

// Ignore client for backend build
client
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SUPPORTED_STATE_CONTRACTS="137=0xdc2A724E6bd60144Cde9DEC0A38a26C619d84B90,80001=0x134B1BE34911E39A8397ec6289782989729807a4"
SUPPORTED_RPC="137=<RPC_POLYGON_MAINNET>,80001=<RPC_POLYGON_MUMBAI>"

ISSUERS="<ISSUER_DID>"

MONGODB_CONNECTION_STRING="mongodb://mongodb:27017/credentials"

EXTERNAL_HOST="<NGROK_URL>"
24 changes: 24 additions & 0 deletions .github/workflows/ci-linter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Lint
on:
push:
branches:
- master
- develop
pull_request:
workflow_dispatch:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.21.x
- name: Checkout code
uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.55.2
args: --timeout=5m
46 changes: 46 additions & 0 deletions .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: e2e hardhat tests

on:
push:
branches:
- master
- develop
pull_request:
workflow_dispatch:

jobs:
run_e2e:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

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

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

- name: Build docker container
uses: docker/build-push-action@v5
with:
context: .
file: build/Dockerfile
load: true
tags: onchain-non-merklized-issuer-demo:latest
cache-from: type=gha
cache-to: type=gha

- name: Run container
run: |
docker run -d -p 8080:8080 \
--name onchain-non-merklized-issuer-demo onchain-non-merklized-issuer-demo:latest
- name: Run Newman
run: |
newman run tests/e2e/e2e.postman_collection.json
42 changes: 42 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Publish
on:
workflow_dispatch:

jobs:
publish_onchain-non-merklized-issuer-demo:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

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

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

- name: Determine tag
id: tag
run: |
ref=$(echo ${{ github.ref }} | cut -d'/' -f3)
echo "Original ref: $ref"
if [[ "$ref" == "master" ]]; then
echo "::set-output name=tag::latest"
elif [[ "$ref" == "develop" ]]; then
echo "::set-output name=tag::develop"
else
echo "::set-output name=tag::$ref"
fi
- name: Build and Deploy to ghcr.io
run: |
tag=${{ steps.tag.outputs.tag }}
echo "Using tag: $tag"
docker buildx build -f build/Dockerfile --push \
--platform linux/amd64,linux/arm64 \
-t ghcr.io/${{ github.repository }}:${tag} .
16 changes: 16 additions & 0 deletions .github/workflows/sync-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
on:
schedule:
- cron: "0 0 1 * *"
workflow_dispatch:
jobs:
repo-sync:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: actions-template-sync
uses: AndreasAugustin/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
source_repo_path: iden3/go-service-template
39 changes: 39 additions & 0 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Go unit tests

on:
push:
branches:
- master
- develop
pull_request:
workflow_dispatch:

jobs:
test:
name: Run unit tests
runs-on: ubuntu-latest
strategy:
matrix:
go-version:
- 1.21.x

steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
id: go

- name: Check out code
uses: actions/checkout@v4

- name: Cache Go Modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-
- name: Run tests
run: go test -v ./...
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
# Bin files
onchain-non-merklized-issuer-demo

# IDE
.vscode

# Docker volumes
data

# Env files
.env
.env.*

!*.env.example
68 changes: 68 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
service:
golangci-lint-version: 1.x.x

run:
tests: false

timeout: 2m
skip-dirs:
- vendor

linters-settings:
govet:
check-shadowing: false
goconst:
min-len: 2
min-occurrences: 2
misspell:
locale: US
lll:
line-length: 140
gocritic:
enabled-tags:
- diagnostic
- style
- performance

linters:
enable:
- bodyclose
- megacheck
- revive
- govet
- unconvert
- megacheck
- structcheck
- gas
- gocyclo
- dupl
- misspell
- unparam
- varcheck
- deadcode
- typecheck
- ineffassign
- varcheck
- stylecheck
- gochecknoinits
- exportloopref
- gocritic
- nakedret
- gosimple
- prealloc
- gci
- errcheck
- gofmt
- goimports
- unused
fast: false
disable-all: true

issues:
exclude-rules:
- text: "exported: type name will be used as"
linters:
- revive
- text: "unexported-return:"
linters:
- revive
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Build the application
FROM --platform=$BUILDPLATFORM golang:1.21.3-bookworm as base
ARG build_tags=""

WORKDIR /build

COPY . .
RUN go mod download

ARG TARGETPLATFORM
ARG TARGETARCH
ARG TARGETOS
RUN echo "TARGETARCH: $TARGETARCH"; \
echo "TARGETOS: $TARGETOS"; \
echo "TARGETPLATFORM: $TARGETPLATFORM";
RUN GOARCH=$TARGETARCH GOOS=$TARGETOS go build -tags="${build_tags}" -o ./onchain-non-merklized-issuer-demo main.go

# Run the application
FROM alpine:3.18.4

RUN apk add --no-cache libstdc++ gcompat libgomp; \
apk add --update busybox>1.3.1-r0; \
apk add --update openssl>3.1.4-r1

RUN apk add doas; \
adduser -S dommyuser -D -G wheel; \
echo 'permit nopass :wheel as root' >> /etc/doas.d/doas.conf;
RUN chmod g+rx,o+rx /

WORKDIR /app

COPY ./keys /app/keys
COPY --from=base /build/onchain-non-merklized-issuer-demo /app/onchain-non-merklized-issuer-demo

# Command to run
ENTRYPOINT ["/app/onchain-non-merklized-issuer-demo"]
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.PHONY: run
run: build
./onchain-non-merklized-issuer-demo

.PHONY: build
build:
go build -o onchain-non-merklized-issuer-demo .

.PHONY: test
test:
go test -v ./...

.PHONY: lint
lint:
golangci-lint run
Loading

0 comments on commit 98d14d7

Please sign in to comment.