Skip to content

Commit

Permalink
Merge pull request #4 from threefoldtech/development-init-project
Browse files Browse the repository at this point in the history
Initial release
  • Loading branch information
xmonader authored Nov 7, 2024
2 parents 14e261c + 65f7a9b commit 8a5763a
Show file tree
Hide file tree
Showing 41 changed files with 6,058 additions and 1 deletion.
23 changes: 23 additions & 0 deletions .app.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
MONGO_URI=mongodb://root:password@db:27017
DATABASE_NAME=tfgrid-kyc-db
PORT=8080
CHALLENGE_WINDOW=120
CHALLENGE_DOMAIN=kyc.dev.grid.tf
VERIFICATION_SUSPICIOUS_VERIFICATION_OUTCOME=APPROVED
VERIFICATION_EXPIRED_DOCUMENT_OUTCOME=APPROVED
VERIFICATION_MIN_BALANCE_TO_VERIFY_ACCOUNT=1000000
IDENFY_BASE_URL=https://ivs.idenfy.com
IDENFY_API_KEY=
IDENFY_API_SECRET=
IDENFY_CALLBACK_SIGN_KEY=
IDENFY_WHITELISTED_IPS=
IDENFY_DEV_MODE=false
TFCHAIN_WS_PROVIDER_URL=wss://tfchain.dev.grid.tf
IP_LIMITER_MAX_TOKEN_REQUESTS=5
IP_LIMITER_TOKEN_EXPIRATION=1440
ID_LIMITER_MAX_TOKEN_REQUESTS=5
ID_LIMITER_TOKEN_EXPIRATION=1440
DEBUG=false
IDENFY_CALLBACK_URL=https://kyc.dev.grid.tf/webhooks/idenfy/verification-update
IDENFY_NAMESPACE=
VERIFICATION_ALWAYS_VERIFIED_IDS=
2 changes: 2 additions & 0 deletions .db.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MONGO_INITDB_ROOT_USERNAME=root
MONGO_INITDB_ROOT_PASSWORD=password
4 changes: 4 additions & 0 deletions .express.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ME_CONFIG_MONGODB_AUTH_USERNAME=root
ME_CONFIG_MONGODB_AUTH_PASSWORD=password
ME_CONFIG_BASICAUTH_USERNAME=admin
ME_CONFIG_BASICAUTH_PASSWORD=password
58 changes: 58 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Build and Publish Docker Image

on:
release:
types: [published]
workflow_dispatch:

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

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

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Generate tags
id: tags
run: |
if [ "${{ github.event_name }}" = "release" ]; then
VERSION=${GITHUB_REF#refs/tags/}
echo "tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${VERSION},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_OUTPUT
else
SHA=$(git rev-parse --short HEAD)
echo "tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:edge-${SHA},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:edge-latest" >> $GITHUB_OUTPUT
fi
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.tags.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*.dll
*.so
*.dylib
bin/

# Test binary, built with `go test -c`
*.test
Expand All @@ -21,5 +22,9 @@
go.work
go.work.sum

# env file
# env files
.env
.*.env

# other files
main
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM golang:1.22-alpine AS builder

WORKDIR /app

RUN apk add --no-cache git

COPY go.mod go.sum ./

RUN go mod download

COPY . .
RUN VERSION=$(git describe --tags --always) && \
CGO_ENABLED=0 GOOS=linux go build -o tfkycv -ldflags "-X github.com/threefoldtech/tf-kyc-verifier/internal/build.Version=$VERSION" cmd/api/main.go

FROM alpine:3.19

COPY --from=builder /app/tfkycv .
RUN apk --no-cache add curl

ENTRYPOINT ["/tfkycv"]

EXPOSE 8080
132 changes: 132 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Variables
APP_NAME := tfkycv
IMAGE_NAME := ghcr.io/threefoldtech/tf-kyc-verifier
MAIN_PATH := cmd/api/main.go
SWAGGER_GENERAL_API_INFO_PATH := internal/handlers/handlers.go
DOCKER_COMPOSE := docker compose

# Go related variables
GOBASE := $(shell pwd)
GOBIN := $(GOBASE)/bin
GOFILES := $(wildcard *.go)

# Git related variables
GIT_COMMIT := $(shell git rev-parse --short HEAD)
VERSION := $(shell git describe --tags --always)

# Build flags
LDFLAGS := -X github.com/threefoldtech/tf-kyc-verifier/internal/build.Version=$(VERSION)

.PHONY: all build clean test coverage lint swagger run docker-build docker-up docker-down help

# Default target
all: clean build

# Build the application
build:
@echo "Building $(APP_NAME)..."
@go build -ldflags "$(LDFLAGS)" -o $(GOBIN)/$(APP_NAME) $(MAIN_PATH)

# Clean build artifacts
clean:
@echo "Cleaning..."
@rm -rf $(GOBIN)
@go clean

# Run tests
test:
@echo "Running tests..."
@go test -v ./...

# Run tests with coverage
coverage:
@echo "Running tests with coverage..."
@go test -coverprofile=coverage.out ./...
@go tool cover -html=coverage.out
@rm coverage.out

# Run linter
lint:
@echo "Running linter..."
@golangci-lint run

# Generate swagger documentation
swagger:
@echo "Generating Swagger documentation..."
@export PATH=$PATH:$(go env GOPATH)/bin
@swag init -g $(SWAGGER_GENERAL_API_INFO_PATH) --output api/docs

# Run the application locally
run: swagger build
@echo "Running $(APP_NAME)..."
@set -o allexport; . ./.app.env; set +o allexport; $(GOBIN)/$(APP_NAME)

# Build docker image
docker-build:
@echo "Building Docker image..."
@docker build -t $(IMAGE_NAME):$(VERSION) .

# Start docker compose services
docker-up:
@echo "Starting Docker services..."
@$(DOCKER_COMPOSE) up --build -d

# Stop docker compose services
docker-down:
@echo "Stopping Docker services..."
@$(DOCKER_COMPOSE) down

# Start development environment
dev: swagger docker-up
@echo "Starting development environment..."
@$(DOCKER_COMPOSE) logs -f api

# Update dependencies
deps-update:
@echo "Updating dependencies..."
@go get -u ./...
@go mod tidy

# Verify dependencies
deps-verify:
@echo "Verifying dependencies..."
@go mod verify

# Check for security vulnerabilities
security-check:
@echo "Checking for security vulnerabilities..."
@gosec ./...

# Format code
fmt:
@echo "Formatting code..."
@go fmt ./...

# Show help
help:
@echo "Available targets:"
@echo " make : Build the application after cleaning"
@echo " make build : Build the application"
@echo " make clean : Clean build artifacts"
@echo " make test : Run tests"
@echo " make coverage : Run tests with coverage report"
@echo " make lint : Run linter"
@echo " make swagger : Generate Swagger documentation"
@echo " make run : Run the application locally"
@echo " make docker-build : Build Docker image"
@echo " make docker-up : Start Docker services"
@echo " make docker-down : Stop Docker services"
@echo " make dev : Start development environment"
@echo " make deps-update : Update dependencies"
@echo " make deps-verify : Verify dependencies"
@echo " make security-check: Check for security vulnerabilities"
@echo " make fmt : Format code"
@echo " make install-tools: Install development tools"

# Install development tools
.PHONY: install-tools
install-tools:
@echo "Installing development tools..."
@go install github.com/swaggo/swag/cmd/swag@latest
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
@go install github.com/securego/gosec/v2/cmd/gosec@latest
Loading

0 comments on commit 8a5763a

Please sign in to comment.