Skip to content

Commit

Permalink
사용자 데이터 CR, kakao oauth 인증 기능 및 jwt token을 발급할 수 있는 기능 추가 (#11)
Browse files Browse the repository at this point in the history
* add: local에서 redis를 사용할 수 있도록 컨테이너 추가

* add: redis 버전 지정

* add: 의존성 정보 추가

* use: redis

* init: redis

* add: 테스트 코드 추가

* add: mysql

* add: mysql data 제외

* use: gorm.io/gorm

* add: mysql query test

* del: 이전 프로젝트 파일 제거

* init

* del: 사용되지 않는 코드 삭제

* edit: 모듈 경로 해당 repo로 변경

* doce: 문서화 반영

* up: config 값 모두 환경변수화

* add: 서버 도메인 환경변수화

* add: dev config랑 동기화

* up: 스웨거 관련 환경변수 추가

* up: qa 환경에서 환경변수 주입받을 수 있도록 k8s 수정 완료

* up: 환경 변수 정리
add: local 이외 환경은 https만 스웨거로 볼 수 있도록 수정

* up: 환경변수 순서 변경

* docs: 문서 보강

* up: prod 환경 변수 주입 코드
  • Loading branch information
parkgang committed Nov 9, 2021
1 parent d7354ef commit 87788ca
Show file tree
Hide file tree
Showing 54 changed files with 4,357 additions and 196 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# common
.git
LICENSE
*.md
*.log
59 changes: 8 additions & 51 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,54 +1,11 @@
# Created by https://www.toptal.com/developers/gitignore/api/go,macos
# Edit at https://www.toptal.com/developers/gitignore?templates=go,macos
# vscode-go 디버깅 파일
__debug_bin

### Go ###
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# codegangsta/gin hot reloading시 발생하는 파일
gin-bin

# Test binary, built with `go test -c`
*.test
# docker
docker/**/data

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

### Go Patch ###
/vendor/
/Godeps/

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# End of https://www.toptal.com/developers/gitignore/api/go,macos
# 기타
.DS_STORE
17 changes: 12 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
{
// IntelliSense를 사용하여 가능한 특성에 대해 알아보세요.
// 기존 특성에 대한 설명을 보려면 가리킵니다.
// 자세한 내용을 보려면 https://go.microsoft.com/fwlink/?linkid=830387을(를) 방문하세요.
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"name": "Attach to Gin",
"type": "go",
"request": "attach",
"mode": "local",
"processId": "gin-bin"
},
{
"name": "Server",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}"
"program": "${workspaceFolder}",
"env": {
"GO_ENV": "development"
}
}
]
}
17 changes: 17 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// json에 주석을 사용할 수 있도록 기본 포멧터 변경
"files.associations": {
"*.json": "jsonc"
},

"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,

"[go]": {
"editor.defaultFormatter": "golang.go"
},
// [handler에 중단점을 찍을 때마다 디버깅이 중지되어서 일단은 레거시 디버깅 사용](https://stackoverflow.com/questions/69156581/does-the-execution-have-to-keep-stopping-to-set-a-breakpoint)
"go.delveConfig": {
"debugAdapter": "legacy"
}
}
48 changes: 48 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "container up",
"type": "shell",
"command": "docker-compose",
"args": ["up", "-d"],
"options": {
"cwd": "${workspaceFolder}"
}
},
{
"label": "container stop",
"type": "shell",
"command": "docker-compose",
"args": ["stop"],
"options": {
"cwd": "${workspaceFolder}"
}
},
{
"label": "swag docs update",
"type": "shell",
"command": "swag",
"args": ["i"],
"options": {
"cwd": "${workspaceFolder}",
"env": {
"PATH": "${env:GOPATH}/bin:${env:PATH}"
}
}
},
{
"label": "live reloading gin server",
"type": "shell",
"command": "gin",
"args": ["--port", "5100", "--immediate", "--notifications"],
"options": {
"cwd": "${workspaceFolder}",
"env": {
"PATH": "${env:GOPATH}/bin:${env:PATH}",
"GO_ENV": "development"
}
}
}
]
}
34 changes: 20 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
# [해당 문서를 참고하였습니다](https://thesorauniverse.com/posts/kr/golang/making-golang-docker-img-best-practices/)
FROM golang:1.16.3 AS builder
FROM golang:1.16.3 AS golang-builder

ENV GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64
ENV GO111MODULE=on
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64

WORKDIR /build

COPY . .

COPY ./go.mod ./
COPY ./go.sum ./
RUN go mod download

RUN go build -o main .
COPY ./ ./
RUN go build -o main ./

WORKDIR /dist

RUN cp /build/main .
RUN cp /build/main ./
RUN cp /build/configs/config.prod.json ./

FROM scratch

COPY --from=builder /dist/main .
LABEL author="parkgang[Kyungeun Park]<[email protected]>"
LABEL version="0.1.0"

ENV GO_ENV=production

COPY --from=golang-builder /dist/main ./
COPY --from=golang-builder /dist/config.prod.json ./configs/config.prod.json

EXPOSE 8080

ENTRYPOINT ["/main"]
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
OAuth 인증서버를 구축합니다.

1. JWT Token을 사용합니다.
1. 해당 앱을 사용하기 위해서는 kakao 개발자 센터에서 애플리케이션을 발급받아야 합니다. 발급 후 설정방법은 노션을 참고하도록 합니다.
1. API Spec는 `{url}/swagger/index.html` 으로 요청하여`swagger` 를 참고해주세요.

# Stack

1. go:1.16.3
1. vscode
1. gin
1. redis
1. redis:6.2.4
1. docker

# 시퀀스 다이어그램
Expand All @@ -19,3 +21,11 @@ OAuth 인증서버를 구축합니다.
# 빠른 시작

1. vscode에서 `F5` 혹은 `go run main.go` 으로 시작합니다.

# 의존성

| 이름 | 명령어 |
| ------------------------------------------ | ------------------------------------- |
| [gin](https://github.com/gin-gonic/gin) | `go get -u github.com/gin-gonic/gin` |
| [redis](https://github.com/go-redis/redis) | `go get github.com/go-redis/redis/v8` |
| [GORM](https://github.com/go-gorm/gorm) | `go get -u gorm.io/gorm` |
8 changes: 0 additions & 8 deletions api.http

This file was deleted.

26 changes: 26 additions & 0 deletions configs/config.dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"STAGES": "local",

"SERVER_PORT": "8080",

"SWAGGER_HOSTNAME": "localhost",
"SWAGGER_PORT": "8080",

"KAKAO_REST_API_KEY": "",
"KAKAO_REDIRECT_URI": "",

"JWT_ACCESS_SECRET": "",
"JWT_REFRESH_SECRET": "",
"AUTH_REDIRECT_URL": "http://localhost:3000/auth-end",

"MYSQL_MASTER_HOST": "localhost",
"MYSQL_MASTER_PORT": "3306",
"MYSQL_MASTER_USERNAME": "root",
"MYSQL_MASTER_PASSWORD": "example",
"MYSQL_MASTER_DATABASE": "belf",

"REDIS_HOST": "localhost",
"REDIS_PORT": "6379",
"REDIS_PASSWORD": "",
"REDIS_DATABASE": 0
}
37 changes: 37 additions & 0 deletions configs/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package configs

import (
"os"

"github.com/gin-gonic/gin"
"github.com/spf13/viper"
)

const (
development = "development"
production = "production"
)

func init() {
viper.AutomaticEnv()
// 절대 경로를 기준으로 작성해야 합니다.
viper.AddConfigPath("./configs")

switch os.Getenv("GO_ENV") {
case "":
panic("GO_ENV 값이 지정되지 않았습니다.")
case development:
viper.SetConfigName("config.dev")
gin.SetMode(gin.DebugMode)
case production:
viper.SetConfigName("config.prod")
gin.SetMode(gin.ReleaseMode)
default:
panic("알려지지 않은 GO_ENV 값 입니다.")
}

err := viper.ReadInConfig()
if err != nil {
panic("config 값 읽기에 실패하였습니다.\n\t" + err.Error())
}
}
26 changes: 26 additions & 0 deletions configs/config.prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"STAGES": "local",

"SERVER_PORT": "8080",

"SWAGGER_HOSTNAME": "localhost",
"SWAGGER_PORT": "8080",

"KAKAO_REST_API_KEY": "",
"KAKAO_REDIRECT_URI": "",

"JWT_ACCESS_SECRET": "",
"JWT_REFRESH_SECRET": "",
"AUTH_REDIRECT_URL": "http://localhost:3000/auth-end",

"MYSQL_MASTER_HOST": "host.docker.internal",
"MYSQL_MASTER_PORT": "3306",
"MYSQL_MASTER_USERNAME": "",
"MYSQL_MASTER_PASSWORD": "",
"MYSQL_MASTER_DATABASE": "belf",

"REDIS_HOST": "host.docker.internal",
"REDIS_PORT": "6379",
"REDIS_PASSWORD": "",
"REDIS_DATABASE": 0
}
17 changes: 0 additions & 17 deletions controller/login.go

This file was deleted.

20 changes: 0 additions & 20 deletions controller/token/valid.go

This file was deleted.

Loading

0 comments on commit 87788ca

Please sign in to comment.