-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from octoposprime/first/hsm/3/create-project
First Project Structure Created
- Loading branch information
Showing
69 changed files
with
1,236 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# If you prefer the allow list template instead of the deny list, see community template: | ||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore | ||
# | ||
# 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 | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
# Go workspace file | ||
go.work | ||
|
||
# ignore local environment variable file | ||
.env | ||
|
||
# ingore built executables | ||
out/ | ||
bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
FROM golang:1.20-bullseye as base | ||
|
||
RUN adduser \ | ||
--disabled-password \ | ||
--gecos "" \ | ||
--home "/nonexistent" \ | ||
--shell "/sbin/nologin" \ | ||
--no-create-home \ | ||
--uid 65532 \ | ||
op | ||
|
||
WORKDIR /app | ||
COPY . ./ | ||
RUN go mod tidy | ||
RUN go get -v ./... | ||
RUN go mod download | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o main ./cmd/service/main.go | ||
|
||
FROM scratch | ||
|
||
ARG TEST | ||
ENV TEST=${TEST} | ||
ARG POSTGRES_USERNAME | ||
ENV POSTGRES_USERNAME=${POSTGRES_USERNAME} | ||
ARG POSTGRES_PASSWORD | ||
ENV POSTGRES_PASSWORD=${POSTGRES_PASSWORD} | ||
ARG JWT_SECRET_KEY | ||
ENV JWT_SECRET_KEY=${JWT_SECRET_KEY} | ||
ARG REDIS_PASSWORD | ||
ENV REDIS_PASSWORD=${REDIS_PASSWORD} | ||
ARG POSTGRES_DATABASE | ||
ENV POSTGRES_DATABASE=${POSTGRES_DATABASE} | ||
|
||
COPY --from=base /usr/share/zoneinfo /usr/share/zoneinfo | ||
COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
COPY --from=base /etc/passwd /etc/passwd | ||
COPY --from=base /etc/group /etc/group | ||
|
||
COPY --from=base /app/main . | ||
COPY --from=base /app/config/ ./config/ | ||
|
||
USER op:op | ||
EXPOSE 18000 | ||
EXPOSE 18080 | ||
|
||
CMD ["./main"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 octoposprime | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
GOCMD=go | ||
GOTEST=$(GOCMD) test | ||
GOBUILD=$(GOCMD) build | ||
BINARY_NAME=main | ||
VERSION?=0.0.0#Docker image release version | ||
DOCKER_REGISTRY?=ghcr.io#Docker registry | ||
DOCKER_REPOSITORY?=octoposprime#Docker repository owner | ||
DOCKER_CONTAINER?=octo-bot#Docker image name | ||
EXPORT_RESULT?=false# for CI please set EXPORT_RESULT to true | ||
TEST?=false#is the container test? | ||
POSTGRES_USERNAME?=op#Postgres Db User Name | ||
POSTGRES_PASSWORD?=op#Postgres Db Password | ||
JWT_SECRET_KEY?=op#Jwt Secret Key | ||
REDIS_PASSWORD?=op#Redis Password | ||
LOCAL_PORT=18083#Grpc port for local | ||
CONTAINER_PORT=18080#Grpc port in container | ||
NETWORK=op#Docker network name | ||
|
||
GREEN := $(shell tput -Txterm setaf 2) | ||
YELLOW := $(shell tput -Txterm setaf 3) | ||
WHITE := $(shell tput -Txterm setaf 7) | ||
CYAN := $(shell tput -Txterm setaf 6) | ||
RESET := $(shell tput -Txterm sgr0) | ||
|
||
.PHONY: all test build coverage lint | ||
|
||
all: help | ||
|
||
## Build: | ||
build: ## Build your project and put the output binary in out/bin/ | ||
mkdir -p out/bin | ||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -ldflags="-s -w" -o out/bin/$(BINARY_NAME) ./cmd/service/main.go | ||
|
||
clean: ## Remove build related file | ||
rm -rf out/ | ||
|
||
## Test: | ||
test: ## Run the tests of the project | ||
$(GOTEST) -v -race ./... $(OUTPUT_OPTIONS) | ||
|
||
coverage: ## Run the tests of the project and export the coverage | ||
$(GOTEST) -cover -covermode=count -coverprofile=out/profile.cov ./... | ||
$(GOCMD) tool cover -func out/profile.cov | ||
ifeq ($(EXPORT_RESULT), true) | ||
GO111MODULE=off go get github.com/AlekSi/gocov-xml | ||
GO111MODULE=off go get github.com/axw/gocov/gocov | ||
gocov convert out/profile.cov | gocov-xml > out/coverage.xml | ||
endif | ||
|
||
## Lint: | ||
lint: ## Use golintci-lint on your project | ||
$(eval OUTPUT_OPTIONS = $(shell [ "${EXPORT_RESULT}" == "true" ] && echo "--out-format checkstyle ./... | tee /dev/tty > out/checkstyle-report.xml" || echo "" )) | ||
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:latest-alpine golangci-lint run --deadline=65s $(OUTPUT_OPTIONS) | ||
|
||
## Docker: | ||
docker-build: ## Use the dockerfile to build the container | ||
docker build --rm --tag $(DOCKER_REPOSITORY)/$(DOCKER_CONTAINER) \ | ||
--build-arg TEST=$(TEST) \ | ||
--build-arg POSTGRES_USERNAME=$(POSTGRES_USERNAME) \ | ||
--build-arg POSTGRES_PASSWORD=$(POSTGRES_PASSWORD) \ | ||
--build-arg JWT_SECRET_KEY=$(JWT_SECRET_KEY) \ | ||
--build-arg REDIS_PASSWORD=$(REDIS_PASSWORD) . | ||
|
||
docker-release: ## Release the container with tag latest and version | ||
docker tag $(DOCKER_REPOSITORY)/$(DOCKER_CONTAINER) $(DOCKER_REGISTRY)/$(DOCKER_REPOSITORY)/$(DOCKER_CONTAINER):latest | ||
docker tag $(DOCKER_REPOSITORY)/$(DOCKER_CONTAINER) $(DOCKER_REGISTRY)/$(DOCKER_REPOSITORY)/$(DOCKER_CONTAINER):$(VERSION) | ||
# Push the docker images | ||
docker push $(DOCKER_REGISTRY)/$(DOCKER_REPOSITORY)/$(DOCKER_CONTAINER):latest | ||
docker push $(DOCKER_REGISTRY)/$(DOCKER_REPOSITORY)/$(DOCKER_CONTAINER):$(VERSION) | ||
|
||
## Run: | ||
local-run: ## Run in Local for Development | ||
LOCAL=true go run cmd/service/main.go | ||
|
||
docker-run: ## Run in Docker for Development | ||
docker run -d --expose $(LOCAL_PORT) -p $(LOCAL_PORT):$(CONTAINER_PORT) --network $(NETWORK) --name $(DOCKER_CONTAINER) $(DOCKER_REPOSITORY)/$(DOCKER_CONTAINER) | ||
|
||
## Help: | ||
help: ## Show this help. | ||
@echo '' | ||
@echo 'Usage:' | ||
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}' | ||
@echo '' | ||
@echo 'Targets:' | ||
@awk 'BEGIN {FS = ":.*?## "} { \ | ||
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \ | ||
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \ | ||
}' $(MAKEFILE_LIST) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,30 @@ | ||
# octo-bot | ||
# octo-bot | ||
The OctoBot Services for the Backend Layer of OctopOSPrime - Computed Microservices | ||
|
||
[![Build - Test](https://github.com/octoposprime/octo-bot/actions/workflows/ci.yml/badge.svg)](https://github.com/octoposprime/octo-bot/actions/workflows/ci.yml) | ||
[![Docker Image Publish](https://github.com/octoposprime/octo-bot/actions/workflows/cd.yml/badge.svg)](https://github.com/octoposprime/octo-bot/actions/workflows/cd.yml) | ||
|
||
## Pre-Requirements | ||
|
||
## Development Environment | ||
You have to see ![github.com/octoposprime/op-be-docs](https://github.com/octoposprime/op-be-docs) before development. | ||
|
||
#### .env | ||
``` | ||
POSTGRES_USERNAME=op | ||
POSTGRES_PASSWORD=op | ||
JWT_SECRET_KEY=op | ||
REDIS_PASSWORD=op | ||
POSTGRES_DATABASE=op | ||
``` | ||
|
||
#### Local Run | ||
``` | ||
make local-run | ||
``` | ||
|
||
#### Docker Run | ||
``` | ||
TEST=true POSTGRES_USERNAME=op POSTGRES_PASSWORD=op JWT_SECRET_KEY=op REDIS_PASSWORD=op make docker-build | ||
make docker-run | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package main | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/golobby/container/v3" | ||
|
||
pa_command "github.com/octoposprime/octo-bot/internal/application/presentation/adapter/command" | ||
pa_query "github.com/octoposprime/octo-bot/internal/application/presentation/adapter/query" | ||
as "github.com/octoposprime/octo-bot/internal/application/service" | ||
ds "github.com/octoposprime/octo-bot/internal/domain/service" | ||
ia_repo "github.com/octoposprime/octo-bot/pkg/infrastructure/adapter/repository" | ||
pc_dc "github.com/octoposprime/octo-bot/pkg/presentation/controller/dc" | ||
tconfig "github.com/octoposprime/octo-bot/tool/config" | ||
tseed "github.com/octoposprime/octo-bot/tool/config" | ||
) | ||
|
||
var dbConfig tconfig.DbConfig | ||
var dcConfig tconfig.DcConfig | ||
var seedConfig tseed.SeedConfig | ||
|
||
func main() { | ||
dbConfig.ReadConfig() | ||
dcConfig.ReadConfig() | ||
seedConfig.ReadConfig() | ||
var err error | ||
|
||
/*fmt.Println("Starting User Service...") | ||
dbClient, err := tgorm.NewGormClient(tgorm.PostgresGormClient).Connect(dbConfig.PostgresDb.Host, dbConfig.PostgresDb.Port, dbConfig.PostgresDb.UserName, dbConfig.PostgresDb.Password, dbConfig.PostgresDb.Database) | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println("Connected to DB")*/ | ||
|
||
cont := container.New() | ||
|
||
//Domain OctoBot Service | ||
err = cont.Singleton(func() *ds.Service { | ||
return ds.NewService() | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
//Infrastructure OctoBot Db Repository Adapter | ||
err = cont.Singleton(func() ia_repo.DbAdapter { | ||
return ia_repo.NewDbAdapter(nil) | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
//Application OctoBot Service | ||
err = cont.Singleton(func(s *ds.Service, d ia_repo.DbAdapter) *as.Service { | ||
return as.NewService(s, &d) | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
//Application OctoBot Query Adapter | ||
err = cont.Singleton(func(s *as.Service) pa_query.QueryAdapter { | ||
return pa_query.NewQueryAdapter(s) | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
//Application OctoBot Command Adapter | ||
err = cont.Singleton(func(s *as.Service) pa_command.CommandAdapter { | ||
return pa_command.NewCommandAdapter(s) | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
var queryHandler pa_query.QueryAdapter | ||
err = cont.Resolve(&queryHandler) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
var commandHandler pa_command.CommandAdapter | ||
err = cont.Resolve(&commandHandler) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
wg := sync.WaitGroup{} | ||
wg.Add(1) | ||
go pc_dc.NewDcAPI(queryHandler, commandHandler).Start(dcConfig) | ||
wg.Wait() | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dc: | ||
token: "" | ||
guildid: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dc: | ||
token: "" | ||
guildid: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dc: | ||
token: "" | ||
guildid: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mongodb: | ||
enabled: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mongodb: | ||
enabled: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mongodb: | ||
enabled: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
|
||
} |
Oops, something went wrong.