Skip to content

Commit cc60237

Browse files
committed
init v1.0.0
0 parents  commit cc60237

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+6699
-0
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
api/public/http/docs/* linguist-generated=true
2+
api/public/http/docs/* -diff -merge

.github/workflows/ci.yaml

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: Continuous Integration
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- exp
8+
- main
9+
- feature/**
10+
tags: ["**"]
11+
12+
permissions:
13+
id-token: write
14+
contents: read
15+
packages: write
16+
17+
jobs:
18+
test:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Setup go
24+
uses: actions/setup-go@v5
25+
with:
26+
go-version-file: go.mod
27+
cache-dependency-path: go.sum
28+
29+
- name: Run test
30+
run: make _test
31+
32+
lint:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v4
36+
37+
- name: Setup go
38+
uses: actions/setup-go@v5
39+
with:
40+
go-version-file: go.mod
41+
cache-dependency-path: go.sum
42+
43+
- name: Run lint
44+
uses: golangci/golangci-lint-action@v6
45+
with:
46+
version: v1.61
47+
args: --timeout=5m
48+
49+
build:
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@v4
53+
54+
- name: Setup go
55+
uses: actions/setup-go@v5
56+
with:
57+
go-version-file: go.mod
58+
cache-dependency-path: go.sum
59+
60+
- name: Build
61+
env:
62+
GOOS: linux
63+
GOARCH: arm64
64+
run: make _build
65+
66+
build-and-push-image:
67+
if: github.ref == 'refs/heads/exp' || startsWith(github.ref, 'refs/heads/feature/') || startsWith(github.ref, 'refs/tags/')
68+
runs-on: ubuntu-latest
69+
needs:
70+
- test
71+
- lint
72+
- build
73+
steps:
74+
- uses: actions/checkout@v4
75+
76+
- name: Get 10 length commit sha
77+
if: github.ref == 'refs/heads/exp' || startsWith(github.ref, 'refs/heads/feature/')
78+
id: short-sha
79+
run: |
80+
echo value=$(echo ${{ github.sha }} | cut -c1-10) >> $GITHUB_OUTPUT
81+
82+
- name: Log in to the Container registry
83+
uses: docker/login-action@v3
84+
with:
85+
registry: ghcr.io
86+
username: ${{ github.actor }}
87+
password: ${{ secrets.GITHUB_TOKEN }}
88+
89+
- name: Docker meta
90+
id: meta
91+
uses: docker/metadata-action@v5
92+
with:
93+
images: |
94+
ghcr.io/${{ github.repository }}
95+
tags: |
96+
type=raw,priority=100,prefix=exp-,value=${{ steps.short-sha.outputs.value }},enable=${{ startsWith(github.ref, 'refs/heads/exp') }}
97+
type=raw,priority=100,prefix=feature-,value=${{ steps.short-sha.outputs.value }},enable=${{ startsWith(github.ref, 'refs/heads/feature/') }}
98+
type=ref,priority=600,event=tag,enable=${{ startsWith(github.ref, 'refs/tags/') }}
99+
100+
- name: Get current time
101+
id: time
102+
shell: sh
103+
run: |
104+
echo current_time=$(TZ=Asia/Seoul date +'%Y-%m-%dT%H:%M:%S%z') >> $GITHUB_OUTPUT
105+
106+
- name: Set up Docker Buildx
107+
uses: docker/setup-buildx-action@v3
108+
with:
109+
platforms: linux/arm64
110+
111+
- name: Build image and push to GitHub Container Registry
112+
uses: docker/build-push-action@v6
113+
with:
114+
context: .
115+
push: true
116+
tags: ${{ steps.meta.outputs.tags }}
117+
platforms: linux/arm64
118+
build-args: |
119+
BUILD_VERSION=${{ github.ref_name }}
120+
BUILD_COMMIT=${{ github.sha }}
121+
BUILD_TIME=${{ steps.time.outputs.current_time }}

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Artifacts
2+
target/
3+
.idea
4+
5+
*.pem

.golangci.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
run:
2+
go: "1.22"
3+
4+
linters:
5+
enable:
6+
- goimports
7+
- gofmt

Dockerfile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM golang:1.22-bookworm AS builder
2+
3+
ARG TARGETOS
4+
ARG TARGETARCH
5+
6+
WORKDIR /cht-app-github
7+
8+
COPY . .
9+
10+
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build
11+
12+
FROM public.ecr.aws/i8a4b9p4/circleci-base/debian:bookworm-slim-curl AS runtime
13+
14+
ARG BUILD_VERSION
15+
ARG BUILD_COMMIT
16+
ARG BUILD_TIME
17+
ENV BUILD_VERSION=${BUILD_VERSION}
18+
ENV BUILD_COMMIT=${BUILD_COMMIT}
19+
ENV BUILD_TIME=${BUILD_TIME}
20+
21+
WORKDIR /cht-app-github
22+
23+
RUN apt-get update && apt-get install -qy \
24+
ca-certificates
25+
26+
COPY --from=builder /cht-app-github/target/app ./app
27+
COPY --from=builder /cht-app-github/config/*.yml ./config/
28+
29+
EXPOSE 4000
30+
31+
CMD ["./app"]

Makefile

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Project directory structure
2+
PROJECT_PATH := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
3+
4+
# Artifacts
5+
TARGET_DIR = target
6+
7+
# Go environment
8+
GOVERSION := $(shell go version | awk '{print $$3}')
9+
GOOS ?= $(shell go env GOOS)
10+
GOARCH ?= $(shell go env GOARCH)
11+
12+
#
13+
# User commands
14+
#
15+
DC=docker compose -f development/docker-compose.yml
16+
17+
.PHONY: help
18+
help: ## Display this help.
19+
@awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
20+
21+
##@ Development
22+
.PHONY: env
23+
env: ## Print current development environment
24+
@echo "PROJECT_PATH:\t${PROJECT_PATH}"
25+
@echo "GOVERSION:\t${GOVERSION}"
26+
@echo "GOOS:\t\t${GOOS}"
27+
@echo "GOARCH:\t\t${GOARCH}"
28+
29+
.PHONY: dev
30+
dev: setup ## Run development server
31+
@go run ./cmd
32+
33+
.PHONY: setup
34+
setup: deps ## Setup development dependencies in background
35+
36+
.PHONY: generate
37+
generate: _generate
38+
39+
##@ Build
40+
.PHONY: build
41+
build: deps _build ## Build project
42+
43+
.PHONY: deps
44+
deps: ## Sync project dependencies
45+
@go mod download
46+
@go mod tidy
47+
48+
.PHONY: lint
49+
lint: ## Run linter and formatter
50+
@echo Running lint...
51+
@if command -v golangci-lint >/dev/null 2>&1; then \
52+
make _lint; \
53+
else \
54+
$(DC) run --rm lint; \
55+
fi
56+
@echo Done
57+
58+
.PHONY: test
59+
test: ## Run tests
60+
make _test
61+
62+
##@ Cleanup
63+
.PHONY: down
64+
down: ## Clean up local development dependencies
65+
@$(DC) down
66+
67+
.PHONY: clean
68+
clean: ## Clean up all local state
69+
@rm -rf ${TARGET_DIR}
70+
@$(DC) down -v
71+
72+
#
73+
# Internal commands for ci
74+
#
75+
.PHONY: _generate
76+
_generate: _generate-docs
77+
78+
.PHONY: _generate-docs
79+
_generate-docs:
80+
@echo Generating docs...
81+
@swag init -d cmd,api/public/http/route -o api/public/http/docs
82+
@swag fmt
83+
84+
.PHONY: _build
85+
_build:
86+
@go build -o ${TARGET_DIR}/app ./cmd
87+
88+
.PHONY: _test
89+
_test:
90+
@go test -count=1 ./...
91+
92+
.PHONY: _lint
93+
_lint:
94+
@golangci-lint run

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# cht-app-github
2+
> 깃헙앱을 통해 깃헙 이벤트를 채널톡 팀챗과 연동합니다.
3+
> [채널톡 사용가이드](https://docs.channel.io/help/ko/articles/5c755cd0)를 참고해주세요
4+
5+
6+
## Installing / Getting started
7+
> A quick introduction of the minimal setup you need to get a hello world up & running.
8+
1. Install Docker
9+
2. run `make dev`
10+
11+
### Build application
12+
13+
```bash
14+
make build
15+
```
16+
17+
### Run application in development mode
18+
```bash
19+
make dev
20+
```

api/metric/fx.go

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package metric
2+
3+
import (
4+
"errors"
5+
"log"
6+
netHttp "net/http"
7+
"time"
8+
9+
"golang.org/x/net/context"
10+
11+
"go.uber.org/fx"
12+
13+
"github.com/channel-io/cht-app-github/api/metric/http/route"
14+
"github.com/channel-io/cht-app-github/internal/config"
15+
"github.com/channel-io/cht-app-github/internal/http"
16+
)
17+
18+
type ServerParams struct {
19+
fx.In
20+
21+
Config http.ServerConfig `name:"metric.http.config"`
22+
Routes []http.Routes `group:"metric.http.routes"`
23+
}
24+
25+
type ServerResults struct {
26+
fx.Out
27+
28+
Server *http.Server `group:"http.servers"`
29+
}
30+
31+
func NewServer(lifeCycle fx.Lifecycle, p ServerParams) (ServerResults, error) {
32+
server, err := http.NewServer(p.Config, p.Routes, nil)
33+
34+
lifeCycle.Append(fx.Hook{
35+
OnStart: func(_ context.Context) error {
36+
go func(server *http.Server) {
37+
log.Println("starting metric server ...")
38+
if err := server.Run(); err != nil && !errors.Is(err, netHttp.ErrServerClosed) {
39+
panic(err)
40+
}
41+
}(server)
42+
return nil
43+
},
44+
OnStop: func(_ context.Context) error {
45+
log.Println("stopping metric server ...")
46+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
47+
defer cancel()
48+
49+
if err := server.Shutdown(ctx); err != nil {
50+
log.Fatal("Server Shutdown:", err)
51+
return err
52+
}
53+
log.Println("stopped metric server success")
54+
return nil
55+
},
56+
})
57+
58+
return ServerResults{
59+
Server: server,
60+
}, err
61+
}
62+
63+
func HTTPServerModule() fx.Option {
64+
return fx.Module(
65+
"api.metric.http_server",
66+
67+
route.Module(),
68+
69+
fx.Provide(
70+
fx.Annotate(
71+
func(e *config.Config) http.ServerConfig {
72+
return http.ServerConfig{
73+
Port: e.API.Metric.HTTP.Port,
74+
}
75+
},
76+
fx.ResultTags(`name:"metric.http.config"`),
77+
),
78+
),
79+
80+
fx.Provide(
81+
NewServer,
82+
),
83+
)
84+
}

api/metric/http/route/fx.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package route
2+
3+
import (
4+
"go.uber.org/fx"
5+
6+
"github.com/channel-io/cht-app-github/api/metric/http/route/metric"
7+
"github.com/channel-io/cht-app-github/internal/http"
8+
)
9+
10+
func Module() fx.Option {
11+
return fx.Module(
12+
"route",
13+
14+
fx.Provide(
15+
fx.Annotate(
16+
metric.NewHandler,
17+
fx.ParamTags(`name:"metric.handler"`),
18+
fx.As(new(http.Routes)),
19+
fx.ResultTags(`group:"metric.http.routes"`),
20+
),
21+
),
22+
)
23+
}

0 commit comments

Comments
 (0)