mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 20:24:27 -04:00
Add healthcheck for auth (#658)
This commit is contained in:
parent
c9de1263d7
commit
899e90deaf
52
.github/workflows/robot.yml
vendored
52
.github/workflows/robot.yml
vendored
@ -1,52 +0,0 @@
|
|||||||
name: RobotTests
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
- next
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
name: Run Robot Tests
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Robot cache
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: '3.9'
|
|
||||||
cache: 'pip'
|
|
||||||
|
|
||||||
- run: pip install -r requirements.txt
|
|
||||||
|
|
||||||
- name: Docker cache
|
|
||||||
uses: satackey/action-docker-layer-caching@v0.0.11
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: Start the service
|
|
||||||
run: |
|
|
||||||
cp .env.example .env
|
|
||||||
docker compose --profile v5 -f docker-compose.build.yml up -d auth postgres traefik --wait --build
|
|
||||||
|
|
||||||
- name: Perform healthchecks
|
|
||||||
run: |
|
|
||||||
docker compose ps -a
|
|
||||||
docker compose logs
|
|
||||||
# wget --retry-connrefused --retry-on-http-error=502 http://localhost:8901/api/health || (docker compose logs && exit 1)
|
|
||||||
|
|
||||||
- name: Run robot tests
|
|
||||||
run: |
|
|
||||||
robot -d out $(find -type d -name robot)
|
|
||||||
|
|
||||||
- name: Show logs
|
|
||||||
if: failure()
|
|
||||||
run: docker compose logs
|
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: results
|
|
||||||
path: out
|
|
||||||
|
|
74
.github/workflows/robot_auth.yml
vendored
Normal file
74
.github/workflows/robot_auth.yml
vendored
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
name: RobotTests
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- next
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
name: Robot tests Auth
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres:15
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
||||||
|
env:
|
||||||
|
POSTGRES_USER: kyoo
|
||||||
|
POSTGRES_PASSWORD: password
|
||||||
|
options: >-
|
||||||
|
--health-cmd pg_isready
|
||||||
|
--health-interval 10s
|
||||||
|
--health-timeout 5s
|
||||||
|
--health-retries 5
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Robot cache
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '3.9'
|
||||||
|
cache: 'pip'
|
||||||
|
|
||||||
|
- run: pip install -r requirements.txt
|
||||||
|
|
||||||
|
- uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: '^1.22.5'
|
||||||
|
cache-dependency-path: ./auth/go.sum
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
working-directory: ./auth
|
||||||
|
run: |
|
||||||
|
go mod download
|
||||||
|
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
|
||||||
|
go install github.com/swaggo/swag/cmd/swag@latest
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
working-directory: ./auth
|
||||||
|
run: |
|
||||||
|
sqlc generate
|
||||||
|
swag init --parseDependency
|
||||||
|
go build -o ./keibi
|
||||||
|
|
||||||
|
- name: Run robot tests
|
||||||
|
working-directory: ./auth
|
||||||
|
run: |
|
||||||
|
./keibi > logs &
|
||||||
|
wget --retry-connrefused --retry-on-http-error=502 http://localhost:4568/health
|
||||||
|
robot -d out robot
|
||||||
|
env:
|
||||||
|
POSTGRES_SERVER: localhost
|
||||||
|
|
||||||
|
- name: Show logs
|
||||||
|
working-directory: ./auth
|
||||||
|
run: cat logs
|
||||||
|
|
||||||
|
- uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: results
|
||||||
|
path: auth/out
|
||||||
|
|
@ -2,10 +2,10 @@
|
|||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
|
|
||||||
# Database things
|
# Database things
|
||||||
POSTGRES_USER=
|
POSTGRES_USER=kyoo
|
||||||
POSTGRES_PASSWORD=
|
POSTGRES_PASSWORD=password
|
||||||
POSTGRES_DB=
|
POSTGRES_DB=kyoo
|
||||||
POSTGRES_SERVER=
|
POSTGRES_SERVER=postgres
|
||||||
POSTGRES_PORT=5432
|
POSTGRES_PORT=5432
|
||||||
# Default is keibi, you can specify "disabled" to use the default search_path of the user.
|
# Default is keibi, you can specify "disabled" to use the default search_path of the user.
|
||||||
# If this is not "disabled", the schema will be created (if it does not exists) and
|
# If this is not "disabled", the schema will be created (if it does not exists) and
|
||||||
|
@ -22,4 +22,5 @@ USER nonroot:nonroot
|
|||||||
|
|
||||||
COPY --from=build /keibi /app/keibi
|
COPY --from=build /keibi /app/keibi
|
||||||
COPY sql ./sql
|
COPY sql ./sql
|
||||||
|
|
||||||
CMD ["/app/keibi"]
|
CMD ["/app/keibi"]
|
||||||
|
31
auth/main.go
31
auth/main.go
@ -53,28 +53,37 @@ func (v *Validator) Validate(i interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Handler) CheckHealth(c echo.Context) error {
|
||||||
|
return c.JSON(200, struct{ Status string }{Status: "healthy"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetenvOr(env string, def string) string {
|
||||||
|
out := os.Getenv(env)
|
||||||
|
if out == "" {
|
||||||
|
return def
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
func OpenDatabase() (*pgxpool.Pool, error) {
|
func OpenDatabase() (*pgxpool.Pool, error) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
port, err := strconv.ParseUint(os.Getenv("POSTGRES_PORT"), 10, 16)
|
port, err := strconv.ParseUint(GetenvOr("POSTGRES_PORT", "5432"), 10, 16)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("invalid postgres port specified")
|
return nil, errors.New("invalid postgres port specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
config, _ := pgxpool.ParseConfig("")
|
config, _ := pgxpool.ParseConfig("")
|
||||||
config.ConnConfig.Host = os.Getenv("POSTGRES_SERVER")
|
config.ConnConfig.Host = GetenvOr("POSTGRES_SERVER", "postgres")
|
||||||
config.ConnConfig.Port = uint16(port)
|
config.ConnConfig.Port = uint16(port)
|
||||||
config.ConnConfig.Database = os.Getenv("POSTGRES_DB")
|
config.ConnConfig.Database = GetenvOr("POSTGRES_DB", "kyoo")
|
||||||
config.ConnConfig.User = os.Getenv("POSTGRES_USER")
|
config.ConnConfig.User = GetenvOr("POSTGRES_USER", "kyoo")
|
||||||
config.ConnConfig.Password = os.Getenv("POSTGRES_PASSWORD")
|
config.ConnConfig.Password = GetenvOr("POSTGRES_PASSWORD", "password")
|
||||||
config.ConnConfig.TLSConfig = nil
|
config.ConnConfig.TLSConfig = nil
|
||||||
config.ConnConfig.RuntimeParams = map[string]string{
|
config.ConnConfig.RuntimeParams = map[string]string{
|
||||||
"application_name": "keibi",
|
"application_name": "keibi",
|
||||||
}
|
}
|
||||||
schema := os.Getenv("POSTGRES_SCHEMA")
|
schema := GetenvOr("POSTGRES_SCHEMA", "keibi")
|
||||||
if schema == "" {
|
|
||||||
schema = "keibi"
|
|
||||||
}
|
|
||||||
if schema != "disabled" {
|
if schema != "disabled" {
|
||||||
config.ConnConfig.RuntimeParams["search_path"] = schema
|
config.ConnConfig.RuntimeParams["search_path"] = schema
|
||||||
}
|
}
|
||||||
@ -160,9 +169,11 @@ func main() {
|
|||||||
r := e.Group("")
|
r := e.Group("")
|
||||||
r.Use(echojwt.WithConfig(echojwt.Config{
|
r.Use(echojwt.WithConfig(echojwt.Config{
|
||||||
SigningMethod: "RS256",
|
SigningMethod: "RS256",
|
||||||
SigningKey: h.config.JwtPublicKey,
|
SigningKey: h.config.JwtPublicKey,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
e.GET("/health", h.CheckHealth)
|
||||||
|
|
||||||
r.GET("/users", h.ListUsers)
|
r.GET("/users", h.ListUsers)
|
||||||
r.GET("/users/:id", h.GetUser)
|
r.GET("/users/:id", h.GetUser)
|
||||||
r.GET("/users/me", h.GetMe)
|
r.GET("/users/me", h.GetMe)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
*** Settings ***
|
*** Settings ***
|
||||||
Documentation Common things to handle rest requests
|
Documentation Common things to handle rest requests
|
||||||
|
|
||||||
Library REST http://localhost:8901/auth
|
Library REST http://localhost:4568
|
||||||
|
|
||||||
|
|
||||||
*** Keywords ***
|
*** Keywords ***
|
||||||
|
Loading…
x
Reference in New Issue
Block a user