-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add minimal web ui, lkar: add setup command
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
- Loading branch information
Showing
114 changed files
with
15,446 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
tmp | ||
.env | ||
bin | ||
**/node_modules | ||
**/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,39 @@ | ||
IMAGE := "linkacloud/artifact-registry" | ||
MODULE = go.linka.cloud/artifact-registry | ||
|
||
install: docker-build | ||
PROJECT = artifact-registry | ||
REPOSITORY = linkacloud | ||
|
||
UI := $(PWD)/ui | ||
|
||
TAG = $(shell git describe --tags --exact-match 2> /dev/null) | ||
VERSION_SUFFIX = $(shell git diff --quiet || echo "-dev") | ||
VERSION = $(shell git describe --tags --exact-match 2> /dev/null || echo "`git describe --tags $$(git rev-list --tags --max-count=1) 2> /dev/null || echo v0.0.0`-`git rev-parse --short HEAD`")$(VERSION_SUFFIX) | ||
show-version: | ||
@echo $(VERSION) | ||
|
||
build-ui: | ||
@yarn --cwd $(UI) install | ||
@yarn --cwd $(UI) build | ||
|
||
install: build-ui | ||
@go generate ./... | ||
@go install -trimpath -ldflags "-s -w -X '$(MODULE).Version=$(VERSION)' -X '$(MODULE).BuildDate=$(shell date)'" ./cmd/artifact-registry | ||
@go install -trimpath -ldflags "-s -w -X '$(MODULE).Version=$(VERSION)' -X '$(MODULE).BuildDate=$(shell date)'" ./cmd/lkar | ||
|
||
DOCKER_BUILDX_ARGS := build --pull --load | ||
|
||
docker: docker-build docker-push | ||
|
||
.PHONY: docker-build | ||
docker-build: | ||
@docker build -t $(IMAGE) . | ||
@docker buildx $(DOCKER_BUILDX_ARGS) --pull -t $(REPOSITORY)/$(PROJECT):$(VERSION) . | ||
ifneq ($(TAG),) | ||
@docker image tag $(REPOSITORY)/$(PROJECT):$(VERSION) $(REPOSITORY)/$(PROJECT):latest | ||
endif | ||
|
||
.PHONY: docker-push | ||
docker-push: | ||
@docker push $(IMAGE) | ||
@docker image push $(REPOSITORY)/$(PROJECT):$(VERSION) | ||
ifneq ($(TAG),) | ||
@docker image push $(REPOSITORY)/$(PROJECT):latest | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// Copyright 2023 Linka Cloud All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"runtime" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"go.linka.cloud/artifact-registry/pkg/packages/apk" | ||
"go.linka.cloud/artifact-registry/pkg/packages/deb" | ||
"go.linka.cloud/artifact-registry/pkg/packages/rpm" | ||
) | ||
|
||
func newPkgSetupCmd(typ string) *cobra.Command { | ||
var ( | ||
force bool | ||
use string | ||
args int | ||
setup func(ctx context.Context, args []string) error | ||
) | ||
scheme := "https" | ||
if plainHTTP { | ||
scheme = "http" | ||
} | ||
var prefix string | ||
switch strings.Split(registry, ".")[0] { | ||
case "apk", "deb", "rpm": | ||
prefix = "/" | ||
default: | ||
prefix = "/" + typ + "/" | ||
} | ||
switch typ { | ||
case "apk": | ||
use = fmt.Sprintf("setup [repository] [branch] [apk-repository]") | ||
args = 3 | ||
setup = func(ctx context.Context, args []string) error { | ||
return apk.Setup(ctx, apk.SetupArgs{ | ||
User: user, | ||
Password: pass, | ||
Scheme: scheme, | ||
Host: registry, | ||
Path: prefix + repository, | ||
Branch: args[1], | ||
Repository: args[2], | ||
}, force) | ||
} | ||
case "deb": | ||
use = fmt.Sprintf("setup [repository] [distribution] [component]") | ||
args = 3 | ||
setup = func(ctx context.Context, args []string) error { | ||
return deb.Setup(ctx, deb.SetupArgs{ | ||
User: user, | ||
Password: pass, | ||
Scheme: scheme, | ||
Host: registry, | ||
Path: prefix + repository, | ||
Name: strings.Replace(repository, "/", "-", -1), | ||
Dist: args[1], | ||
Component: args[2], | ||
}, force) | ||
} | ||
case "rpm": | ||
use = fmt.Sprintf("setup [repository]") | ||
args = 1 | ||
setup = func(ctx context.Context, args []string) error { | ||
return rpm.Setup(ctx, rpm.SetupArgs{ | ||
User: user, | ||
Password: pass, | ||
Scheme: scheme, | ||
Host: registry, | ||
Path: prefix + repository, | ||
}, force) | ||
} | ||
} | ||
cmd := &cobra.Command{ | ||
Use: use, | ||
Short: fmt.Sprintf("Setup %s repository on the machine", typ), | ||
Args: cobra.ExactArgs(args), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := cmd.Context() | ||
if runtime.GOOS != "linux" { | ||
return fmt.Errorf("command only supported on Linux") | ||
} | ||
// Check if the user has root privileges | ||
if os.Geteuid() != 0 { | ||
return fmt.Errorf("please run as root or sudo") | ||
} | ||
return setup(ctx, args) | ||
}, | ||
} | ||
cmd.Flags().BoolVar(&force, "force", false, "Force setup") | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.