diff --git a/.gitignore b/.gitignore index 4c49bd7..bb109d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ +# env file .env + +# tmp directory +tmp diff --git a/Dockerfile.local b/Dockerfile.local new file mode 100644 index 0000000..41db7be --- /dev/null +++ b/Dockerfile.local @@ -0,0 +1,17 @@ +FROM golang:1.18-alpine3.15 + +WORKDIR /app/go/base + +RUN apk add --no-cache --update-cache \ + alpine-sdk \ + protoc + +RUN go install github.com/cosmtrek/air@latest && \ + go install github.com/golang/protobuf/protoc-gen-go@latest && \ + go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@latest && \ + go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest && \ + go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@latest + +COPY . . + +#RUN go mod tidy diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f02c8f3 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +.PHONY: docker-up +docker-up: + @docker-compose -f docker-compose.local.yml up -d + +.PHONY: docker-down +docker-down: + @docker-compose -f docker-compose.local.yml down + +.PHONY: docker-stop +docker-stop: + @docker-compose -f docker-compose.local.yml stop + +.PHONY: docker-build +docker-build: + @docker-compose -f docker-compose.local.yml build + +.PHONY: watch-log +watch-log: + @docker-compose -f docker-compose.local.yml logs -f blockchain diff --git a/README.md b/README.md new file mode 100644 index 0000000..3c02fa2 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# blockchain server +Provide a blockchain server. + +## Version +- Docker:20.10.12 +- golang:1.18 + +## Commands +### Run local +- `set .env file` +- `make docker-up` + +### Build local +- `make docker-build` + +### Watch log local +- `make watch-log` diff --git a/cmd/.air.toml b/cmd/.air.toml new file mode 100644 index 0000000..65cf500 --- /dev/null +++ b/cmd/.air.toml @@ -0,0 +1,47 @@ +# Config file for [Air](https://github.com/cosmtrek/air) in TOML format + +# Working directory +# . or absolute path, please note that the directories following must be under root. +root = "." +tmp_dir = "tmp" + +[build] +# Just plain old shell command. You could use `make` as well. +cmd = "go build -o /tmp/main ./cmd/main.go" +# Binary file yields from `cmd`. +bin = "/tmp/main" +# Customize binary. +full_bin = "SERVER_ENV=local APP_USER=air /tmp/main" +# Watch these filename extensions. +include_ext = ["go", "tpl", "tmpl"] +# Ignore these filename extensions or directories. +exclude_dir = ["assets", "tmp", "vendor"] +# Watch these directories if you specified. +include_dir = [] +# Exclude files. +exclude_file = [] +# This log file places in your tmp_dir. +log = "air.log" +# It's not necessary to trigger build each time file changes if it's too frequent. +delay = 1000 # ms +# Stop running old binary when build errors occur. +stop_on_error = true +# Send Interrupt signal before killing process (windows does not support this feature) +send_interrupt = false +# Delay after sending Interrupt signal +kill_delay = 500 # ms + +[log] +# Show log time +time = false + +[color] +# Customize each part's color. If no color found, use the raw app log. +main = "magenta" +watcher = "cyan" +build = "yellow" +runner = "green" + +[misc] +# Delete tmp directory on exit +clean_on_exit = true diff --git a/cmd/main.go b/cmd/main.go new file mode 100644 index 0000000..28f37e0 --- /dev/null +++ b/cmd/main.go @@ -0,0 +1,9 @@ +package main + +import ( + "fmt" +) + +func main() { + fmt.Println("hello") +} diff --git a/docker-compose.local.yml b/docker-compose.local.yml new file mode 100644 index 0000000..296f206 --- /dev/null +++ b/docker-compose.local.yml @@ -0,0 +1,18 @@ +version: "3" + +services: + blockchain: + container_name: blockchain-server + build: + context: . + dockerfile: Dockerfile.local + command: "air -c /app/go/base/cmd/.air.toml" + env_file: + - .env + image: blockchain + volumes: + - .:/app/go/base:rw + tty: true + ports: + - ${REST_PORT}:${REST_PORT} + - ${GRPC_PORT}:${GRPC_PORT}