Skip to content

Commit 1ba5fb4

Browse files
adding quickstart guide and fixing the ci process (#71)
1 parent dc2d7f0 commit 1ba5fb4

File tree

4 files changed

+143
-154
lines changed

4 files changed

+143
-154
lines changed

QUICKSTART.md

Lines changed: 143 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ In this guide, we'll use a Harbor registry instance.
1616
### 3. Configure Ground Control
1717
Navigate to the `ground-control` directory and set up the following environment variables:
1818

19+
- For running ground control using Dagger
20+
1921
```bash
2022
HARBOR_USERNAME=admin
2123
HARBOR_PASSWORD=Harbor12345
@@ -31,6 +33,23 @@ DB_USERNAME=postgres # Customize based on your DB config
3133
DB_PASSWORD=password # Customize based on your DB config
3234
```
3335

36+
- For running ground control without Dagger
37+
38+
```bash
39+
HARBOR_USERNAME=admin
40+
HARBOR_PASSWORD=Harbor12345
41+
HARBOR_URL=https://demo.goharbor.io
42+
43+
PORT=8080
44+
APP_ENV=local
45+
46+
DB_HOST=127.0.0.1
47+
DB_PORT=8100
48+
DB_DATABASE=groundcontrol
49+
DB_USERNAME=postgres # Customize based on your DB config and add the same config to the docker-compose file
50+
DB_PASSWORD=password # Customize based on your DB config and add the same config to the docker-compose file
51+
```
52+
3453
### 4. Run Ground Control
3554
To start the Ground Control service, execute the following Dagger command:
3655

@@ -52,66 +71,156 @@ To Run ground-control binary use
5271

5372
> **Note:** Ensure you have set up Dagger with the latest version before running this command. Ground Control will run on port 8080.
5473
55-
### 5. Configure Satellite
56-
Return to the root project directory:
74+
#### Without Using Dagger
75+
76+
To start the Ground Control service without using Dagger, follow these steps:
77+
First, move to the ground-control directory
5778

5879
```bash
5980
cd ..
6081
```
6182

62-
Then navigate to the `satellite` directory and verify that `config.toml` is set up correctly:
83+
Then add the credentials to the `docker-compose` file for the Postgres service and pgAdmin, and start the services using. Make sure you add the same credentials that you have added in the .env file
6384

64-
```toml
65-
# Whether to use the built-in Zot registry or not
66-
bring_own_registry = false
85+
```bash
86+
docker compose up
87+
```
6788

68-
# IP address and port of the registry
69-
own_registry_adr = "127.0.0.1"
70-
own_registry_port = "8585"
89+
Once the services are up, move to the `sql/schema` folder to set up the database required for the ground control
7190

72-
# URL of remote registry or local file path
73-
url_or_file = "https://demo.goharbor.io/v2/myproject/album-server"
91+
```bash
92+
cd sql/schema
93+
```
7494

95+
Install `goose` to run database migrations if not already installed
7596

97+
```bash
98+
go install github.com/pressly/goose/v3/cmd/goose@latest
99+
```
76100

77-
# Default path for Zot registry config.json
78-
zotConfigPath = "./registry/config.json"
101+
Now run the below command with the credentials that you have added in the docker-compose file
79102

80-
# Set logging level
81-
log_level = "info"
103+
```bash
104+
goose postgres "postgres://<POSTGRES_USER>:<POSTGRES_PASSWORD>@localhost:8100/groundcontrol?sslmode=disable" up
82105
```
83106

84-
### 6. Register the Satellite with Ground Control
85-
Using `curl` or Postman, make a `POST` request to register the Satellite with Ground Control:
107+
Now you can start the `ground-control` using the below command by first moving to the directory and running
86108

87109
```bash
88-
curl -X POST http://localhost:8080/satellites/register -H "Content-Type: application/json" -d '{ "name": "<satellite_name_here>" }'
110+
cd ../..
111+
go run main.go
89112
```
90113

91-
The response will include a token string. Set this token in the Satellite `.env` file:
114+
### 6. Register the Satellite with Ground Control
92115

93-
```console
94-
TOKEN=<string_from_ground_control>
95-
```
116+
Once the ground control is up and running, you can check its health status using the following curl command
96117

97-
### 7. Build the Satellite
98-
Run the following Dagger command to build the Satellite:
118+
To test the health of the server, use the following `curl` command:
99119

100120
```bash
101-
dagger call build-dev --platform "linux/amd64" --component satellite export --path=./satellite-dev
121+
curl --location 'http://localhost:8080/health'
102122
```
103123

104-
To Run Satellite:
124+
- Now we create a group. To create a group, use the following `curl` command
125+
> **Note:** Please modify the body given below according to your registry
126+
``` bash
127+
curl --location 'http://localhost:8080/groups/sync' \
128+
--header 'Content-Type: application/json' \
129+
--data '{
130+
"group": "GROUP_NAME",
131+
"registry": "YOUR_REGISTRY_URL",
132+
"artifacts": [
133+
{
134+
"repository": "YOUR_PROJECT/YOUR_IMAGE",
135+
"tag": ["TAGS OF THE IMAGE"],
136+
"type": TYPE_OF_IMAGE,
137+
"digest": "DIGEST",
138+
"deleted": false
139+
}
140+
]
141+
}
142+
'
143+
```
144+
Example Curl Command for creating `GROUP`
105145
```bash
106-
./satellite-dev
146+
curl --location 'http://localhost:8080/groups/sync' \
147+
--header 'Content-Type: application/json' \
148+
--data '{
149+
"group": "group1",
150+
"registry": "https://demo.goharbor.io",
151+
"artifacts": [
152+
{
153+
"repository": "alpine/alpine",
154+
"tag": ["latest"],
155+
"type": "docker",
156+
"digest": "sha256:3e21c52835bab96cbecb471e3c3eb0e8a012b91ba2f0b934bd0b5394cd570b9f",
157+
"deleted": false
158+
}
159+
]
160+
}
161+
'
107162
```
163+
- Once the group is created, now we would add a satellite to the group so that the satellite would be available to track the images/artifacts present in the group
108164

109-
The Satellite service will start on port 9090. Ensure that the `ground_control_url` is correctly set in the Satellite configuration before launching.
110-
165+
Below curl command is used to register a satellite which also provides the authentication token for the satellite
166+
```bash
167+
curl --location 'http://localhost:8080/satellites/register' \
168+
--header 'Content-Type: application/json' \
169+
--data '{
170+
"name": "SATELLITE_NAME",
171+
"groups": ["GROUP_NAME"]
172+
}'
173+
```
174+
> **Note**: Running the above command would produce a token which is important for the satellite to register itself to the ground control
175+
- Once you have the token for the satellite, we can move on to the satellite to configure it.
176+
### 6. Configure Satellite
111177

112-
### 8. Finalize and Run
113-
After setting the token, you can now run the Satellite. This setup will launch the Satellite in a container with the following exposed ports:
114-
- **9090** for the Satellite service.
115-
- **8585** for the Zot registry (if configured).
178+
Return to the root project directory:
116179

117-
With this setup, your Harbor Satellite should be up and running!
180+
In the `config.json` file, add the following configuration
181+
182+
```json
183+
{
184+
"environment_variables": {
185+
"ground_control_url": "http://127.0.0.1:8080", // URL for the ground control server
186+
"log_level": "info", // Log level: can be "debug", "info", "warn", or "error"
187+
"use_unsecure": true, // Use unsecure connections (set to true for dev environments)
188+
"zot_config_path": "./registry/config.json", // Path to Zot registry configuration file
189+
"token":"ADD_THE_TOKEN_FROM_THE_ABOVE_STEP", // add the token received while registering satellite from the below step
190+
"jobs": [
191+
// List of scheduled jobs
192+
// Checkout https://pkg.go.dev/github.com/robfig/cron#hdr-Predefined_schedules for more
193+
// details on how to write the cron job config
194+
{
195+
"name": "replicate_state", // Job to replicate state
196+
"schedule": "@every 00h00m10s" // Schedule interval: every 10 seconds
197+
},
198+
{
199+
"name": "update_config", // Job to update configuration
200+
"schedule": "@every 00h00m30s" // Schedule interval: every 30 seconds
201+
},
202+
{
203+
"name": "register_satellite", // Job to register satellite
204+
"schedule": "@every 00h00m05s" // Schedule interval: every 5 seconds
205+
}
206+
],
207+
"local_registry": {
208+
// Configuration for the local registry
209+
"url": "", // Add your own registry URL if bring_own_registry is true else leave blank
210+
"username": "", // Add your own registry username if bring_own_registry is true else leave blank
211+
"password": "", // Add your own registry password if bring_own_registry is true else leave blank
212+
"bring_own_registry": false // Set to true if using an external registry and the above config
213+
}
214+
}
215+
}
216+
```
217+
- Now start the satellite using the following command
218+
```bash
219+
go run main.go
220+
```
221+
> **Note**: You can also build the satellite binaries and use them.
222+
- To build the binary of the satellite, use the following command
223+
```bash
224+
dagger call build --source=. --name=satellite export --path=./bin
225+
```
226+
- This would generate the binaries for various architectures in the `bin` folder. Choose the binary for your system and use it. Make sure that the `config.json` and the binary directory are the same when running it otherwise it would throw an error.

ci/ground_control.go

Lines changed: 0 additions & 36 deletions
This file was deleted.

ci/satellite.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

ci/utils.go

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,6 @@ import (
1010
"container-registry.com/harbor-satellite/ci/internal/dagger"
1111
)
1212

13-
// Attach would attach a docker as a service to the container provided.
14-
func (m *HarborSatellite) Attach(ctx context.Context, container *dagger.Container, dockerVersion string) (*dagger.Container, error) {
15-
dockerd := m.Service(dockerVersion)
16-
17-
dockerd, err := dockerd.Start(ctx)
18-
if err != nil {
19-
return nil, err
20-
}
21-
22-
dockerHost, err := dockerd.Endpoint(ctx, dagger.ServiceEndpointOpts{
23-
Scheme: "tcp",
24-
})
25-
if err != nil {
26-
return nil, err
27-
}
28-
29-
return container.
30-
WithServiceBinding("docker", dockerd).
31-
WithEnvVariable("DOCKER_HOST", dockerHost), nil
32-
}
33-
34-
// Get a Service container running dockerd
35-
func (m *HarborSatellite) Service(
36-
// +optional
37-
// +default="24.0"
38-
dockerVersion string,
39-
) *dagger.Service {
40-
port := 2375
41-
return dag.Container().
42-
From(fmt.Sprintf("docker:%s", dockerVersion)).
43-
WithMountedCache(
44-
"/var/lib/docker",
45-
dag.CacheVolume(dockerVersion+"-docker-lib"),
46-
dagger.ContainerWithMountedCacheOpts{
47-
Sharing: dagger.Private,
48-
}).
49-
WithExposedPort(port).
50-
WithExec([]string{
51-
"dockerd",
52-
"--host=tcp://0.0.0.0:2375",
53-
"--host=unix:///var/run/docker.sock",
54-
"--tls=false",
55-
}, dagger.ContainerWithExecOpts{
56-
InsecureRootCapabilities: true,
57-
}).
58-
AsService()
59-
}
6013

6114
// builds given component from source
6215
func (m *HarborSatellite) build(source *dagger.Directory, component string) *dagger.Directory {

0 commit comments

Comments
 (0)