Skip to content
Open
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
10 changes: 10 additions & 0 deletions .github/workflows/cli-build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,15 @@ jobs:
- name: Release Dry-run
run: make release-local

test:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests now run even if the build fails, no dependency now. Do we want this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a dependency between build and tests? I wanted to speed up the CI tbh

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right, it should just run faster now as there Is no real dependency

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6

- name: Set up Go
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6
with:
go-version-file: 'go.mod'

- name: Test
run: make test
31 changes: 0 additions & 31 deletions .github/workflows/service-build_test.yml

This file was deleted.

3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ go.work.sum

# bin file
bin/
oms-cli
oms-service
oms
dist/
oms-workdir/

Expand Down
22 changes: 1 addition & 21 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,7 @@ builds:
- darwin_amd64
- windows_amd64
main: ./cli
binary: oms-cli
ldflags:
- -s -w
- -X github.com/codesphere-cloud/oms/internal/version.version={{.Version}}
- -X github.com/codesphere-cloud/oms/internal/version.commit={{.Commit}}
- -X github.com/codesphere-cloud/oms/internal/version.date={{.Date}}
- -X github.com/codesphere-cloud/oms/internal/version.os={{.Os}}
- -X github.com/codesphere-cloud/oms/internal/version.arch={{.Arch}}

- id: service
env:
- CGO_ENABLED=0
targets:
- linux_amd64
- linux_arm64
- darwin_arm64
- darwin_amd64
- windows_amd64

main: ./service
binary: oms-service
binary: oms
ldflags:
- -s -w
- -X github.com/codesphere-cloud/oms/internal/version.version={{.Version}}
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Run the generated `AddInstallComponent()` function in the parent `cli/cmd/instal
This will add the following command to the CLI:

```
oms-cli install component
oms install component
```

## Contributing Code
Expand Down
17 changes: 5 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
all: build-cli build-service
all: build-cli

build-cli:
cd cli && go build -v && mv cli ../oms-cli
cd cli && go build -v && mv cli ../oms

build-service:
cd service && go build -v && mv service ../oms-service

test:
go test -count=1 -v ./...
test: test-cli

test-cli:
# -count=1 to disable caching test results
Expand All @@ -17,9 +13,6 @@ test-integration:
# Run integration tests with build tag
go test -count=1 -v -tags=integration ./cli/...

test-service:
go test -count=1 -v ./service/...

format:
go fmt ./...

Expand All @@ -44,8 +37,8 @@ release-local: install-build-deps
docs:
rm -rf docs
mkdir docs
go run -ldflags="-X 'github.com/codesphere-cloud/oms/internal/version.binName=oms-cli'" hack/gendocs/main.go
cp docs/oms-cli.md docs/README.md
go run -ldflags="-X 'github.com/codesphere-cloud/oms/internal/version.binName=oms'" hack/gendocs/main.go
cp docs/oms.md docs/README.md

generate-license: generate
go tool go-licenses report --template .NOTICE.template ./... > NOTICE
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ Note that some commands may require you to elevate to the root user with `sudo`.
##### ARM Mac

```
gh release download -R codesphere-cloud/oms -O /usr/local/bin/oms-cli -p "oms-cli*darwin_arm64"
chmod +x /usr/local/bin/oms-cli
gh release download -R codesphere-cloud/oms -O /usr/local/bin/oms -p "oms*darwin_arm64"
chmod +x /usr/local/bin/oms
```

##### Linux Amd64

```
gh release download -R codesphere-cloud/oms -O /usr/local/bin/oms-cli -p "oms-cli*linux_amd64"
chmod +x /usr/local/bin/oms-cli
gh release download -R codesphere-cloud/oms -O /usr/local/bin/oms -p "oms*linux_amd64"
chmod +x /usr/local/bin/oms
```

#### Using `wget`
Expand All @@ -43,31 +43,31 @@ Note that some commands may require you to elevate to the root user with `sudo`.
##### ARM Mac

```
wget -qO- 'https://api.github.com/repos/codesphere-cloud/oms/releases/latest' | jq -r '.assets[] | select(.name | match("oms-cli.*darwin_arm64")) | .browser_download_url' | xargs wget -O oms-cli
mv oms-cli /usr/local/bin/oms-cli
chmod +x /usr/local/bin/oms-cli
wget -qO- 'https://api.github.com/repos/codesphere-cloud/oms/releases/latest' | jq -r '.assets[] | select(.name | match("oms.*darwin_arm64")) | .browser_download_url' | xargs wget -O oms
mv oms /usr/local/bin/oms
chmod +x /usr/local/bin/oms
```

##### Linux Amd64

```
wget -qO- 'https://api.github.com/repos/codesphere-cloud/oms/releases/latest' | jq -r '.assets[] | select(.name | match("oms-cli.*linux_amd64")) | .browser_download_url' | xargs wget -O oms-cli
mv oms-cli /usr/local/bin/oms-cli
chmod +x /usr/local/bin/oms-cli
wget -qO- 'https://api.github.com/repos/codesphere-cloud/oms/releases/latest' | jq -r '.assets[] | select(.name | match("oms.*linux_amd64")) | .browser_download_url' | xargs wget -O oms
mv oms /usr/local/bin/oms
chmod +x /usr/local/bin/oms
```

#### Manual Download

You can also download the pre-compiled binaries from the [OMS Releases page](https://github.com/codesphere-cloud/oms/releases).
Note that some commands may require you to elevate to the root user with `sudo`.

1. Go to the [latest release](https://github.com/codesphere-cloud/oms-cli/releases/latest).
1. Go to the [latest release](https://github.com/codesphere-cloud/oms/releases/latest).

2. Download the appropriate release for your operating system and architecture (e.g., `oms-cli_darwin_amd64` for macOS, `oms-cli_linux_amd64` for Linux, or `oms-cli_windows_amd64` for Windows).
2. Download the appropriate release for your operating system and architecture (e.g., `oms_darwin_amd64` for macOS, `oms_linux_amd64` for Linux, or `oms_windows_amd64` for Windows).

3. Move the `oms-cli` binary to a directory in your system's `PATH` (e.g., `/usr/local/bin` on Linux/Mac, or a directory added to `Path` environment variable on Windows).
3. Move the `oms` binary to a directory in your system's `PATH` (e.g., `/usr/local/bin` on Linux/Mac, or a directory added to `Path` environment variable on Windows).

4. Make the binary executable (e.g. by running `chmod +x /usr/local/bin/oms-cli` on Mac or Linux)
4. Make the binary executable (e.g. by running `chmod +x /usr/local/bin/oms` on Mac or Linux)

#### Available Commands

Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/api_key_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ var _ = Describe("API Key Integration Tests", func() {

Describe("Old API Key Detection and Warning", func() {
var (
cliPath = "../../oms-cli"
cliPath = "../../oms"
)

Context("when using a 25-character old API key format", func() {
Expand Down Expand Up @@ -310,7 +310,7 @@ var _ = Describe("API Key Integration Tests", func() {

Describe("PreRun Hook Execution", func() {
var (
cliPath = "../../oms-cli"
cliPath = "../../oms"
)

Context("when running any OMS command", func() {
Expand Down
33 changes: 15 additions & 18 deletions cli/cmd/bootstrap_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,40 +122,37 @@ func (c *BootstrapGcpCmd) BootstrapGcp() error {
}

err = bs.Bootstrap()
envBytes, err2 := json.MarshalIndent(bs.Env, "", " ")
envBytes, errMarshal := json.MarshalIndent(bs.Env, "", " ")

envString := string(envBytes)
if err2 != nil {
envString = ""
if errMarshal == nil {
workdir := env.NewEnv().GetOmsWorkdir()
err = fw.MkdirAll(workdir, 0755)
if err != nil {
log.Printf("warning: failed to create workdir: %v", err)
}
infraFilePath := gcp.GetInfraFilePath()
err = fw.WriteFile(infraFilePath, envBytes, 0644)
if err != nil {
log.Printf("warning: failed to write gcp bootstrap env file: %v", err)
}
log.Printf("Infrastructure details written to %s", infraFilePath)
}

if err != nil {
if bs.Env.Jumpbox != nil && bs.Env.Jumpbox.GetExternalIP() != "" {
log.Printf("To debug on the jumpbox host:\nssh-add $SSH_KEY_PATH; ssh -o StrictHostKeyChecking=no -o ForwardAgent=yes -o SendEnv=OMS_PORTAL_API_KEY root@%s", bs.Env.Jumpbox.GetExternalIP())
}
return fmt.Errorf("failed to bootstrap GCP: %w, env: %s", err, envString)
}

workdir := env.NewEnv().GetOmsWorkdir()
err = fw.MkdirAll(workdir, 0755)
if err != nil {
return fmt.Errorf("failed to create workdir: %w", err)
}
infraFilePath := gcp.GetInfraFilePath()
err = fw.WriteFile(infraFilePath, envBytes, 0644)
if err != nil {
return fmt.Errorf("failed to write gcp bootstrap env file: %w", err)
return fmt.Errorf("failed to bootstrap GCP: %w", err)
}

log.Println("\n🎉🎉🎉 GCP infrastructure bootstrapped successfully!")
log.Printf("Infrastructure details written to %s", infraFilePath)
log.Printf("Access the jumpbox using:\nssh-add $SSH_KEY_PATH; ssh -o StrictHostKeyChecking=no -o ForwardAgent=yes -o SendEnv=OMS_PORTAL_API_KEY root@%s", bs.Env.Jumpbox.GetExternalIP())
if bs.Env.InstallVersion != "" {
log.Printf("Access Codesphere in your web browser at https://cs.%s", bs.Env.BaseDomain)
return nil
}
packageName := "<package-name>-installer"
installCmd := "oms-cli install codesphere -c /etc/codesphere/config.yaml -k /etc/codesphere/secrets/age_key.txt"
installCmd := "oms install codesphere -c /etc/codesphere/config.yaml -k /etc/codesphere/secrets/age_key.txt"
if gcp.RegistryType(bs.Env.RegistryType) == gcp.RegistryTypeGitHub {
log.Printf("You set a GitHub PAT for direct image access. Make sure to use a lite package, as VM root disk sizes are reduced.")
installCmd += " -s load-container-images"
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/build_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ func AddBuildImageCmd(parentCmd *cobra.Command, opts *GlobalOptions) {
Use: "image",
Short: "Build and push Docker image using Dockerfile and Codesphere package version",
Long: `Build a Docker image from a Dockerfile and push it to a registry, tagged with the Codesphere version from the package.`,
Example: formatExamplesWithBinary("build image", []io.Example{
Example: formatExamples("build image", []io.Example{
{Cmd: "--dockerfile baseimage/Dockerfile --package codesphere-v1.68.0.tar.gz --registry my-registry.com/my-image", Desc: "Build image for Codesphere version 1.68.0 and push to specified registry"},
}, "oms-cli"),
}),
Args: cobra.ExactArgs(0),
},
Opts: BuildImageOpts{GlobalOptions: opts},
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/download_k0s.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ func AddDownloadK0sCmd(download *cobra.Command, opts *GlobalOptions) {
Short: "Download k0s Kubernetes distribution",
Long: packageio.Long(`Download a k0s binary directly to the OMS workdir.
Will download the latest version if no version is specified.`),
Example: formatExamplesWithBinary("download k0s", []packageio.Example{
Example: formatExamples("download k0s", []packageio.Example{
{Cmd: "", Desc: "Download k0s using the Go-native implementation"},
{Cmd: "--version 1.22.0", Desc: "Download a specific version of k0s"},
{Cmd: "--quiet", Desc: "Download k0s with minimal output"},
{Cmd: "--force", Desc: "Force download even if k0s binary exists"},
}, "oms-cli"),
}),
},
Opts: DownloadK0sOpts{GlobalOptions: opts},
Env: env.NewEnv(),
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/download_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ func AddDownloadPackageCmd(download *cobra.Command, opts *GlobalOptions) {
Short: "Download a codesphere package",
Long: io.Long(`Download a specific version of a Codesphere package
To list available packages, run oms list packages.`),
Example: formatExamplesWithBinary("download package", []io.Example{
Example: formatExamples("download package", []io.Example{
{Cmd: "codesphere-v1.55.0", Desc: "Download Codesphere version 1.55.0"},
{Cmd: "--version codesphere-v1.55.0", Desc: "Download Codesphere version 1.55.0"},
{Cmd: "--version codesphere-v1.55.0 --file installer-lite.tar.gz", Desc: "Download lite package of Codesphere version 1.55.0"},
}, "oms-cli"),
}),
PreRunE: func(cmd *cobra.Command, args []string) error {
// if version flag is not set, expect version as argument
cmd.Args = cobra.NoArgs
Expand Down
10 changes: 6 additions & 4 deletions cli/cmd/example_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
"strings"

"github.com/codesphere-cloud/cs-go/pkg/io"
"github.com/codesphere-cloud/oms/internal/version"
)

// formatExamplesWithBinary builds an Example string similar to io.FormatExampleCommands
// but prefixes commands with a stable binary name (e.g. "oms-cli") instead of temporary go-build paths
func formatExamplesWithBinary(cmdName string, examples []io.Example, binaryName string) string {
// formatExamples builds an Example string similar to io.FormatExampleCommands
// it prefixes commands with a stable binary name (e.g. "oms") instead of temporary go-build paths
func formatExamples(cmdName string, examples []io.Example) string {
var b strings.Builder
for i, ex := range examples {
if ex.Desc != "" {
Expand All @@ -20,7 +21,8 @@ func formatExamplesWithBinary(cmdName string, examples []io.Example, binaryName
b.WriteString("\n")
}
b.WriteString("$ ")
b.WriteString(binaryName)
build := version.Build{}
b.WriteString(build.BinName())
b.WriteString(" ")
b.WriteString(cmdName)
if ex.Cmd != "" {
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/init_install_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ func AddInitInstallConfigCmd(init *cobra.Command, opts *GlobalOptions) {
- dev: Single-node development setup
- production: HA multi-node setup
- minimal: Minimal testing setup`),
Example: formatExamplesWithBinary("init install-config", []csio.Example{
Example: formatExamples("init install-config", []csio.Example{
{Cmd: "-c config.yaml --vault prod.vault.yaml", Desc: "Create config files interactively"},
{Cmd: "--profile dev -c config.yaml --vault prod.vault.yaml", Desc: "Use dev profile with defaults"},
{Cmd: "--profile production -c config.yaml --vault prod.vault.yaml", Desc: "Use production profile"},
{Cmd: "--validate -c config.yaml --vault prod.vault.yaml", Desc: "Validate existing configuration files"},
}, "oms-cli"),
}),
},
Opts: &InitInstallConfigOpts{GlobalOptions: opts},
FileWriter: util.NewFilesystemWriter(),
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/install_k0s.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ func AddInstallK0sCmd(install *cobra.Command, opts *GlobalOptions) {
or load the k0s binary from the provided package file and install it.
If no version is specified, the latest version will be downloaded.
If no install config is provided, k0s will be installed with the '--single' flag.`),
Example: formatExamplesWithBinary("install k0s", []packageio.Example{
Example: formatExamples("install k0s", []packageio.Example{
{Cmd: "", Desc: "Install k0s using the Go-native implementation"},
{Cmd: "--version <version>", Desc: "Version of k0s to install"},
{Cmd: "--package <file>", Desc: "Package file (e.g. codesphere-v1.2.3-installer.tar.gz) to load k0s from"},
{Cmd: "--k0s-config <path>", Desc: "Path to k0s configuration file, if not set k0s will be installed with the '--single' flag"},
{Cmd: "--force", Desc: "Force new download and installation even if k0s binary exists or is already installed"},
}, "oms-cli"),
}),
},
Opts: InstallK0sOpts{GlobalOptions: opts},
Env: env.NewEnv(),
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/smoketest_codesphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func AddSmoketestCodesphereCmd(parent *cobra.Command, opts *GlobalOptions) {
Long: io.Long(`Run automated smoke tests for a Codesphere installation by creating a workspace,
setting environment variables, executing commands, syncing landscape, and running a pipeline stage.
The workspace is automatically deleted after the test completes.`),
Example: formatExamplesWithBinary("smoketest codesphere", []io.Example{
Example: formatExamples("smoketest codesphere", []io.Example{
{
Cmd: "--baseurl https://codesphere.example.com/api --token YOUR_TOKEN --team-id TEAM_ID --plan-id PLAN_ID",
Desc: "Run smoke tests against a Codesphere installation",
Expand All @@ -84,7 +84,7 @@ func AddSmoketestCodesphereCmd(parent *cobra.Command, opts *GlobalOptions) {
Cmd: "--baseurl https://codesphere.example.com/api --token YOUR_TOKEN --team-id TEAM_ID --plan-id PLAN_ID --steps createWorkspace,syncLandscape,deleteWorkspace",
Desc: "Run specific steps and delete the workspace afterwards",
},
}, "oms-cli"),
}),
},
Opts: &teststeps.SmoketestCodesphereOpts{},
}
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/update_dockerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ func AddUpdateDockerfileCmd(parentCmd *cobra.Command, opts *GlobalOptions) {

This command extracts the base image from a Codesphere package and updates the FROM statement
in the specified Dockerfile to use that base image. The base image is loaded into the local Docker daemon so it can be used for building.`,
Example: formatExamplesWithBinary("update dockerfile", []io.Example{
Example: formatExamples("update dockerfile", []io.Example{
{Cmd: "--dockerfile baseimage/Dockerfile --package codesphere-v1.68.0.tar.gz", Desc: "Update Dockerfile to use the default base image from the package (workspace-agent-24.04)"},
{Cmd: "--dockerfile baseimage/Dockerfile --package codesphere-v1.68.0.tar.gz --baseimage workspace-agent-20.04.tar", Desc: "Update Dockerfile to use the workspace-agent-20.04 base image from the package"},
}, "oms-cli"),
}),
Args: cobra.ExactArgs(0),
},
Opts: UpdateDockerfileOpts{GlobalOptions: opts},
Expand Down
Loading