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

Add Quickstart #60

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Add Quickstart #60

wants to merge 4 commits into from

Conversation

bupd
Copy link
Collaborator

@bupd bupd commented Nov 4, 2024

Fixes: #43

This PR focuses on creating a quickstart guide on how to setup ground-control and satellite in local dev environments.
and simplifies the setup with dagger by creating local dev servers.

Currently, there is a known limitation in dagger with which we can't have live reloading of the dev server.
Dagger Limitation: dagger/dagger#6990
When the above Limitation gets resolved we can have the live reloading in dagger.

Note

We need to rerun dagger call build-dev --component ground-control up to reflect the changes in the dev server.

Summary by CodeRabbit

  • New Features

    • Introduced configuration settings for the Air tool to enhance live reloading capabilities in Go applications.
    • Added a new method to start a development server for specified components in the Harbor Satellite project.
  • Documentation

    • Updated QUICKSTART.md with a comprehensive guide for setting up Harbor Satellite locally.
    • Enhanced README.md for clarity, including a new "QuickStart" section and corrections for typographical errors.
  • Bug Fixes

    • Corrected typographical errors related to "registry" throughout documentation.
  • Chores

    • Updated dependencies and Go version in go.mod for improved performance and compatibility.
    • Modified environment variable configurations in .env for the ground-control project.

- This adds development server for ground control
- This commit only focuses on setting the dev server for ground-control
- Dagger has a known limitation for hot reloading dev servers.
- limitation issue in dagger
(dagger/dagger#6990)

Signed-off-by: bupd <[email protected]>
Copy link

coderabbitai bot commented Nov 4, 2024

Walkthrough

The changes introduce configuration files for the Air tool to facilitate live reloading in Go applications and enhance documentation for setting up the Harbor Satellite project. A new method BuildDev is added to the HarborSatellite struct for starting a development server. Documentation updates include a new QuickStart section in the README.md and QUICKSTART.md, providing step-by-step instructions for local setup, alongside typographical corrections and improved clarity in existing sections.

Changes

File Change Summary
.air.toml New configuration file added for Air tool with [build] and [log] sections, specifying build parameters and logging level.
ground-control/.air.toml New configuration file added for Air tool with [build] and [log] sections, similar to .air.toml.
QUICKSTART.md New section added for local setup instructions of Harbor Satellite, detailing prerequisites and setup steps.
README.md New QuickStart section added, corrections made to typographical errors, and rephrased descriptions in the "Specific Use Cases" section.
ci/main.go New method BuildDev added to HarborSatellite struct for starting a development server for "satellite" and "ground-control" components.
dagger.json Engine version updated from v0.13.3 to v0.14.0.
go.mod Go version updated from 1.22.3 to 1.22.5, with several dependency updates and additions.
ground-control/.env DB_HOST variable updated from localhost to pgservice.

Assessment against linked issues

Objective Addressed Explanation
Getting Started Guide (#43)
Provide instructions for starting GC and Satellite (#43)

Possibly related PRs

Suggested reviewers

  • Vad1mo

Poem

In the burrow where we play,
New tools for a brighter day,
QuickStart guides to lead the way,
With Air and Go, we hop and sway!
A binary bright, all set to run,
Let's build and code, oh what fun! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added documentation Improvements or additions to documentation golang labels Nov 4, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 8

🧹 Outside diff range and nitpick comments (10)
.air.toml (2)

12-13: Consider environment-specific logging configuration.

The current logging configuration is set to "debug" level, which might not be suitable for all environments. Additionally, the logging configuration could benefit from more development-friendly options.

Consider enhancing the logging configuration:

[log]
-  level = "debug"
+  # Use environment variable to control log level
+  level = "${AIR_LOG_LEVEL}"
+  # Add development-friendly logging options
+  time = true
+  main_only = false

You can set the environment variable in your development environment:

export AIR_LOG_LEVEL=debug

1-13: Document Air configuration in quickstart guide.

Since this configuration is crucial for the development setup and works around the Dagger live reload limitation mentioned in the PR objectives, please ensure that:

  1. The .air.toml configuration is explained in the quickstart guide
  2. The relationship between Air and Dagger is clearly documented
  3. Any environment variables or setup requirements are listed

Would you like me to help draft the documentation section for this configuration?

ground-control/.air.toml (1)

12-13: Consider environment-specific logging configuration

The debug log level is fine for development but might generate excessive output. Consider adding a comment to explain this or implementing environment-specific configurations.

Add a comment explaining the log level choice:

[log]
+  # Debug level is used for development environment
+  # Consider using "info" for production deployments
  level = "debug"
QUICKSTART.md (2)

5-10: Enhance prerequisites section with specific requirements.

The prerequisites section should include:

  • Minimum Dagger version number
  • Supported operating systems
  • System requirements (disk space, memory)

1-100: Overall document structure is good, but needs additional sections.

Consider adding these important sections:

  1. Version compatibility matrix
  2. Backup and recovery procedures
  3. Common errors and solutions
  4. Security best practices
  5. Resource cleanup instructions
ci/main.go (3)

23-30: Enhance method documentation for better clarity.

The current documentation lacks essential details. Consider adding:

  • Parameter descriptions (especially the optional source)
  • Return value documentation
  • Usage examples
  • Prerequisites (Air tool requirement)
  • Limitations (no live reload support, as mentioned in PR description)
-// build-dev function would start the dev server for the component provided.
+// BuildDev starts a development server for the specified component using the Air tool for live reloading.
+//
+// Parameters:
+//   - ctx: Context for cancellation and timeout
+//   - source: Optional directory containing the source code (defaults to "./ground-control")
+//   - component: Component to run ("satellite" or "ground-control")
+//
+// Returns:
+//   - *dagger.Service: Service handle for the running development server
+//   - error: Any error encountered during setup
+//
+// Note: Currently, live reloading requires manual restart due to Dagger limitations.
+// See: https://github.com/dagger/dagger/issues/XXX
+//
+// Example:
+//   service, err := harbor.BuildDev(ctx, dag.Host().Directory("./"), "ground-control")

51-52: Track TODO item for satellite implementation.

The TODO comment should be tracked properly to ensure it's not forgotten.

Would you like me to create a GitHub issue to track the satellite implementation task?


56-57: Enhance error message for better user guidance.

The error message could be more informative by including usage examples.

-	return nil, fmt.Errorf("error: please provide component as either satellite or ground-control")
+	return nil, fmt.Errorf("invalid component %q: must be either 'satellite' or 'ground-control'", component)
README.md (2)

57-60: Improve clarity and consistency in use case descriptions.

Several style and grammar improvements are needed:

  1. Add missing commas after introductory phrases
  2. Use "number of" instead of "amount of" when referring to countable items
  3. Maintain consistent spelling between "containerised" and "containerized"

Consider these improvements:

-The stateless satellite component will handle pulling images
+The stateless satellite component will handle pulling images,

-amount of demands
+number of demands

-containerised
+containerized

Also applies to: 68-72

🧰 Tools
🪛 LanguageTool

[uncategorized] ~58-~58: Possible missing comma found.
Context: ... then be accessible to other local edge devices who can pull required images directly f...

(AI_HYDRA_LEO_MISSING_COMMA)


[grammar] ~59-~59: Uncountable nouns are usually not used with an indefinite article. Use simply “direct access”.
Context: ...ull required images directly from it. _(A direct access from edge device to the remote registry...

(A_UNCOUNTABLE)


77-79: Consider formatting improvements for consistency.

The use case descriptions would benefit from consistent formatting:

  1. Use consistent punctuation at the end of list items
  2. Maintain consistent paragraph spacing between sections

Would you like me to provide specific formatting suggestions for these sections?

🧰 Tools
🪛 LanguageTool

[style] ~78-~78: Consider using more formal and concise wording here.
Context: ... The stateless satellite component will be in charge of configuring the local OCI compliant reg...

(RESPONSIBLE_FOR)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 20f6be7 and 9dcfc66.

📒 Files selected for processing (5)
  • .air.toml (1 hunks)
  • QUICKSTART.md (1 hunks)
  • README.md (2 hunks)
  • ci/main.go (1 hunks)
  • ground-control/.air.toml (1 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md

[typographical] ~17-~17: Consider adding a comma here.
Context: ...decentralized registries. ## QuickStart Please refer to the latest setup instructions ...

(PLEASE_COMMA)


[uncategorized] ~58-~58: Possible missing comma found.
Context: ... then be accessible to other local edge devices who can pull required images directly f...

(AI_HYDRA_LEO_MISSING_COMMA)


[grammar] ~59-~59: Uncountable nouns are usually not used with an indefinite article. Use simply “direct access”.
Context: ...ull required images directly from it. _(A direct access from edge device to the remote registry...

(A_UNCOUNTABLE)


[uncategorized] ~63-~63: Do not mix variants of the same word (‘containerise’ and ‘containerize’) within a single text.
Context: ...onnnectivity, these devices need to run containerised images but cannot pull from a central H...

(EN_WORD_COHERENCY)


[uncategorized] ~63-~63: It appears that hyphens are missing in the adjective “up-to-date”.
Context: ... central Harbor registry and thus store up to date images locally._ ![Use Case #1](docs/i...

(UP_TO_DATE_HYPHEN)


[uncategorized] ~72-~72: Do not mix variants of the same word (‘containerise’ and ‘containerize’) within a single text.
Context: ...nt amount of IoT devices needing to run containerised applications, a single local registry i...

(EN_WORD_COHERENCY)


[uncategorized] ~72-~72: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ...ght not be able to handle the increased amount of demands from edge devices. The solut...

(AMOUNTOF_TO_NUMBEROF)


[uncategorized] ~72-~72: Possible missing comma found.
Context: ...to deploy several registries to several nodes who are able to automatically replicate...

(AI_HYDRA_LEO_MISSING_COMMA)


[style] ~72-~72: As a shorter alternative for ‘able to’, consider using “can”.
Context: ...several registries to several nodes who are able to automatically replicate images across e...

(BE_ABLE_TO)


[style] ~78-~78: Consider using more formal and concise wording here.
Context: ... The stateless satellite component will be in charge of configuring the local OCI compliant reg...

(RESPONSIBLE_FOR)

🔇 Additional comments (3)
.air.toml (1)

1-10: 🛠️ Refactor suggestion

Enhance build configuration security and specificity.

The current build configuration has several areas that could be improved for better security and maintainability:

  1. The binary name "main" is too generic and could conflict with other tools in the PATH
  2. The build directory "." is ambiguous and could lead to wrong builds if the command is executed from a subdirectory
  3. The run_after_build command could affect wrong files if a "main" binary exists elsewhere

Consider applying these improvements:

[build]
-  bin = "main"
+  bin = "harbor-satellite-dev"
-  dir = "."
+  dir = "${GOPATH}/src/github.com/yourorg/harbor-satellite"
-  cmd = "go build -o main ."
+  cmd = "go build -o ./bin/harbor-satellite-dev ."
   exclude_dir = ["assets", "tmp", "vendor", "testdata"]
   exclude_regex = ["_test.go"]
   exclude_unchanged = false
   follow_symlink = false
-  run_after_build = "chmod +x main"
+  run_after_build = "chmod +x ./bin/harbor-satellite-dev"
   include_ext = ["go"]

Additionally, consider adding:

  • Build tags for development builds
  • Clear temporary files after builds
  • Version information in the binary
✅ Verification successful

Adjust Air configuration to align with project structure and gitignore

Based on the codebase analysis, here are the recommended changes to the Air configuration:

[build]
-  bin = "main"
+  bin = "bin/harbor-satellite"
   dir = "."
-  cmd = "go build -o main ."
+  cmd = "go build -o bin/harbor-satellite ."
   exclude_dir = ["assets", "tmp", "vendor", "testdata"]
   exclude_regex = ["_test.go"]
   exclude_unchanged = false
   follow_symlink = false
-  run_after_build = "chmod +x main"
+  run_after_build = "chmod +x bin/harbor-satellite"
   include_ext = ["go"]

The changes are based on:

  • Project's module name is container-registry.com/harbor-satellite
  • /bin directory is already in .gitignore for build outputs
  • Main package is in the root directory
  • More specific binary name that matches the project
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify if the current directory structure supports the suggested paths
fd -t d "bin$"

Length of output: 16


Script:

#!/bin/bash
# Let's gather more context about the project structure and build setup
# Check for Go module name and structure
cat go.mod 2>/dev/null || echo "No go.mod found"

# Check for any existing build or binary directories
fd -t d "(build|dist|bin|target)$"

# Look for other .air.toml files for consistency
fd -t f ".air.toml$"

# Check for main package location
rg -l "package main" --type go

Length of output: 25699


Script:

#!/bin/bash
# Let's check the main.go content to understand the project structure
cat main.go

# Check if there are any existing build scripts or Makefiles
fd -t f "(Makefile|build\.sh)$"

# Look for any existing build output directories in gitignore
cat .gitignore 2>/dev/null

Length of output: 4862

ground-control/.air.toml (1)

1-13: Verify Air integration with Dagger setup

Since this configuration is part of addressing Dagger's live reload limitations, we should verify:

  1. That Air's file watching works correctly with the Dagger container setup
  2. That the included file patterns catch all relevant changes

Let's check for any potential file watching configuration in Dagger:

✅ Verification successful

The previous results show all Go files are within the watched directories, but we need to verify the Dagger integration specifics and any potential conflicts with Air's live reload. Let's examine the Dagger pipeline configuration and development setup.


Air configuration is compatible with the development setup

The Air configuration is correctly set up and won't conflict with the Dagger pipeline:

  • The Air config watches all .go files in the project directory, excluding test files and vendor directories
  • Dagger is used for CI/CD pipelines and testing, not for local development, so there's no conflict with Air's live reload functionality
  • The file watching patterns in .air.toml cover all Go source files in the project structure
  • The build command and directory settings are appropriate for the Go project structure
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for file watching configurations in Dagger files
# and potential conflicts with Air configuration

# Look for Dagger-related file watching configurations
rg -l "watch|reload|live" --type yaml --type go

# Check if there are any Go files outside the watched directories
fd -e go -E "vendor" -E "testdata" -E "tmp"

Length of output: 1539


Script:

#!/bin/bash
# Let's check the Dagger pipeline configuration and any file watching mechanisms

# Search for Dagger pipeline definitions
rg -A 5 "dagger.Pipeline" 

# Check for any watch/reload related code in ci/ground_control.go
cat ci/ground_control.go

# Look for development-related configurations
fd -e yaml -e yml

Length of output: 1019

README.md (1)

17-18: LGTM! QuickStart section addition aligns with PR objectives.

The new section effectively directs users to the detailed setup instructions, fulfilling the requirement for better documentation of the local setup process.

🧰 Tools
🪛 LanguageTool

[typographical] ~17-~17: Consider adding a comma here.
Context: ...decentralized registries. ## QuickStart Please refer to the latest setup instructions ...

(PLEASE_COMMA)

Comment on lines +1 to +10
[build]
bin = "main"
dir = "."
cmd = "go build -o main ."
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
run_after_build = "chmod +x main"
include_ext = ["go"]
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Several improvements needed in build configuration

  1. The binary name "main" is too generic and could lead to conflicts. Consider using a more specific name like "ground-control-dev".
  2. The chmod +x command should specify explicit permissions (e.g., 755) for better security.
  3. Setting exclude_unchanged = false means every file change triggers a rebuild, which could impact development performance.
  4. Consider adding more exclude directories like ".git", "node_modules".

Apply these improvements:

[build]
-  bin = "main"
+  bin = "ground-control-dev"
  dir = "."
-  cmd = "go build -o main ."
+  cmd = "go build -o ground-control-dev ."
-  exclude_dir = ["assets", "tmp", "vendor", "testdata"]
+  exclude_dir = ["assets", "tmp", "vendor", "testdata", ".git", "node_modules"]
  exclude_regex = ["_test.go"]
-  exclude_unchanged = false
+  exclude_unchanged = true
  follow_symlink = false
-  run_after_build = "chmod +x main"
+  run_after_build = "chmod 755 ground-control-dev"
  include_ext = ["go"]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
[build]
bin = "main"
dir = "."
cmd = "go build -o main ."
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
run_after_build = "chmod +x main"
include_ext = ["go"]
[build]
bin = "ground-control-dev"
dir = "."
cmd = "go build -o ground-control-dev ."
exclude_dir = ["assets", "tmp", "vendor", "testdata", ".git", "node_modules"]
exclude_regex = ["_test.go"]
exclude_unchanged = true
follow_symlink = false
run_after_build = "chmod 755 ground-control-dev"
include_ext = ["go"]

Comment on lines +50 to +70
Then navigate to the `satellite` directory and verify that `config.toml` is set up correctly:

```toml
# Whether to use the built-in Zot registry or not
bring_own_registry = false

# IP address and port of the registry
own_registry_adr = "127.0.0.1"
own_registry_port = "8585"

# URL of remote registry or local file path
url_or_file = "https://demo.goharbor.io/v2/myproject/album-server"



# Default path for Zot registry config.json
zotConfigPath = "./registry/config.json"

# Set logging level
log_level = "info"
```
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance configuration documentation with explanations and validation steps.

The configuration section needs:

  1. Explanations for each configuration option
  2. Steps to validate the configuration
  3. A more generic example URL

Apply this diff:

 # Whether to use the built-in Zot registry or not
 bring_own_registry = false
+# Set to true if you want to use an external registry instead of the built-in Zot registry
 
 # IP address and port of the registry
 own_registry_adr = "127.0.0.1"
 own_registry_port = "8585"
+# These settings are used when bring_own_registry = true
 
 # URL of remote registry or local file path
-url_or_file = "https://demo.goharbor.io/v2/myproject/album-server"
+url_or_file = "<your_registry_url>/v2/<project>/<repository>"
+# Format: https://registry.example.com/v2/project/repository
 
 # Default path for Zot registry config.json
 zotConfigPath = "./registry/config.json"
+# This path must exist and be readable
 
 # Set logging level
 log_level = "info"
+# Available levels: debug, info, warn, error

Add validation steps:

To validate your configuration:
1. Verify file permissions for zotConfigPath
2. Test registry connectivity
3. Confirm port availability

QUICKSTART.md Outdated
Comment on lines 72 to 100
### 6. Register the Satellite with Ground Control
Using `curl` or Postman, make a `POST` request to register the Satellite with Ground Control:

```bash
curl -X POST http://localhost:8080/satellites/register -H "Content-Type: application/json" -d '{ "name": "<satellite_name_here>" }'
```

The response will include a token string. Set this token in the Satellite `.env` file:

```console
TOKEN=<string_from_ground_control>
```

### 7. Start the Satellite
Run the following Dagger command to start the Satellite service:

```bash
dagger call build-dev --component satellite up
```

The Satellite service will start on port 9090. Ensure that the `ground_control_url` is correctly set in the Satellite configuration before launching.


### 8. Finalize and Run
After setting the token, you can now run the Satellite. This setup will launch the Satellite in a container with the following exposed ports:
- **9090** for the Satellite service.
- **8585** for the Zot registry (if configured).

With this setup, your Harbor Satellite should be up and running!
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling and verification steps to the setup process.

The setup instructions should include:

  1. Error handling for registration failures
  2. Health check endpoints
  3. Troubleshooting steps
  4. Verification of successful setup

Add the following sections:

### Verification Steps
1. Check Ground Control health:
   ```bash
   curl http://localhost:8080/health
  1. Verify Satellite registration:
    curl http://localhost:8080/satellites/status

Troubleshooting

Common issues and solutions:

  • Connection refused: Verify ports are not in use
  • Registration fails: Check Ground Control logs
  • Token issues: Verify token format and permissions

Health Monitoring

Monitor these endpoints:


<!-- This is an auto-generated comment by CodeRabbit -->

QUICKSTART.md Outdated
Comment on lines 19 to 32
```bash
HARBOR_USERNAME=admin
HARBOR_PASSWORD=Harbor12345
HARBOR_URL=https://demo.goharbor.io

PORT=8080
APP_ENV=local

DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=groundcontrol
DB_USERNAME=postgres # Customize based on your DB config
DB_PASSWORD=password # Customize based on your DB config
```
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Security: Replace sensitive credentials with placeholders.

The example contains actual credentials and URLs which could be security risks if copied directly. Consider:

  1. Using placeholders instead of actual credentials
  2. Adding a warning about securing sensitive information
  3. Mentioning credential management best practices

Apply this diff:

-HARBOR_USERNAME=admin
-HARBOR_PASSWORD=Harbor12345
-HARBOR_URL=https://demo.goharbor.io
+HARBOR_USERNAME=<your_harbor_username>
+HARBOR_PASSWORD=<your_harbor_password>
+HARBOR_URL=<your_harbor_url>

 PORT=8080
 APP_ENV=local

 DB_HOST=localhost
 DB_PORT=5432
 DB_DATABASE=groundcontrol
-DB_USERNAME=postgres       # Customize based on your DB config
-DB_PASSWORD=password       # Customize based on your DB config
+DB_USERNAME=<your_db_username>
+DB_PASSWORD=<your_db_password>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
```bash
HARBOR_USERNAME=admin
HARBOR_PASSWORD=Harbor12345
HARBOR_URL=https://demo.goharbor.io
PORT=8080
APP_ENV=local
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=groundcontrol
DB_USERNAME=postgres # Customize based on your DB config
DB_PASSWORD=password # Customize based on your DB config
```
```bash
HARBOR_USERNAME=<your_harbor_username>
HARBOR_PASSWORD=<your_harbor_password>
HARBOR_URL=<your_harbor_url>
PORT=8080
APP_ENV=local
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=groundcontrol
DB_USERNAME=<your_db_username>
DB_PASSWORD=<your_db_password>
```

ci/main.go Outdated
Comment on lines 42 to 50
if component == "ground-control" {
golang = golang.
WithExec([]string{"ls", "-la"}).
// WithWorkdir("./ground-control/").
// WithExec([]string{"go", "mod", "download"}).
WithExec([]string{"ls", "-la"}).
WithExec([]string{"air", "-c", ".air.toml"}).
WithExposedPort(8080)
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Clean up development setup and improve error handling.

The ground-control setup needs cleanup and improvements:

  1. Remove debug ls commands
  2. Remove or implement commented code
  3. Add validation for Air config
  4. Use constant for port number
 		if component == "ground-control" {
 			golang = golang.
-				WithExec([]string{"ls", "-la"}).
-				// WithWorkdir("./ground-control/").
-				// WithExec([]string{"go", "mod", "download"}).
-				WithExec([]string{"ls", "-la"}).
+				WithExec([]string{"test", "-f", ".air.toml"}).  // Validate config
 				WithExec([]string{"air", "-c", ".air.toml"}).
-				WithExposedPort(8080)
+				WithExposedPort(8080)  // Consider adding a constant for this

Committable suggestion skipped: line range outside the PR's diff.

ci/main.go Outdated
Comment on lines 31 to 41
if component == "satellite" || component == "ground-control" {
golang := dag.Container().
From("golang:latest").
WithMountedCache("/go/pkg/mod", dag.CacheVolume("go-mod")).
WithEnvVariable("GOMODCACHE", "/go/pkg/mod").
WithMountedCache("/go/build-cache", dag.CacheVolume("go-build")).
WithEnvVariable("GOCACHE", "/go/build-cache").
WithMountedDirectory(PROJ_MOUNT, source).
WithWorkdir(PROJ_MOUNT).
WithExec([]string{"go", "install", "github.com/air-verse/air@latest"})

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Improve container setup reliability and consistency.

Several issues need attention:

  1. Using "latest" tag can lead to non-reproducible builds
  2. Air tool version should be pinned for consistency
  3. Missing error handling for Air installation

Apply these changes:

-		golang := dag.Container().
-			From("golang:latest").
+		golang := dag.Container().
+			From(DEFAULT_GO).
+			WithExec([]string{"go", "install", "github.com/air-verse/[email protected]"}).
+			WithExec([]string{"which", "air"}).  // Verify installation

Committable suggestion skipped: line range outside the PR's diff.

ci/main.go Outdated
Comment on lines 23 to 57
// build-dev function would start the dev server for the component provided.
func (m *HarborSatellite) BuildDev(
ctx context.Context,
// +optional
// +defaultPath="./ground-control"
source *dagger.Directory,
component string,
) (*dagger.Service, error) {
if component == "satellite" || component == "ground-control" {
golang := dag.Container().
From("golang:latest").
WithMountedCache("/go/pkg/mod", dag.CacheVolume("go-mod")).
WithEnvVariable("GOMODCACHE", "/go/pkg/mod").
WithMountedCache("/go/build-cache", dag.CacheVolume("go-build")).
WithEnvVariable("GOCACHE", "/go/build-cache").
WithMountedDirectory(PROJ_MOUNT, source).
WithWorkdir(PROJ_MOUNT).
WithExec([]string{"go", "install", "github.com/air-verse/air@latest"})

if component == "ground-control" {
golang = golang.
WithExec([]string{"ls", "-la"}).
// WithWorkdir("./ground-control/").
// WithExec([]string{"go", "mod", "download"}).
WithExec([]string{"ls", "-la"}).
WithExec([]string{"air", "-c", ".air.toml"}).
WithExposedPort(8080)
}
// to-do: build else part for the satellite

return golang.AsService(), nil
}

return nil, fmt.Errorf("error: please provide component as either satellite or ground-control")
}
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Missing Air configuration file and potential setup issues

The verification revealed several concerns:

  • The .air.toml configuration file referenced in the code is missing from both the root and ground-control directories
  • The ground-control module exists with its own go.mod, but the Air development server setup is incomplete
  • The BuildDev method is only defined but not used elsewhere in the codebase

Required actions:

  • Add the missing .air.toml configuration file in the ground-control directory
  • Ensure the Air development server configuration aligns with the Go module structure
  • Consider documenting the BuildDev usage in the codebase
🔗 Analysis chain

Verify Air configuration and method usage.

Let's verify the integration points:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify Air configuration and BuildDev usage

# Check if Air config exists
echo "Checking Air configuration files..."
fd -t f ".air.toml$"

# Look for BuildDev method usage
echo -e "\nChecking BuildDev method usage..."
rg "BuildDev.*ground-control" -t go

Length of output: 224


Script:

#!/bin/bash
# Let's broaden our search to get more context

# Check for any Air-related configuration files with different extensions
echo "Checking for Air configuration files with various extensions..."
fd -t f "air\.(toml|conf|config|yaml|yml)$"

# Look for BuildDev method usage with a broader search
echo -e "\nChecking BuildDev method usage (broader search)..."
rg "BuildDev" -A 3 -B 1 -t go

# Check the ground-control directory structure
echo -e "\nChecking ground-control directory structure..."
fd . ground-control

# Look for go.mod in ground-control
echo -e "\nChecking for go.mod in ground-control..."
fd "go.mod$" ground-control

Length of output: 2711

A typical use case would work as follows :
_(A direct access from edge device to the remote registry is still possible when network conditions permit it)._
The satellite component may also handle updating container runtime configurations and fetching image lists from Ground Control, a part of Harbor.
The stateful local regsitry will also need to handle storing and managing data on local volumes.
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix typo in "registry" spelling.

There are instances where "registry" is misspelled as "regsitry".

Apply these corrections:

-regsitry
+registry

Also applies to: 68-68

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (3)
ci/main.go (2)

23-30: Enhance method documentation for better clarity.

The current documentation lacks essential details. Consider adding:

  • Parameter descriptions and their requirements
  • Return value explanation
  • Prerequisites (e.g., Air tool requirement)
  • Example usage
-// build-dev function would start the dev server for the component provided.
+// BuildDev starts a development server for the specified component using the Air tool
+// for live reloading.
+//
+// Parameters:
+//   - ctx: Context for cancellation and timeout
+//   - source: Directory containing the source code (defaults to ".")
+//   - component: Either "satellite" or "ground-control"
+//
+// Returns:
+//   - *dagger.Service: Running development server
+//   - error: If component is invalid or setup fails
+//
+// Prerequisites:
+//   - Air tool for live reloading
+//   - For ground-control: PostgreSQL database (automatically started)

60-66: Improve TODO comment and error handling.

The TODO comment lacks detail, and error messages could be more helpful.

-		// to-do: build else part for the satellite
+		// TODO: Implement satellite development server setup
+		// Requirements:
+		// - Add Air configuration for satellite
+		// - Configure appropriate ports and environment
+		// - Add any satellite-specific dependencies

-	return nil, fmt.Errorf("error: please provide component as either satellite or ground-control")
+	return nil, fmt.Errorf("invalid component %q: must be either 'satellite' or 'ground-control'", component)
go.mod (1)

Line range hint 474-483: Review replace directives for OpenTelemetry packages.

The replace directives for OpenTelemetry packages are using specific versions. This approach:

  1. Ensures version consistency
  2. Might make future updates more challenging
  3. Should be documented with the reason for these specific replacements

Consider adding a comment explaining why these specific versions are required.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9dcfc66 and 3a82f41.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (4)
  • ci/main.go (1 hunks)
  • dagger.json (1 hunks)
  • go.mod (5 hunks)
  • ground-control/.env (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • ground-control/.env
🧰 Additional context used
🪛 golangci-lint
ci/main.go

32-32: undefined: dag

(typecheck)


34-34: undefined: dag

(typecheck)

🔇 Additional comments (6)
dagger.json (2)

5-5: Verify CI pipeline updates for local development

Since this PR adds local development capabilities, ensure that the "ci" directory contains the necessary pipeline definitions for both CI and local development scenarios.

Let's check the pipeline definitions:

#!/bin/bash
# Description: Verify pipeline definitions for local development

# Check for development-related functions in the CI code
rg -A 10 "func.*Dev|func.*Local" ci/

# Look for any development server configurations
rg -i "development.*server|dev.*mode|local.*environment" ci/

3-3: Verify Dagger engine version compatibility

The upgrade from v0.13.3 to v0.14.0 should be verified for compatibility with the local development setup described in the quickstart guide.

Let's verify the version compatibility and check for any breaking changes:

✅ Verification successful

Dagger engine version is up to date and compatible

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check Dagger version compatibility and release notes

# Check if v0.14.0 is the latest stable version
curl -s https://api.github.com/repos/dagger/dagger/releases | jq -r '.[].tag_name' | head -n 5

# Search for any breaking changes or known issues in the codebase related to Dagger versions
rg -i "dagger.*version|breaking.?change" README.md CHANGELOG.md docs/

# Check if the quickstart guide mentions specific Dagger version requirements
rg -i "dagger.*version|v0\.14\.0" QUICKSTART.md

Length of output: 992


Script:

#!/bin/bash
# Description: Confirm the latest Dagger version and retrieve release notes for v0.14.0

# Fetch the latest stable release tag from GitHub
latest_version=$(curl -s https://api.github.com/repos/dagger/dagger/releases/latest | jq -r '.tag_name')
echo "Latest Dagger version: $latest_version"

# Compare with the current version in dagger.json
current_version=$(grep '"engineVersion"' dagger.json | awk -F '"' '{print $4}')
echo "Current Dagger version in dagger.json: $current_version"

if [ "$latest_version" != "$current_version" ]; then
  echo "A newer Dagger version is available: $latest_version"
else
  echo "Dagger is up to date."
fi

# Retrieve release notes for v0.14.0
curl -s https://api.github.com/repos/dagger/dagger/releases/tags/$current_version | jq -r '.body'

Length of output: 1910

ci/main.go (1)

32-41: ⚠️ Potential issue

Fix container setup reliability issues.

Several critical issues need attention:

  1. Using "latest" tag can lead to non-reproducible builds
  2. Air tool version should be pinned
  3. The dag variable is undefined

Apply these changes:

-		golang := dag.Container().
-			From("golang:latest").
+		golang := dag.Container().
+			From(DEFAULT_GO).  // Using the constant defined above
+			WithExec([]string{"go", "install", "github.com/air-verse/[email protected]"}).

Also, ensure the dag variable is properly initialized. It seems to be missing from the current scope.

🧰 Tools
🪛 golangci-lint

32-32: undefined: dag

(typecheck)


34-34: undefined: dag

(typecheck)

go.mod (3)

396-397: Review OpenTelemetry integration approach.

The addition of OpenTelemetry metric exporters (both gRPC and HTTP) suggests implementation of metrics collection. Ensure that:

  1. Only one exporter type is used to avoid duplicate metrics
  2. Proper configuration is in place for the chosen exporter
#!/bin/bash
# Description: Check OpenTelemetry configuration and usage
# Test: Look for OpenTelemetry initialization and configuration

# Search for OpenTelemetry initialization
rg -l "NewMeterProvider|NewTracerProvider"

# Look for exporter configuration
rg -l "otlpmetrichttp.New|otlpmetricgrpc.New"

Also applies to: 402-402, 405-405


31-31: Verify compatibility with updated dependencies.

Major version updates for key dependencies:

  • github.com/99designs/gqlgen → v0.17.55
  • github.com/adrg/xdg → v0.5.1
  • github.com/vektah/gqlparser/v2 → v2.5.17

These updates may include breaking changes that need to be addressed.

#!/bin/bash
# Description: Check for potential breaking changes in dependency usage
# Test: Search for usage of updated packages that might need modifications

# Search for gqlgen usage
rg "github.com/99designs/gqlgen" -A 5

# Search for xdg usage
rg "github.com/adrg/xdg" -A 5

# Search for gqlparser usage
rg "github.com/vektah/gqlparser/v2" -A 5

Also applies to: 67-67, 376-376


3-5: Verify Go toolchain compatibility.

The Go version (1.22.5) and toolchain version (1.23.2) mismatch might cause compatibility issues. Typically, the toolchain version should match the Go version being used.

Comment on lines +68 to +78
// starts postgres DB container for ground-control.
func (m *HarborSatellite) Db(ctx context.Context) (*dagger.Service, error) {
return dag.Container().
From("postgres:17").
WithEnvVariable("POSTGRES_USER", "postgres").
WithEnvVariable("POSTGRES_PASSWORD", "password").
WithEnvVariable("POSTGRES_HOST_AUTH_METHOD", "trust").
WithEnvVariable("POSTGRES_DB", "groundcontrol").
WithExposedPort(5432).
AsService().Start(ctx)
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve database container configuration and security.

Several improvements needed:

  1. Make credentials configurable
  2. Pin PostgreSQL version
  3. Add container health check
 func (m *HarborSatellite) Db(ctx context.Context) (*dagger.Service, error) {
+	const POSTGRES_VERSION = "17.2"  // Pin specific version
+
 	return dag.Container().
-		From("postgres:17").
+		From("postgres:" + POSTGRES_VERSION).
 		WithEnvVariable("POSTGRES_USER", "postgres").
 		WithEnvVariable("POSTGRES_PASSWORD", "password").
 		WithEnvVariable("POSTGRES_HOST_AUTH_METHOD", "trust").
 		WithEnvVariable("POSTGRES_DB", "groundcontrol").
 		WithExposedPort(5432).
+		WithHealthCheck(
+			dag.Container().
+				WithExec([]string{"pg_isready", "-U", "postgres"}),
+		).
 		AsService().Start(ctx)
 }

Consider extracting credentials to environment variables or a configuration file for better security and flexibility.

Committable suggestion skipped: line range outside the PR's diff.

ci/main.go Outdated
Comment on lines 48 to 58
golang = golang.
WithWorkdir(PROJ_MOUNT+"/ground-control/sql/schema").
WithExec([]string{"ls", "-la"}).
WithServiceBinding("pgservice", db).
WithExec([]string{"go", "install", "github.com/pressly/goose/v3/cmd/goose@latest"}).
WithExec([]string{"goose", "postgres", "postgres://postgres:password@pgservice:5432/groundcontrol", "up"}).
WithWorkdir(PROJ_MOUNT + "/ground-control").
WithExec([]string{"ls", "-la"}).
WithExec([]string{"go", "mod", "download"}).
WithExec([]string{"air", "-c", ".air.toml"}).
WithExposedPort(8080)
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Clean up development setup and improve reliability.

Several improvements needed:

  1. Remove debug ls commands
  2. Pin goose version
  3. Verify Air configuration file existence
 			golang = golang.
 				WithWorkdir(PROJ_MOUNT+"/ground-control/sql/schema").
-				WithExec([]string{"ls", "-la"}).
 				WithServiceBinding("pgservice", db).
-				WithExec([]string{"go", "install", "github.com/pressly/goose/v3/cmd/goose@latest"}).
+				WithExec([]string{"go", "install", "github.com/pressly/goose/v3/cmd/[email protected]"}).
 				WithExec([]string{"goose", "postgres", "postgres://postgres:password@pgservice:5432/groundcontrol", "up"}).
 				WithWorkdir(PROJ_MOUNT + "/ground-control").
-				WithExec([]string{"ls", "-la"}).
+				WithExec([]string{"test", "-f", ".air.toml"}).  // Verify config exists
 				WithExec([]string{"go", "mod", "download"}).
 				WithExec([]string{"air", "-c", ".air.toml"}).
 				WithExposedPort(8080)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
golang = golang.
WithWorkdir(PROJ_MOUNT+"/ground-control/sql/schema").
WithExec([]string{"ls", "-la"}).
WithServiceBinding("pgservice", db).
WithExec([]string{"go", "install", "github.com/pressly/goose/v3/cmd/goose@latest"}).
WithExec([]string{"goose", "postgres", "postgres://postgres:password@pgservice:5432/groundcontrol", "up"}).
WithWorkdir(PROJ_MOUNT + "/ground-control").
WithExec([]string{"ls", "-la"}).
WithExec([]string{"go", "mod", "download"}).
WithExec([]string{"air", "-c", ".air.toml"}).
WithExposedPort(8080)
golang = golang.
WithWorkdir(PROJ_MOUNT+"/ground-control/sql/schema").
WithServiceBinding("pgservice", db).
WithExec([]string{"go", "install", "github.com/pressly/goose/v3/cmd/[email protected]"}).
WithExec([]string{"goose", "postgres", "postgres://postgres:password@pgservice:5432/groundcontrol", "up"}).
WithWorkdir(PROJ_MOUNT + "/ground-control").
WithExec([]string{"test", "-f", ".air.toml"}). // Verify config exists
WithExec([]string{"go", "mod", "download"}).
WithExec([]string{"air", "-c", ".air.toml"}).
WithExposedPort(8080)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Outside diff range and nitpick comments (2)
QUICKSTART.md (1)

5-9: Enhance prerequisites section with specific requirements.

The prerequisites section should include:

  • Minimum system requirements (CPU, RAM, disk space)
  • Required Go version
  • Network requirements (ports that need to be available)
  • Docker version requirements (if needed)
ci/main.go (1)

Line range hint 1-11: Fix undefined dag variable

The dag variable is used throughout the code but not defined. This needs to be fixed to prevent runtime errors.

Add the following at the beginning of the file:

 package main

 import (
 	"context"
 	"fmt"
 	"log"
 	"log/slog"
 	"os"
 	"strings"

 	"container-registry.com/harbor-satellite/ci/internal/dagger"
+
+	dag "container-registry.com/harbor-satellite/ci/internal/dagger"
 )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3a82f41 and b00b5ad.

📒 Files selected for processing (2)
  • QUICKSTART.md (1 hunks)
  • ci/main.go (3 hunks)
🧰 Additional context used
🪛 golangci-lint
ci/main.go

32-32: undefined: dag

(typecheck)


34-34: undefined: dag

(typecheck)

🔇 Additional comments (5)
QUICKSTART.md (3)

19-32: ⚠️ Potential issue

Replace sensitive information with secure placeholders.

The configuration contains actual credentials and demo URLs which pose security risks.

Previous review comments about securing sensitive information are still valid. Additionally:

  1. Add a warning about not using these credentials in production
  2. Document the required permission scopes for the Harbor credentials
  3. Add validation steps for testing the configuration

34-54: 🛠️ Refactor suggestion

Add operational validation and troubleshooting steps.

The execution instructions need additional operational details.

Previous review comments about adding health checks and troubleshooting steps are still valid. Additionally:

  1. Document expected output for successful execution
  2. Add instructions for viewing logs
  3. Include steps to verify the service is running correctly

64-82: 🛠️ Refactor suggestion

Enhance configuration documentation.

The configuration section needs better documentation and examples.

Previous review comments about enhancing configuration documentation are still valid. Additionally:

  1. Document the impact of each configuration option
  2. Add examples for different setup scenarios
  3. Include configuration validation steps
ci/main.go (2)

185-192: LGTM!

The helper function is well-implemented with proper input validation and clear error messaging.


114-124: ⚠️ Potential issue

Improve database container configuration and security

Several improvements needed:

  1. Pin PostgreSQL to specific minor version
  2. Make credentials configurable
  3. Add container health check

Apply this diff:

+const (
+	POSTGRES_VERSION = "17.2"
+	POSTGRES_USER = "postgres"
+	POSTGRES_PASSWORD = "password"
+	POSTGRES_DB = "groundcontrol"
+)

 func (m *HarborSatellite) Db(ctx context.Context) (*dagger.Service, error) {
 	return dag.Container().
-		From("postgres:17").
+		From("postgres:" + POSTGRES_VERSION).
-		WithEnvVariable("POSTGRES_USER", "postgres").
-		WithEnvVariable("POSTGRES_PASSWORD", "password").
+		WithEnvVariable("POSTGRES_USER", POSTGRES_USER).
+		WithEnvVariable("POSTGRES_PASSWORD", POSTGRES_PASSWORD).
 		WithEnvVariable("POSTGRES_HOST_AUTH_METHOD", "trust").
-		WithEnvVariable("POSTGRES_DB", "groundcontrol").
+		WithEnvVariable("POSTGRES_DB", POSTGRES_DB).
 		WithExposedPort(5432).
+		WithHealthCheck(
+			dag.Container().
+				WithExec([]string{"pg_isready", "-U", POSTGRES_USER}),
+		).
 		AsService().Start(ctx)
 }

Likely invalid or redundant comment.

Comment on lines +84 to +117
### 6. Register the Satellite with Ground Control
Using `curl` or Postman, make a `POST` request to register the Satellite with Ground Control:

```bash
curl -X POST http://localhost:8080/satellites/register -H "Content-Type: application/json" -d '{ "name": "<satellite_name_here>" }'
```

The response will include a token string. Set this token in the Satellite `.env` file:

```console
TOKEN=<string_from_ground_control>
```

### 7. Build the Satellite
Run the following Dagger command to build the Satellite:

```bash
dagger call build-dev --platform "linux/amd64" --component satellite export --path=./satellite-dev
```

To Run Satellite:
```bash
./satellite-dev
```

The Satellite service will start on port 9090. Ensure that the `ground_control_url` is correctly set in the Satellite configuration before launching.


### 8. Finalize and Run
After setting the token, you can now run the Satellite. This setup will launch the Satellite in a container with the following exposed ports:
- **9090** for the Satellite service.
- **8585** for the Zot registry (if configured).

With this setup, your Harbor Satellite should be up and running!
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add security considerations and verification steps for registration process.

The registration and execution instructions need enhancement:

  1. Add error handling for registration failures
  2. Document token security best practices
  3. Include steps to verify successful registration

Apply this diff:

 curl -X POST http://localhost:8080/satellites/register -H "Content-Type: application/json" -d '{ "name": "<satellite_name_here>" }'
+
+# Verify registration status
+curl -X GET http://localhost:8080/satellites/status
+
+# Store token securely (do not commit to version control)
+echo "TOKEN=<string_from_ground_control>" > .env
+chmod 600 .env

Add a security note:

> **Security Note:** The registration token grants access to Ground Control. Store it securely and never commit it to version control. Rotate tokens periodically following security best practices.

Comment on lines +32 to +41
golang := dag.Container().
From("golang:latest").
WithMountedCache("/go/pkg/mod", dag.CacheVolume("go-mod")).
WithEnvVariable("GOMODCACHE", "/go/pkg/mod").
WithMountedCache("/go/build-cache", dag.CacheVolume("go-build")).
WithEnvVariable("GOCACHE", "/go/build-cache").
WithMountedDirectory(PROJ_MOUNT, source).
WithWorkdir(PROJ_MOUNT).
WithExec([]string{"go", "install", "github.com/air-verse/air@latest"})

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Pin container and tool versions for reproducibility

Several improvements needed for container setup:

  1. Pin Golang version instead of using "latest"
  2. Pin Air tool version
  3. Add Air config validation

Apply this diff:

 	golang := dag.Container().
-		From("golang:latest").
+		From(DEFAULT_GO).  // Using the constant defined above
 		WithMountedCache("/go/pkg/mod", dag.CacheVolume("go-mod")).
 		WithEnvVariable("GOMODCACHE", "/go/pkg/mod").
 		WithMountedCache("/go/build-cache", dag.CacheVolume("go-build")).
 		WithEnvVariable("GOCACHE", "/go/build-cache").
 		WithMountedDirectory(PROJ_MOUNT, source).
 		WithWorkdir(PROJ_MOUNT).
-		WithExec([]string{"go", "install", "github.com/air-verse/air@latest"})
+		WithExec([]string{"go", "install", "github.com/air-verse/[email protected]"}).
+		WithExec([]string{"which", "air"})  // Verify installation

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 golangci-lint

32-32: undefined: dag

(typecheck)


34-34: undefined: dag

(typecheck)

Comment on lines +71 to +76
fmt.Println("🛠️ Building Harbor-Cli with Dagger...")
// Define the path for the binary output
os, arch, err := parsePlatform(platform)
if err != nil {
log.Fatalf("Error parsing platform: %v", err)
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Improve error handling and messaging

The error handling could be improved:

  1. Don't use log.Fatalf as it terminates the program
  2. Return the error to the caller for proper handling

Apply this diff:

-	fmt.Println("🛠️  Building Harbor-Cli with Dagger...")
+	fmt.Printf("🛠️  Building %s with Dagger...\n", component)
 	// Define the path for the binary output
 	os, arch, err := parsePlatform(platform)
 	if err != nil {
-		log.Fatalf("Error parsing platform: %v", err)
+		return nil, fmt.Errorf("error parsing platform: %w", err)
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fmt.Println("🛠️ Building Harbor-Cli with Dagger...")
// Define the path for the binary output
os, arch, err := parsePlatform(platform)
if err != nil {
log.Fatalf("Error parsing platform: %v", err)
}
fmt.Printf("🛠️ Building %s with Dagger...\n", component)
// Define the path for the binary output
os, arch, err := parsePlatform(platform)
if err != nil {
return nil, fmt.Errorf("error parsing platform: %w", err)
}

Comment on lines +47 to +57
golang = golang.
WithWorkdir(PROJ_MOUNT+"/ground-control/sql/schema").
WithExec([]string{"ls", "-la"}).
WithServiceBinding("pgservice", db).
WithExec([]string{"go", "install", "github.com/pressly/goose/v3/cmd/goose@latest"}).
WithExec([]string{"goose", "postgres", "postgres://postgres:password@pgservice:5432/groundcontrol", "up"}).
WithWorkdir(PROJ_MOUNT + "/ground-control").
WithExec([]string{"ls", "-la"}).
WithExec([]string{"go", "mod", "download"}).
WithExec([]string{"air", "-c", ".air.toml"}).
WithExposedPort(8080)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Clean up development setup and improve error handling

Several improvements needed:

  1. Remove debug ls commands
  2. Extract database connection string to a constant
  3. Pin goose version
  4. Add Air config validation

Apply this diff:

 	golang = golang.
 		WithWorkdir(PROJ_MOUNT+"/ground-control/sql/schema").
-		WithExec([]string{"ls", "-la"}).
 		WithServiceBinding("pgservice", db).
-		WithExec([]string{"go", "install", "github.com/pressly/goose/v3/cmd/goose@latest"}).
+		WithExec([]string{"go", "install", "github.com/pressly/goose/v3/cmd/[email protected]"}).
+		WithExec([]string{"test", "-f", "migrations"}).  // Verify migrations exist
 		WithExec([]string{"goose", "postgres", "postgres://postgres:password@pgservice:5432/groundcontrol", "up"}).
 		WithWorkdir(PROJ_MOUNT + "/ground-control").
-		WithExec([]string{"ls", "-la"}).
+		WithExec([]string{"test", "-f", ".air.toml"}).  // Verify config exists
 		WithExec([]string{"go", "mod", "download"}).
 		WithExec([]string{"air", "-c", ".air.toml"}).
 		WithExposedPort(8080)

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +78 to +106
if component == "satellite" || component == "ground-control" {
var binaryFile *dagger.File
golang := dag.Container().
From("golang:latest").
WithMountedCache("/go/pkg/mod", dag.CacheVolume("go-mod")).
WithEnvVariable("GOMODCACHE", "/go/pkg/mod").
WithMountedCache("/go/build-cache", dag.CacheVolume("go-build")).
WithEnvVariable("GOCACHE", "/go/build-cache").
WithMountedDirectory(PROJ_MOUNT, source).
WithWorkdir(PROJ_MOUNT).
WithEnvVariable("GOOS", os).
WithEnvVariable("GOARCH", arch)

if component == "ground-control" {
golang = golang.
WithWorkdir(PROJ_MOUNT + "/ground-control").
WithExec([]string{"ls", "-la"}).
WithExec([]string{"go", "mod", "download"}).
WithExec([]string{"go", "build", "."})

binaryFile = golang.File(PROJ_MOUNT + "/ground-control/ground-control")
} else {
golang = golang.
WithExec([]string{"ls", "-la"}).
WithExec([]string{"go", "mod", "download"}).
WithExec([]string{"go", "build", "."})

binaryFile = golang.File(PROJ_MOUNT + "/harbor-satellite")
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Refactor container setup and remove debug commands

The code has several issues:

  1. Duplicated container setup logic
  2. Debug ls commands
  3. Unpinned golang version

Extract common container setup to a helper method and clean up the code:

+func setupGolangContainer(source *dagger.Directory, os, arch string) *dagger.Container {
+	return dag.Container().
+		From(DEFAULT_GO).
+		WithMountedCache("/go/pkg/mod", dag.CacheVolume("go-mod")).
+		WithEnvVariable("GOMODCACHE", "/go/pkg/mod").
+		WithMountedCache("/go/build-cache", dag.CacheVolume("go-build")).
+		WithEnvVariable("GOCACHE", "/go/build-cache").
+		WithMountedDirectory(PROJ_MOUNT, source).
+		WithWorkdir(PROJ_MOUNT).
+		WithEnvVariable("GOOS", os).
+		WithEnvVariable("GOARCH", arch)
+}

 if component == "satellite" || component == "ground-control" {
 	var binaryFile *dagger.File
-	golang := dag.Container().
-		From("golang:latest").
-		WithMountedCache("/go/pkg/mod", dag.CacheVolume("go-mod")).
-		WithEnvVariable("GOMODCACHE", "/go/pkg/mod").
-		WithMountedCache("/go/build-cache", dag.CacheVolume("go-build")).
-		WithEnvVariable("GOCACHE", "/go/build-cache").
-		WithMountedDirectory(PROJ_MOUNT, source).
-		WithWorkdir(PROJ_MOUNT).
-		WithEnvVariable("GOOS", os).
-		WithEnvVariable("GOARCH", arch)
+	golang := setupGolangContainer(source, os, arch)

 	if component == "ground-control" {
 		golang = golang.
 			WithWorkdir(PROJ_MOUNT + "/ground-control").
-			WithExec([]string{"ls", "-la"}).
 			WithExec([]string{"go", "mod", "download"}).
 			WithExec([]string{"go", "build", "."})

 		binaryFile = golang.File(PROJ_MOUNT + "/ground-control/ground-control")
 	} else {
 		golang = golang.
-			WithExec([]string{"ls", "-la"}).
 			WithExec([]string{"go", "mod", "download"}).
 			WithExec([]string{"go", "build", "."})

 		binaryFile = golang.File(PROJ_MOUNT + "/harbor-satellite")
 	}

Committable suggestion skipped: line range outside the PR's diff.

@bupd bupd marked this pull request as ready for review November 13, 2024 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation golang
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Getting Started Guide
1 participant