diff --git a/.github/workflows/robot.yml b/.github/workflows/robot.yml deleted file mode 100644 index 5c11cab6..00000000 --- a/.github/workflows/robot.yml +++ /dev/null @@ -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 - diff --git a/.github/workflows/robot_auth.yml b/.github/workflows/robot_auth.yml new file mode 100644 index 00000000..e86d6196 --- /dev/null +++ b/.github/workflows/robot_auth.yml @@ -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 + diff --git a/auth/.env.example b/auth/.env.example index 012ba22f..76eae223 100644 --- a/auth/.env.example +++ b/auth/.env.example @@ -2,10 +2,10 @@ # shellcheck disable=SC2034 # Database things -POSTGRES_USER= -POSTGRES_PASSWORD= -POSTGRES_DB= -POSTGRES_SERVER= +POSTGRES_USER=kyoo +POSTGRES_PASSWORD=password +POSTGRES_DB=kyoo +POSTGRES_SERVER=postgres POSTGRES_PORT=5432 # 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 diff --git a/auth/Dockerfile b/auth/Dockerfile index 798b7db4..a5d02dc1 100644 --- a/auth/Dockerfile +++ b/auth/Dockerfile @@ -22,4 +22,5 @@ USER nonroot:nonroot COPY --from=build /keibi /app/keibi COPY sql ./sql + CMD ["/app/keibi"] diff --git a/auth/main.go b/auth/main.go index d0a1369b..45e10628 100644 --- a/auth/main.go +++ b/auth/main.go @@ -53,28 +53,37 @@ func (v *Validator) Validate(i interface{}) error { 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) { 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 { return nil, errors.New("invalid postgres port specified") } config, _ := pgxpool.ParseConfig("") - config.ConnConfig.Host = os.Getenv("POSTGRES_SERVER") + config.ConnConfig.Host = GetenvOr("POSTGRES_SERVER", "postgres") config.ConnConfig.Port = uint16(port) - config.ConnConfig.Database = os.Getenv("POSTGRES_DB") - config.ConnConfig.User = os.Getenv("POSTGRES_USER") - config.ConnConfig.Password = os.Getenv("POSTGRES_PASSWORD") + config.ConnConfig.Database = GetenvOr("POSTGRES_DB", "kyoo") + config.ConnConfig.User = GetenvOr("POSTGRES_USER", "kyoo") + config.ConnConfig.Password = GetenvOr("POSTGRES_PASSWORD", "password") config.ConnConfig.TLSConfig = nil config.ConnConfig.RuntimeParams = map[string]string{ "application_name": "keibi", } - schema := os.Getenv("POSTGRES_SCHEMA") - if schema == "" { - schema = "keibi" - } + schema := GetenvOr("POSTGRES_SCHEMA", "keibi") if schema != "disabled" { config.ConnConfig.RuntimeParams["search_path"] = schema } @@ -160,9 +169,11 @@ func main() { r := e.Group("") r.Use(echojwt.WithConfig(echojwt.Config{ SigningMethod: "RS256", - SigningKey: h.config.JwtPublicKey, + SigningKey: h.config.JwtPublicKey, })) + e.GET("/health", h.CheckHealth) + r.GET("/users", h.ListUsers) r.GET("/users/:id", h.GetUser) r.GET("/users/me", h.GetMe) diff --git a/auth/robot/auth.resource b/auth/robot/auth.resource index 51298261..2e469ecd 100644 --- a/auth/robot/auth.resource +++ b/auth/robot/auth.resource @@ -1,7 +1,7 @@ *** Settings *** Documentation Common things to handle rest requests -Library REST http://localhost:8901/auth +Library REST http://localhost:4568 *** Keywords ***