Scaffolding

This commit is contained in:
altafan
2023-10-30 14:43:51 +01:00
commit bd6199a787
32 changed files with 567 additions and 0 deletions

7
.dockerignore Executable file
View File

@@ -0,0 +1,7 @@
*.md
build
dist
.git
.github
Dockerfile

19
.github/workflows/ci.intergation.yaml vendored Executable file
View File

@@ -0,0 +1,19 @@
name: ci_integration
on:
push:
branches: [master]
jobs:
test:
name: integration tests
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: ">1.17.2"
- uses: actions/checkout@v3
- run: go get -v -t -d ./...
- name: integration testing
run: make integrationtest

32
.github/workflows/ci.unit.yaml vendored Executable file
View File

@@ -0,0 +1,32 @@
name: ci_unit
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
test:
name: unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: ">1.17.2"
- uses: actions/checkout@v3
- name: check linting
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
- name: check code integrity
uses: securego/gosec@master
with:
args: '-severity high -quiet ./...'
- uses: bufbuild/buf-setup-action@v1.3.1
- name: check proto linting
run: make proto-lint
- run: go get -v -t -d ./...
- name: unit testing
run: make test

47
.github/workflows/release.yaml vendored Executable file
View File

@@ -0,0 +1,47 @@
name: release
on:
workflow_dispatch:
push:
tags:
- "*"
jobs:
goreleaser:
runs-on: ubuntu-20.04
env:
DOCKER_CLI_EXPERIMENTAL: "enabled"
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v3
with:
go-version: ">1.17.2"
- uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: release artifacts
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist --debug
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
- uses: bufbuild/buf-setup-action@v1.3.1
- name: release protos
uses: bufbuild/buf-push-action@v1
with:
input: api-spec/protobuf
buf_token: ${{ secrets.BUF_TOKEN }}

21
.gitignore vendored Executable file
View File

@@ -0,0 +1,21 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with 'go test -c'
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
/build/
/dist/
DS_Store
._.DS_Store
**/.DS_Store
**/._.DS_Store

99
.goreleaser.yaml Executable file
View File

@@ -0,0 +1,99 @@
builds:
- id: "arkd"
main: ./cmd/arkd
ldflags:
- -s -X 'main.version={{.Version}}' -X 'main.commit={{.Commit}}' -X 'main.date={{.Date}}'
goos:
- linux
- darwin
goarch:
- amd64
- arm64
binary: arkd
## flag the semver v**.**.**-<tag>.* as pre-release on Github
release:
prerelease: auto
checksum:
name_template: "checksums.txt"
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
use: github-native
archives:
- id: arkd
format: binary
builds:
- arkd
name_template: "arkd-v{{ .Version }}-{{ .Os }}-{{ .Arch }}"
dockers:
###########################
# tag latest & prerelease #
###########################
#amd64
- image_templates:
- "ghcr.io/ark-network/arkd:{{ .Tag }}-amd64"
# push always either release or prerelease with a docker tag with the semver only
skip_push: "false"
use: buildx
ids:
- arkd
dockerfile: goreleaser.Dockerfile
# GOOS of the built binaries/packages that should be used.
goos: linux
# GOARCH of the built binaries/packages that should be used.
goarch: amd64
# Template of the docker build flags.
build_flag_templates:
- "--platform=linux/amd64"
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title=arkd"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--build-arg=VERSION={{.Version}}"
- "--build-arg=COMMIT={{.Commit}}"
- "--build-arg=DATE={{.Date}}"
- image_templates:
- "ghcr.io/ark-network/arkd:{{ .Tag }}-arm64v8"
# push always either release or prerelease with a docker tag with the semver only
skip_push: "false"
use: buildx
ids:
- arkd
dockerfile: goreleaser.Dockerfile
# GOOS of the built binaries/packages that should be used.
goos: linux
# GOARCH of the built binaries/packages that should be used.
goarch: arm64
# Template of the docker build flags.
build_flag_templates:
- "--platform=linux/arm64/v8"
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title=arkd"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--build-arg=VERSION={{.Version}}"
- "--build-arg=COMMIT={{.Commit}}"
- "--build-arg=DATE={{.Date}}"
docker_manifests:
- name_template: ghcr.io/ark-network/arkd:{{ .Tag }}
image_templates:
- ghcr.io/ark-network/arkd:{{ .Tag }}-amd64
- ghcr.io/ark-network/arkd:{{ .Tag }}-arm64v8
skip_push: "false"
- name_template: ghcr.io/ark-network/arkd:latest
image_templates:
- ghcr.io/ark-network/arkd:{{ .Tag }}-amd64
- ghcr.io/ark-network/arkd:{{ .Tag }}-arm64v8
skip_push: auto

41
Dockerfile Executable file
View File

@@ -0,0 +1,41 @@
# first image used to build the sources
FROM golang:1.21 AS builder
ARG VERSION
ARG COMMIT
ARG DATE
ARG TARGETOS
ARG TARGETARCH
WORKDIR /app
COPY . .
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-X 'main.Version=${COMMIT}' -X 'main.Commit=${COMMIT}' -X 'main.Date=${COMMIT}'" -o bin/arkd cmd/arkd/main.go
# Second image, running the arkd executable
FROM debian:buster-slim
# $USER name, and data $DIR to be used in the 'final' image
ARG USER=ark
ARG DIR=/home/ark
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates
COPY --from=builder /app/bin/* /usr/local/bin/
# NOTE: Default GID == UID == 1000
RUN adduser --disabled-password \
--home "$DIR/" \
--gecos "" \
"$USER"
USER $USER
# Prevents 'VOLUME $DIR/.arkd/' being created as owned by 'root'
RUN mkdir -p "$DIR/.arkd/"
# Expose volume containing all 'arkd' data
VOLUME $DIR/.arkd/
ENTRYPOINT [ "arkd" ]

22
LICENSE Executable file
View File

@@ -0,0 +1,22 @@
MIT License
Copyright (c) 2023 ark-network
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

58
Makefile Executable file
View File

@@ -0,0 +1,58 @@
.PHONY: build clean cov help intergrationtest lint run test vet proto proto-lint
## build: build for all platforms
build:
@echo "Building arkd binary..."
@bash ./scripts/build
## clean: cleans the binary
clean:
@echo "Cleaning..."
@go clean
## cov: generates coverage report
cov:
@echo "Coverage..."
@go test -cover ./...
## help: prints this help message
help:
@echo "Usage: \n"
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
## intergrationtest: runs integration tests
integrationtest:
@echo "Running integration tests..."
@go test -v -count=1 -race ./... $(go list ./... | grep internal/test)
## lint: lint codebase
lint:
@echo "Linting code..."
@golangci-lint run --fix
## run: run in dev mode
run: clean
@echo "Running arkd in dev mode..."
@go run ./cmd/arkd
## test: runs unit and component tests
test:
@echo "Running unit tests..."
@go test -v -count=1 -race ./... $(go list ./... | grep -v internal/test)
## vet: code analysis
vet:
@echo "Running code analysis..."
@go vet ./...
## proto: compile proto stubs
proto: proto-lint
@echo "Compiling stubs..."
@buf generate
## proto-lint: lint protos
proto-lint:
@echo "Linting protos..."
@buf lint

1
README.md Executable file
View File

@@ -0,0 +1 @@
# ark

View File

@@ -0,0 +1,23 @@
syntax = "proto3";
package arkd.v1;
import "google/api/annotations.proto";
// TODO: Edit this proto to something more meaningful for your application.
service Service {
rpc GetVersion(GetVersionRequest) returns (GetVersionResponse) {
option (google.api.http) = {
post: "/v1/hello"
body: "*"
};
}
}
message GetVersionRequest {
string name = 1;
}
message GetVersionResponse {
string message = 1;
}

View File

@@ -0,0 +1,8 @@
# Generated by buf. DO NOT EDIT.
version: v1
deps:
- remote: buf.build
owner: googleapis
repository: googleapis
commit: 28151c0d0a1641bf938a7672c500e01d
digest: shake256:49215edf8ef57f7863004539deff8834cfb2195113f0b890dd1f67815d9353e28e668019165b9d872395871eeafcbab3ccfdb2b5f11734d3cca95be9e8d139de

12
api-spec/protobuf/buf.yaml Executable file
View File

@@ -0,0 +1,12 @@
version: v1
name: buf.build/ark-network/ark
deps:
- buf.build/googleapis/googleapis
breaking:
use:
- FILE
ignore_unstable_packages: true
lint:
use:
- DEFAULT

20
buf.gen.yaml Executable file
View File

@@ -0,0 +1,20 @@
version: v1
managed:
enabled: true
go_package_prefix:
default: github.com/ark-network/ark/api-spec/protobuf/gen
plugins:
# Golang
- remote: buf.build/protocolbuffers/plugins/go
out: api-spec/protobuf/gen/go
opt: paths=source_relative
- remote: buf.build/grpc/plugins/go
out: api-spec/protobuf/gen/go
opt: paths=source_relative,require_unimplemented_servers=false
- remote: buf.build/grpc-ecosystem/plugins/grpc-gateway
out: api-spec/protobuf/gen
opt: paths=source_relative
#OpenApi
- remote: buf.build/grpc-ecosystem/plugins/openapiv2
out: api-spec/openapi/swagger

4
buf.work.yaml Executable file
View File

@@ -0,0 +1,4 @@
version: v1
directories:
- api-spec/protobuf

40
cmd/arkd/main.go Executable file
View File

@@ -0,0 +1,40 @@
package main
import (
"os"
"os/signal"
"syscall"
log "github.com/sirupsen/logrus"
service_interface "github.com/ark-network/ark/internal/interface"
)
//nolint:all
var (
version = "dev"
commit = "none"
date = "unknown"
)
// TODO: Edit this file to something more meaningful for your application.
func main() {
svc, err := service_interface.NewService()
if err != nil {
log.Fatal(err)
}
log.RegisterExitHandler(svc.Stop)
log.Info("starting service...")
if err := svc.Start(); err != nil {
log.Fatal(err)
}
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT)
<-sigChan
log.Info("shutting down service...")
log.Exit(0)
}

7
go.mod Normal file
View File

@@ -0,0 +1,7 @@
module github.com/ark-network/ark
go 1.21.0
require github.com/sirupsen/logrus v1.9.3
require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect

15
go.sum Normal file
View File

@@ -0,0 +1,15 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

35
goreleaser.Dockerfile Executable file
View File

@@ -0,0 +1,35 @@
FROM debian:buster-slim
ARG TARGETPLATFORM
WORKDIR /app
COPY . .
RUN set -ex \
&& if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then export TARGETPLATFORM=amd64; fi \
&& if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then export TARGETPLATFORM=arm64; fi \
&& mv "arkd-linux-$TARGETPLATFORM" /usr/local/bin/arkd
# $USER name, and data $DIR to be used in the 'final' image
ARG USER=ark
ARG DIR=/home/ark
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates
# NOTE: Default GID == UID == 1000
RUN adduser --disabled-password \
--home "$DIR/" \
--gecos "" \
"$USER"
USER $USER
# Prevents 'VOLUME $DIR/.arkd/' being created as owned by 'root'
RUN mkdir -p "$DIR/.arkd/"
# Expose volume containing all arkd data
VOLUME $DIR/.arkd/
ENTRYPOINT [ "arkd" ]

0
internal/config/.gitkeep Executable file
View File

View File

0
internal/core/domain/.gitkeep Executable file
View File

0
internal/core/ports/.gitkeep Executable file
View File

View File

View File

View File

View File

View File

@@ -0,0 +1,22 @@
package grpc_interface
import (
log "github.com/sirupsen/logrus"
)
// TODO: Edit this file to something more meaningful for your application.
type service struct {}
func NewService() (*service, error) {
return &service{}, nil
}
func (s *service) Start() error {
log.Debug("service is listening")
return nil
}
func (s *service) Stop() {
log.Debug("service stopped")
}

16
internal/interface/service.go Executable file
View File

@@ -0,0 +1,16 @@
package service_interface
import (
grpc_interface "github.com/ark-network/ark/internal/interface/grpc"
)
// TODO: Edit this file to something more meaningful for your application.
type Service interface {
Start() error
Stop()
}
func NewService() (Service, error) {
return grpc_interface.NewService()
}

0
internal/test/.gitkeep Executable file
View File

0
pkg/.gitkeep Executable file
View File

18
scripts/build Executable file
View File

@@ -0,0 +1,18 @@
#!/bin/bash
set -e
PARENT_PATH=$(dirname $(
cd $(dirname $0)
pwd -P
))
OS=$(eval "go env GOOS")
ARCH=$(eval "go env GOARCH")
pushd $PARENT_PATH
mkdir -p build
GO111MODULE=on go build -ldflags="-s -w" -o build/arkd-$OS-$ARCH cmd/arkd/main.go
popd