Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(admin): add admin page containing a workers table #707

Closed
wants to merge 9 commits into from
Closed
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
66 changes: 61 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ services:
# https://go-vela.github.io/docs/administration/server/
server:
container_name: server
image: target/vela-server:latest
image: server:local
networks:
- vela
environment:
Expand Down Expand Up @@ -79,8 +79,8 @@ services:
# queue and executing them based off their configuration.
#
# https://go-vela.github.io/docs/administration/worker/
worker:
container_name: worker
worker_1:
container_name: worker_1
image: target/vela-worker:latest
networks:
- vela
Expand All @@ -89,15 +89,15 @@ services:
QUEUE_DRIVER: redis
QUEUE_ADDR: 'redis://redis:6379'
QUEUE_PUBLIC_KEY: 'DXsJkoTSkHlG26d75LyHJG+KQsXPr8VKPpmH/78zmko='
VELA_BUILD_LIMIT: 1
VELA_BUILD_LIMIT: 3
VELA_BUILD_TIMEOUT: 30m
VELA_LOG_LEVEL: trace
VELA_RUNTIME_DRIVER: docker
VELA_RUNTIME_PRIVILEGED_IMAGES: 'target/vela-docker'
VELA_SERVER_ADDR: 'http://server:8080'
# comment the line below to use registration flow
VELA_SERVER_SECRET: 'zB7mrKDTZqNeNTD8z47yG4DHywspAh'
WORKER_ADDR: 'http://worker:8080'
WORKER_ADDR: 'http://worker_1:8080'
WORKER_CHECK_IN: 5m
restart: always
ports:
Expand All @@ -107,6 +107,62 @@ services:
depends_on:
- server

worker_2:
container_name: worker_2
image: target/vela-worker:latest
networks:
- vela
environment:
EXECUTOR_DRIVER: linux
QUEUE_DRIVER: redis
QUEUE_ADDR: 'redis://redis:6379'
QUEUE_PUBLIC_KEY: 'DXsJkoTSkHlG26d75LyHJG+KQsXPr8VKPpmH/78zmko='
VELA_BUILD_LIMIT: 5
VELA_BUILD_TIMEOUT: 30m
VELA_LOG_LEVEL: trace
VELA_RUNTIME_DRIVER: docker
VELA_RUNTIME_PRIVILEGED_IMAGES: 'target/vela-docker'
VELA_SERVER_ADDR: 'http://server:8080'
# comment the line below to use registration flow
VELA_SERVER_SECRET: 'zB7mrKDTZqNeNTD8z47yG4DHywspAh'
WORKER_ADDR: 'http://worker_2:8081'
WORKER_CHECK_IN: 5m
restart: always
ports:
- '8082:8081'
volumes:
- '/var/run/docker.sock:/var/run/docker.sock'
depends_on:
- server

worker_3:
container_name: worker_3
image: target/vela-worker:latest
networks:
- vela
environment:
EXECUTOR_DRIVER: linux
QUEUE_DRIVER: redis
QUEUE_ADDR: 'redis://redis:6379'
QUEUE_PUBLIC_KEY: 'DXsJkoTSkHlG26d75LyHJG+KQsXPr8VKPpmH/78zmko='
VELA_BUILD_LIMIT: 1
VELA_BUILD_TIMEOUT: 30m
VELA_LOG_LEVEL: trace
VELA_RUNTIME_DRIVER: docker
VELA_RUNTIME_PRIVILEGED_IMAGES: 'target/vela-docker'
VELA_SERVER_ADDR: 'http://server:8080'
# comment the line below to use registration flow
VELA_SERVER_SECRET: 'zB7mrKDTZqNeNTD8z47yG4DHywspAh'
WORKER_ADDR: 'http://worker_3:8082'
WORKER_CHECK_IN: 5m
restart: always
ports:
- '8083:8082'
volumes:
- '/var/run/docker.sock:/var/run/docker.sock'
depends_on:
- server

# The `redis` compose service hosts the Redis database.
#
# This component is used for publishing builds to a FIFO queue.
Expand Down
12 changes: 12 additions & 0 deletions src/elm/Api.elm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module Api exposing
, getSourceRepositories
, getStepLogs
, getToken
, getWorkers
, redeliverHook
, repairRepo
, restartBuild
Expand Down Expand Up @@ -93,6 +94,7 @@ import Vela
, StepNumber
, Templates
, Type
, Worker
, decodeBuild
, decodeBuilds
, decodeCurrentUser
Expand All @@ -112,6 +114,8 @@ import Vela
, decodeService
, decodeSourceRepositories
, decodeStep
, decodeWorker
, decodeWorkers
)


Expand Down Expand Up @@ -751,3 +755,11 @@ deleteSchedule : PartialModel a -> Org -> Repo -> ScheduleName -> Request String
deleteSchedule model org repo id =
delete model.velaAPI (Endpoint.Schedule org repo (Just id) Nothing Nothing) Json.Decode.string
|> withAuth model.session


{-| getWorkers : fetches workers for admin page
-}
getWorkers : PartialModel a -> Request (List Worker)
getWorkers model =
get model.velaAPI Endpoint.Workers decodeWorkers
|> withAuth model.session
4 changes: 4 additions & 0 deletions src/elm/Api/Endpoint.elm
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type Endpoint
| PipelineConfig Org Repo Ref
| ExpandPipelineConfig Org Repo Ref
| PipelineTemplates Org Repo Ref
| Workers


{-| toUrl : turns and Endpoint into a URL string
Expand Down Expand Up @@ -169,6 +170,9 @@ toUrl api endpoint =
Deployments maybePage maybePerPage org repo ->
url api [ "deployments", org, repo ] <| Pagination.toQueryParams maybePage maybePerPage

Workers ->
url api [ "workers" ] <| [ UB.string "links" "true" ]


{-| url : creates a URL string with the given path segments and query parameters
-}
Expand Down
3 changes: 3 additions & 0 deletions src/elm/Crumbs.elm
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ toPath page =
in
[ overviewCrumbLink, settingsCrumbStatic ]

Pages.Admin ->
[]

Pages.NotFound ->
let
notFoundCrumbStatic =
Expand Down
9 changes: 9 additions & 0 deletions src/elm/Help/Commands.elm
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ commands page =
Pages.Settings ->
[]

Pages.Admin ->
[]

Pages.Login ->
[ authenticate ]

Expand Down Expand Up @@ -938,6 +941,9 @@ resourceLoaded args =
Pages.Settings ->
True

Pages.Admin ->
True

Pages.Login ->
True

Expand Down Expand Up @@ -1034,6 +1040,9 @@ resourceLoading args =
Pages.Settings ->
False

Pages.Admin ->
False

Pages.Login ->
False

Expand Down
47 changes: 46 additions & 1 deletion src/elm/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import Maybe.Extra exposing (unwrap)
import Nav exposing (viewUtil)
import Pager
import Pages exposing (Page)
import Pages.Admin
import Pages.Build.Logs
exposing
( addLog
Expand Down Expand Up @@ -173,6 +174,8 @@ import Vela
, Type
, UpdateRepositoryPayload
, UpdateUserPayload
, Worker
, WorkerModel
, buildUpdateFavoritesPayload
, buildUpdateRepoBoolPayload
, buildUpdateRepoIntPayload
Expand All @@ -183,6 +186,7 @@ import Vela
, defaultPipeline
, defaultPipelineTemplates
, defaultRepoModel
, defaultWorkerModel
, encodeEnableRepository
, encodeTheme
, encodeUpdateRepository
Expand Down Expand Up @@ -283,6 +287,7 @@ type alias Model =
, pipeline : PipelineModel
, templates : PipelineTemplates
, buildMenuOpen : List Int
, workers : WorkerModel
}


Expand Down Expand Up @@ -338,6 +343,7 @@ init flags url navKey =
, deploymentModel = initDeploymentsModel
, pipeline = defaultPipeline
, templates = defaultPipelineTemplates
, workers = defaultWorkerModel
}

( newModel, newPage ) =
Expand Down Expand Up @@ -429,6 +435,7 @@ type Msg
| ExpandPipelineConfig Org Repo BuildNumber Ref FocusFragment Bool
-- Inbound HTTP responses
| LogoutResponse (Result (Http.Detailed.Error String) ( Http.Metadata, String ))
| WorkersResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Worker ))
| TokenResponse (Result (Http.Detailed.Error String) ( Http.Metadata, JwtAccessToken ))
| CurrentUserResponse (Result (Http.Detailed.Error String) ( Http.Metadata, CurrentUser ))
| SourceRepositoriesResponse (Result (Http.Detailed.Error String) ( Http.Metadata, SourceRepositories ))
Expand Down Expand Up @@ -498,6 +505,9 @@ update msg model =
rm =
model.repo

wm =
model.workers

sm =
model.schedulesModel

Expand Down Expand Up @@ -1409,6 +1419,14 @@ update msg model =
Err error ->
( { model | repo = updateRepo (toFailure error) rm }, addError error )

WorkersResponse response ->
case response of
Ok ( _, workerResponse ) ->
( { model | workers = { wm | workers = RemoteData.succeed workerResponse } }, Cmd.none )

Err error ->
( model, addError error )

OrgRepositoriesResponse response ->
case response of
Ok ( meta, repoResponse ) ->
Expand Down Expand Up @@ -2331,7 +2349,14 @@ refreshPage model =
getRepoSecrets model maybePage maybePerPage engine org repo

Pages.SharedSecrets engine org team maybePage maybePerPage ->
getSharedSecrets model maybePage maybePerPage engine org team
Cmd.batch
[ getSharedSecrets model maybePage maybePerPage engine org team
]

Pages.Admin ->
Cmd.batch
[ getWorkers model
]

_ ->
Cmd.none
Expand Down Expand Up @@ -2885,6 +2910,16 @@ viewContent model =
, Pages.Settings.view model.session model.time (Pages.Settings.Msgs Copy)
)

Pages.Admin ->
( "Admin"
, div []
[ Pages.Admin.view
{ workers = model.workers
, time = model.time
}
]
)

Pages.Login ->
( "Login"
, viewLogin
Expand Down Expand Up @@ -3007,6 +3042,8 @@ viewHeader session { feedbackLink, docsLink, theme, help, showId } =
, ul [ class "identity-menu", attribute "aria-hidden" "true", attribute "role" "menu" ]
[ li [ class "identity-menu-item" ]
[ a [ Routes.href Routes.Settings, Util.testAttribute "settings-link", attribute "role" "menuitem" ] [ text "Settings" ] ]
, li [ class "identity-menu-item" ]
[ a [ Routes.href Routes.Admin, Util.testAttribute "admin-link", attribute "role" "menuitem" ] [ text "Admin Page" ] ]
, li [ class "identity-menu-item" ]
[ a [ Routes.href Routes.Logout, Util.testAttribute "logout-link", attribute "role" "menuitem" ] [ text "Logout" ] ]
]
Expand Down Expand Up @@ -3192,6 +3229,9 @@ setNewPage route model =
( Routes.Settings, Authenticated _ ) ->
( { model | page = Pages.Settings, showIdentity = False }, Cmd.none )

( Routes.Admin, Authenticated _ ) ->
( { model | page = Pages.Admin, showIdentity = False }, getWorkers model )

( Routes.Logout, Authenticated _ ) ->
( model, getLogout model )

Expand Down Expand Up @@ -4575,6 +4615,11 @@ getLogout model =
Api.try LogoutResponse <| Api.getLogout model


getWorkers : Model -> Cmd Msg
getWorkers model =
Api.try WorkersResponse <| Api.getWorkers model


getCurrentUser : Model -> Cmd Msg
getCurrentUser model =
case model.user of
Expand Down
6 changes: 6 additions & 0 deletions src/elm/Nav.elm
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ navButtons model { fetchSourceRepos, toggleFavorite, restartBuild, cancelBuild }
Pages.Login ->
text ""

Pages.Admin ->
text ""

Pages.NotFound ->
text ""

Expand Down Expand Up @@ -320,6 +323,9 @@ viewUtil model =
Pages.Login ->
text ""

Pages.Admin ->
text ""

Pages.NotFound ->
text ""
]
Expand Down
7 changes: 7 additions & 0 deletions src/elm/Pages.elm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Page
| AddSchedule Org Repo
| Schedule Org Repo ScheduleName
| Schedules Org Repo (Maybe Pagination.Page) (Maybe Pagination.PerPage)
| Admin
| Settings
| Login
| NotFound
Expand Down Expand Up @@ -137,6 +138,9 @@ toRoute page =
Settings ->
Routes.Settings

Admin ->
Routes.Admin

Login ->
Routes.Login

Expand Down Expand Up @@ -233,6 +237,9 @@ strip page =
Settings ->
Settings

Admin ->
Admin

Login ->
Login

Expand Down
Loading
Loading