Skip to content

Commit

Permalink
✨ Support sort runners
Browse files Browse the repository at this point in the history
  • Loading branch information
tosone committed Oct 6, 2023
1 parent b5929bf commit b5a6389
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 24 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ jobs:
IP=`hostname -I | awk '{print $1}'`
echo '{"insecure-registries" : ["'$IP':3000"]}' | sudo tee /etc/docker/daemon.json
sudo service docker restart
echo $DOCKER_HOST
make docker-build
- name: Run sigma
run: |
docker run --name sigma -d -p 3000:3000 sigma:latest
docker run --name sigma -v /var/run/docker.sock:/var/run/docker.sock -d -p 3000:3000 sigma:latest
sleep 5
docker logs sigma
- name: Test push and e2e with k6
run: |
./e2e/push.sh
curl https://github.com/grafana/k6/releases/download/v0.45.0/k6-v0.45.0-linux-amd64.tar.gz -L | tar xvz --strip-components 1
curl https://github.com/grafana/k6/releases/download/v0.46.0/k6-v0.46.0-linux-amd64.tar.gz -L | tar xvz --strip-components 1
./k6 run e2e/sc.js
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Setup golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.53.2
version: v1.54.2
args: --deadline=10m --verbose
- name: Lint Dockerfile
uses: hadolint/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion build/Dockerfile.debian
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ COPY --from=web-builder /web/dist /go/src/github.com/go-sigma/sigma/web/dist

WORKDIR /go/src/github.com/go-sigma/sigma

RUN make build-release
RUN make build

FROM debian:${DEBIAN_VERSION}

Expand Down
7 changes: 4 additions & 3 deletions e2e/push.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

set +e
# set +e

TIMES=12
while [ $TIMES -gt 0 ]; do
Expand All @@ -13,11 +13,11 @@ while [ $TIMES -gt 0 ]; do
done

if [ $TIMES -eq 0 ]; then
echo "XImager cannot be available within one minute."
echo "sigma cannot be available within one minute."
exit 1
fi

set -e
# set -e

docker pull hello-world:latest
docker tag hello-world:latest 127.0.0.1:3000/library/hello-world:latest
Expand All @@ -30,3 +30,4 @@ docker push 127.0.0.1:3000/library/hello-world:latest
docker pull 127.0.0.1:3000/library/hello-world:latest
docker push 127.0.0.1:3000/library/mysql:8
docker pull 127.0.0.1:3000/library/mysql:8
docker logs -f sigma
4 changes: 2 additions & 2 deletions pkg/dal/dao/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ func (s builderService) ListRunners(ctx context.Context, id int64, pagination ty
case enums.SortMethodAsc:
query = query.Order(field)
default:
query = query.Order(s.tx.BuilderRunner.UpdatedAt.Desc())
query = query.Order(s.tx.BuilderRunner.CreatedAt.Desc())

Check warning on line 154 in pkg/dal/dao/builder.go

View check run for this annotation

Codecov / codecov/patch

pkg/dal/dao/builder.go#L154

Added line #L154 was not covered by tests
}
} else {
query = query.Order(s.tx.BuilderRunner.UpdatedAt.Desc())
query = query.Order(s.tx.BuilderRunner.CreatedAt.Desc())

Check warning on line 157 in pkg/dal/dao/builder.go

View check run for this annotation

Codecov / codecov/patch

pkg/dal/dao/builder.go#L157

Added line #L157 was not covered by tests
}
return query.FindByPage(ptr.To(pagination.Limit)*(ptr.To(pagination.Page)-1), ptr.To(pagination.Limit))
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/dal/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var mysqlFS embed.FS
var postgresqlFS embed.FS

//go:embed migrations/sqlite3/*.sql
var sqlite3FS embed.FS
var sqliteFS embed.FS

func migrateMysql(dsn string) error {
d, err := iofs.New(mysqlFS, "migrations/mysql")
Expand Down Expand Up @@ -79,7 +79,7 @@ func migratePostgres(dsn string) error {
}

func migrateSqlite(dsn string) error {
d, err := iofs.New(sqlite3FS, "migrations/sqlite3")
d, err := iofs.New(sqliteFS, "migrations/sqlite3")
if err != nil {
return err
}
Expand Down
16 changes: 9 additions & 7 deletions pkg/handlers/distribution/manifest/manifest_put.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,15 @@ func (h *handler) putManifestManifest(ctx context.Context, user *models.User, di
log.Error().Err(err).Str("tag", refs.Tag).Str("digest", refs.Digest.String()).Msg("Create tag failed")
return ptr.Of(xerrors.DSErrCodeUnknown)
}
err = workq.ProducerClient.Produce(ctx, enums.DaemonTagPushed.String(), types.DaemonTagPushedPayload{
RepositoryID: repositoryObj.ID,
Tag: refs.Tag,
})
if err != nil {
log.Error().Err(err).Str("tag", refs.Tag).Str("digest", refs.Digest.String()).Msg("Enqueue tag pushed task failed")
return ptr.Of(xerrors.DSErrCodeUnknown)
if workq.ProducerClient != nil { // TODO: init in test
err = workq.ProducerClient.Produce(ctx, enums.DaemonTagPushed.String(), types.DaemonTagPushedPayload{
RepositoryID: repositoryObj.ID,
Tag: refs.Tag,
})
if err != nil {
log.Error().Err(err).Str("tag", refs.Tag).Str("digest", refs.Digest.String()).Msg("Enqueue tag pushed task failed")
return ptr.Of(xerrors.DSErrCodeUnknown)
}

Check warning on line 221 in pkg/handlers/distribution/manifest/manifest_put.go

View check run for this annotation

Codecov / codecov/patch

pkg/handlers/distribution/manifest/manifest_put.go#L214-L221

Added lines #L214 - L221 were not covered by tests
}
}
return nil
Expand Down
21 changes: 20 additions & 1 deletion pkg/middlewares/redirect_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func RedirectRepository(config configs.Configuration) echo.MiddlewareFunc {
if !strings.Contains(strings.TrimPrefix(reqPath, "/"), "/") {
return next(c)
}
if c.Request().Method == http.MethodGet && !strings.HasPrefix(reqPath, "/api/v1/") && !strings.HasPrefix(reqPath, "/v2/") {
if !skipRedirect(c) {
namespace := strings.SplitN(strings.TrimPrefix(reqPath, "/"), "/", 2)[0]
repository := strings.TrimPrefix(reqPath, "/")
if strings.Contains(repository, ":") {
Expand All @@ -55,3 +55,22 @@ func RedirectRepository(config configs.Configuration) echo.MiddlewareFunc {
}
}
}

func skipRedirect(c echo.Context) bool {
if c.Request().Method != http.MethodGet {
return true
}
reqPath := c.Request().URL.Path
if strings.HasPrefix(reqPath, "/api/v1/") {
return true
}
if strings.HasPrefix(reqPath, "/v2/") {
return true
}
if strings.HasPrefix(reqPath, "/assets") && (strings.HasSuffix(reqPath, ".ttf") ||
strings.HasSuffix(reqPath, ".css") ||
strings.HasSuffix(reqPath, ".js")) {
return true
}
return false

Check warning on line 75 in pkg/middlewares/redirect_repository.go

View check run for this annotation

Codecov / codecov/patch

pkg/middlewares/redirect_repository.go#L59-L75

Added lines #L59 - L75 were not covered by tests
}
14 changes: 9 additions & 5 deletions web/src/pages/Builder/RunnerList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ export default function ({ localServer }: { localServer: string }) {
if (builderObj === undefined) {
return;
}
axios.get(localServer + `/api/v1/namespaces/${repositoryObj?.namespace_id}/repositories/${repository_id}/builders/${builderObj.id}/runners/?limit=${Settings.PageSize}&page=${page}`).then(response => {
let url = localServer + `/api/v1/namespaces/${repositoryObj?.namespace_id}/repositories/${repository_id}/builders/${builderObj.id}/runners/?limit=${Settings.PageSize}&page=${page}`
if (sortName !== "" && sortOrder !== IOrder.None) {
url += `&sort=${sortName}&method=${sortOrder.toString()}`
}
axios.get(url).then(response => {
if (response?.status === 200) {
const r = response.data as IBuilderRunnerList;
setRunnerObjs(r.items);
Expand All @@ -165,7 +169,7 @@ export default function ({ localServer }: { localServer: string }) {
const errorcode = error.response.data as IHTTPError;
Toast({ level: "warning", title: errorcode.title, message: errorcode.description });
});
}, [namespace, repository_id, builderObj, refreshState]);
}, [namespace, repository_id, builderObj, refreshState, sortOrder, sortName]);

return (
<>
Expand Down Expand Up @@ -277,12 +281,12 @@ export default function ({ localServer }: { localServer: string }) {
<span className="lg:pl-2">Status</span>
</th>
<th className="sticky top-0 z-10 px-6 py-3 border-gray-200 bg-gray-100 text-right text-xs font-medium text-gray-500 tracking-wider whitespace-nowrap">
<OrderHeader text={"Cost"}
<OrderHeader text={"Elapsed"}
orderStatus={costOrder} setOrder={e => {
resetOrder();
setCostOrder(e);
setSortOrder(e);
setSortName("cost");
setSortName("duration");
}} />
</th>
<th className="sticky top-0 z-10 px-6 py-3 border-gray-200 bg-gray-100 text-right text-xs font-medium text-gray-500 tracking-wider whitespace-nowrap">
Expand Down Expand Up @@ -543,7 +547,7 @@ function TableItem({ localServer, namespace, repositoryObj, runnerObj }: { local
{runnerObj.status}
</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500 text-right cursor-pointer">
{dayjs().to(dayjs(runnerObj.created_at))}
{runnerObj.duration || "-"}
</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500 text-right cursor-pointer">
{dayjs().to(dayjs(runnerObj.created_at))}
Expand Down

0 comments on commit b5a6389

Please sign in to comment.