Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

.git
.env
.env.example

*.log
*.tmp
62 changes: 62 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: build test before PR to main

permissions:
pull-requests: write

on:
pull_request:
branches: ["main"]

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.23.4

- name: Build file
run: go build ./cmd/main.go

- name: install go-ctrf-json-reporter
run: go install github.com/ctrf-io/go-ctrf-json-reporter/cmd/go-ctrf-json-reporter@latest

- name: Test with the Go CLI
run: go test ./... -json > test-report.json

- name: create ctrf-report.json
run: cat test-report.json | go-ctrf-json-reporter -output ctrf-report.json
if: always()

- name: Upload test report
uses: actions/upload-artifact@v4
if: always()
with:
name: ctrf-report
path: ctrf-report.json

report:
runs-on: ubuntu-latest
needs: build-and-test
if: always()

steps:
- name: Download test report
uses: actions/download-artifact@v4
with:
name: ctrf-report

- name: Setup Node.js
uses: actions/setup-node@v4

- name: Publish CTRF pull request comment
run: npx github-actions-ctrf pull-request ctrf-report.json
if: always()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: annotate test result
run: npx github-actions-ctrf annotate ctrf-report.json
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Build Stage
FROM golang:1.23.4 AS builder
ENV CGO_ENABLED=0 \
GOOS=linux

WORKDIR /app

# Download Go modules
COPY go.mod go.sum ./
RUN go mod download

# Copy the source code. Note the slash at the end, as explained in
# https://docs.docker.com/reference/dockerfile/#copy
COPY . ./

# Disable CGO and set target OS to Linux for a portable static binary
RUN go build -o /techbloghub-server ./cmd/main.go


# Final Stage
FROM alpine:latest AS deployment

# copy only built binaries
COPY --from=builder /techbloghub-server ./

# Optional:
# To bind to a TCP port, runtime parameters must be supplied to the docker command.
# But we can document in the Dockerfile what ports
# the application is going to listen on by default.
# https://docs.docker.com/reference/dockerfile/#expose
EXPOSE 8080

# Run
CMD ["./techbloghub-server"]
4 changes: 2 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ func main() {
// PORT 환경변수에서 가져오기
// 후에 이런 config값 관리할것들 많아지면 후에 Config struct등으로 분리 고려
port := getEnvWithDefault("PORT", "8080")
r := SetRouter()
r := setRouter()
err := r.Run(":" + port)
if err != nil {
fmt.Println("Error while running server: ", err)
return
}
}

func SetRouter() *gin.Engine {
func setRouter() *gin.Engine {
r := gin.Default()
r.GET("/ping", func(context *gin.Context) {
context.String(200, "pong")
Expand Down
34 changes: 34 additions & 0 deletions cmd/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"net/http"
"net/http/httptest"
"testing"

"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
)

func TestPingEndpoint(t *testing.T) {
// Set Gin to Test Mode
gin.SetMode(gin.TestMode)

// Create a new router instance using the private setRouter function
router := setRouter()

// Create a test HTTP recorder
w := httptest.NewRecorder()

// Create a test request to the /ping endpoint
req, err := http.NewRequest("GET", "/ping", nil)
assert.NoError(t, err)

// Serve the request using the router
router.ServeHTTP(w, req)

// Assert the response code is 200
assert.Equal(t, http.StatusOK, w.Code)

// Assert the response body is "pong"
assert.Equal(t, "pong", w.Body.String())
}
30 changes: 11 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,42 @@ module github.com/techbloghub/server
go 1.23.4

require (
ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43 // indirect
entgo.io/ent v0.14.1 // indirect
github.com/agext/levenshtein v1.2.1 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/gin-gonic/gin v1.10.0
github.com/joho/godotenv v1.5.1
github.com/stretchr/testify v1.10.0
)

require (
github.com/bytedance/sonic v1.12.6 // indirect
github.com/bytedance/sonic/loader v0.2.1 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.7 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.10.0 // indirect
github.com/go-openapi/inflect v0.19.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.23.0 // indirect
github.com/goccy/go-json v0.10.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/hcl/v2 v2.13.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/zclconf/go-cty v1.8.0 // indirect
golang.org/x/arch v0.12.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/tools v0.24.0 // indirect
google.golang.org/protobuf v1.36.1 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading