Skip to content
Open
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
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Go CI

on:
pull_request:
push:
branches:
- main

workflow_dispatch:
inputs:
skip_tests:
description: 'Skip running tests'
required: false
default: false
type: boolean
triggered_user:
description: 'Who triggered the workflow'
required: false
default: "<!here>"
type: string

jobs:
go-ci:
permissions:
id-token: write
contents: write
packages: read
uses: punchh/GHA-central-workflow/.github/workflows/go-ci.yml@main

with:
repository: ${{ github.repository }}
branch: ${{ github.event_name == 'workflow_dispatch' && github.ref_name || (github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref_name) }}
go_version: 1.24.1
triggered_user: ${{ github.event_name == 'workflow_dispatch' && inputs.triggered_user || '<!here>' }}
skip_tests: ${{ github.event_name == 'workflow_dispatch' && inputs.skip_tests || false }}
test_cases: false
snyk_severity_threshold: "critical"
go_build: true
secrets:
SVC_ACCOUNT_GITHUB_ORG_TOKEN: ${{ secrets.SVC_ACCOUNT_GITHUB_ORG_TOKEN }}
SVC_ACCOUNT_SNYK_ORG_TOKEN: ${{ secrets.SVC_ACCOUNT_SNYK_ORG_TOKEN }}
CAPTAIN_DEVOPS_SLACK_BOT_TOKEN: ${{ secrets.CAPTAIN_DEVOPS_SLACK_BOT_TOKEN }}
30 changes: 0 additions & 30 deletions .github/workflows/go.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
with:
fetch-depth: 0
- run: git fetch --force --tags
- uses: actions/setup-go@v3
- uses: actions/setup-go@v5
with:
go-version: '1.21.5'
go-version: '1.24'
cache: true
# More assembly might be required: Docker logins, GPG, etc. It all depends
# on your needs.
Expand Down
29 changes: 7 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
# Build the application from source
FROM golang:1.21 AS build-stage

WORKDIR /app

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

COPY . .

RUN CGO_ENABLED=0 GOOS=linux go build -o /server main.go

# Deploy the application binary into a lean image
FROM alpine:3.21.3 AS build-release-stage

FROM alpine:3.21.3
Comment thread
kshitij-partech marked this conversation as resolved.
RUN apk update \
&& apk --no-cache add ca-certificates \
&& apk --no-cache add -U tzdata \
&& rm -rf /var/cache/apk/*

WORKDIR /usr/app/
&& apk --no-cache add ca-certificates \
&& apk --no-cache add -U tzdata \
&& rm -rf /var/cache/apk/*

COPY --from=build-stage server .
WORKDIR /server
COPY server .

Comment thread
kshitij-partech marked this conversation as resolved.
EXPOSE 8080
ENTRYPOINT ["./server"]
CMD ["./server"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Codepush server go is compatible with [react-native-code-push](https://github.co

## Support version
- [mysql](https://dev.mysql.com/downloads/mysql/) >= 8.0
- [golang](https://go.dev/dl/) >= 1.21.5
- [golang](https://go.dev/dl/) >= 1.24
- [redis](https://redis.io/downloads/) >= 5.0

## Support client version
Expand Down
37 changes: 37 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ type appConfig struct {
TokenExpireTime int64
Environment string `json:"environment" validate:"required"`
TenantName string `json:"tenant_name" validate:"required"`
// Observability (same JSON keys as go-email-templates service secrets)
AirbrakeProjectID int64
AirbrakeProjectKey string
NewRelicLicenseKey string
}
type dbConfig struct {
Write dbConfigObj
Expand Down Expand Up @@ -76,6 +80,25 @@ func GetConfig() *appConfig {
}

func LoadConfig() *appConfig {
intFormatter := func(v interface{}) (val int64, ok bool) {
switch ta := v.(type) {
case int:
return int64(ta), true
case int64:
return ta, true
case float64:
return int64(ta), true
case string:
parsed, err := strconv.ParseInt(ta, 10, 64)
if err != nil {
return 0, false
}
return parsed, true
default:
return 0, false
}
}

fmt.Println("Fetching config from AWS secret manager...")
keys := []string{
"global", // Global secrets
Expand Down Expand Up @@ -206,6 +229,20 @@ func LoadConfig() *appConfig {
if k == "environment" {
config.Environment = v.(string)
}

if k == "airbrake_project_id" {
if parsed, ok := intFormatter(v); ok {
config.AirbrakeProjectID = parsed
} else {
fmt.Printf("config: invalid airbrake_project_id value (%T): %v\n", v, v)
}
}
if k == "airbrake_project_key" {
config.AirbrakeProjectKey = v.(string)
}
if k == "newrelic_license_key" {
config.NewRelicLicenseKey = v.(string)
}
}
}
config.DBUser.Write = dbObj
Expand Down
11 changes: 10 additions & 1 deletion db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"time"

"com.lc.go.codepush/server/config"

_ "github.com/newrelic/go-agent/v3/integrations/nrmysql"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
Expand All @@ -20,7 +22,14 @@ func GetUserDB() (odb *gorm.DB, err error) {
dbConfig := config.GetConfig().DBUser
dsnSource := dbConfig.Write.UserName + ":" + dbConfig.Write.Password + "@tcp(" + dbConfig.Write.Host + ":" + strconv.Itoa(int(dbConfig.Write.Port)) + ")/" + dbConfig.Write.DBname + "?charset=utf8mb4&parseTime=True&loc=Local"

db, err := gorm.Open(mysql.Open(dsnSource), &gorm.Config{
// New Relic datastore instrumentation:
// Using the "nrmysql" driver enables MySQL metrics. To associate DB segments with the
// current HTTP transaction, queries must run with the request context
// (e.g. via `db.WithContext(c.Request.Context())` in handlers).
db, err := gorm.Open(mysql.New(mysql.Config{
DriverName: "nrmysql",
DSN: dsnSource,
}), &gorm.Config{
Logger: logger.Default.LogMode(logger.Error),
})
if err != nil {
Expand Down
27 changes: 20 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
module com.lc.go.codepush/server

go 1.21
go 1.24
Comment thread
kshitij-partech marked this conversation as resolved.

require (
github.com/go-playground/validator/v10 v10.19.0
github.com/jlaffaye/ftp v0.2.0
github.com/newrelic/go-agent/v3/integrations/nrgin v1.2.1
github.com/newrelic/go-agent/v3/integrations/nrmysql v1.2.2
github.com/punchh/go-packages v1.2.1
github.com/sirupsen/logrus v1.9.4
gorm.io/driver/mysql v1.5.6
)

require (
github.com/airbrake/gobrake/v5 v5.6.2 // indirect
github.com/bytedance/sonic v1.11.3 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/caio/go-tdigest/v4 v4.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
Expand All @@ -19,24 +25,31 @@ require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jonboulle/clockwork v0.5.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/newrelic/go-agent/v3 v3.24.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.7.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
golang.org/x/crypto v0.33.0 // indirect
golang.org/x/net v0.35.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/text v0.22.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
google.golang.org/grpc v1.54.0 // indirect
google.golang.org/protobuf v1.36.5 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand Down
Loading