Skip to content

Commit

Permalink
Merge pull request #13 from threefoldtech/development
Browse files Browse the repository at this point in the history
v0.3
  • Loading branch information
xmonader authored Nov 7, 2024
2 parents ebbd698 + 8a5763a commit 8917e3d
Show file tree
Hide file tree
Showing 38 changed files with 1,858 additions and 922 deletions.
1 change: 1 addition & 0 deletions .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 Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ COPY go.mod go.sum ./
RUN go mod download

COPY . .
RUN VERSION=`git describe --tags` && \
CGO_ENABLED=0 GOOS=linux go build -o tfgrid-kyc -ldflags "-X github.com/threefoldtech/tf-kyc-verifier/internal/build.Version=$VERSION" cmd/api/main.go
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/tfgrid-kyc .
COPY --from=builder /app/tfkycv .
RUN apk --no-cache add curl

ENTRYPOINT ["/tfgrid-kyc"]
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
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,22 @@ First make sure to create and set the environment variables in the `.app.env`, `
Examples can be found in `.app.env.example`, `.db.env.example`.
In beta releases, we include the mongo-express container, but you can opt to disable it.
To start only the server and MongoDB using Docker Compose:
To start only the core services (API and MongoDB) using Docker Compose:
```bash
docker compose up -d db api
docker compose up -d
```
For a full setup with mongo-express, make sure to create and set the environment variables in the `.express.env` file as well, then run:
To include mongo-express for development, make sure to create and set the environment variables in the `.express.env` file as well, then run:
```bash
docker compose up -d
docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d
```
To start only mongo-express if core services are already running, run:
```bash
docker compose -f docker-compose.dev.yml up -d mongo-express
```
### Running Locally
Expand Down
Loading

0 comments on commit 8917e3d

Please sign in to comment.