Skip to content

Commit 7a41bfe

Browse files
adding dagger funcitons and improving ci
1 parent 654eadd commit 7a41bfe

File tree

14 files changed

+410
-421
lines changed

14 files changed

+410
-421
lines changed

.github/workflows/build.yaml

Lines changed: 11 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -9,86 +9,25 @@ on:
99
jobs:
1010
dagger-build-satellite:
1111
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
packages: write
1215
# unless you specify the success on the event,
1316
# this job will also run if the lint workflow was skipped(which is also the case if the condition for the file extension type is false).
14-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
17+
# if: ${{ github.event.workflow_run.conclusion == 'success' }}
1518
steps:
1619
- name: Checkout repository
1720
uses: actions/checkout@v4
1821

19-
- name: Setup Go
20-
uses: actions/setup-go@v4
22+
- name: Call Dagger Function to build and publish on Github
23+
uses: dagger/dagger-for-github@v5
2124
with:
22-
go-version: '>=1.22'
23-
24-
- name: Update CA certificates
25-
run: |
26-
sudo apt-get update
27-
sudo apt-get install -y ca-certificates
28-
sudo update-ca-certificates
29-
30-
- name: Install curl and Docker
31-
run: |
32-
sudo apt-get install -y curl
33-
curl -fsSL https://get.docker.com -o get-docker.sh
34-
sudo sh get-docker.sh
35-
36-
- name: Verify Docker installation
37-
run: docker --version
38-
39-
- name: Install Dagger CLI
40-
run: |
41-
cd /usr/local
42-
curl -L https://dl.dagger.io/dagger/install.sh | DAGGER_VERSION=0.12.3 sudo sh
43-
cd -
44-
45-
- name: Build Satellite with Dagger
46-
run: dagger run go run ci/main.go satellite
47-
env:
48-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49-
GITHUB_USERNAME: ${{ github.repository_owner }}
50-
GITHUB_REPOSITORY: ${{ github.repository }}
51-
GITHUB_SHA: ${{ github.sha }}
52-
53-
dagger-build-ground-control:
54-
# unless you specify the success on the event,
55-
# this job will also run if the lint workflow was skipped(which is also the case if the condition for the file extension type is false).
56-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
57-
runs-on: ubuntu-latest
58-
steps:
59-
- name: Checkout repository
60-
uses: actions/checkout@v4
61-
62-
- name: Setup Go
63-
uses: actions/setup-go@v4
64-
with:
65-
go-version: '>=1.22'
66-
67-
- name: Update CA certificates
68-
run: |
69-
sudo apt-get update
70-
sudo apt-get install -y ca-certificates
71-
sudo update-ca-certificates
72-
73-
- name: Install curl and Docker
74-
run: |
75-
sudo apt-get install -y curl
76-
curl -fsSL https://get.docker.com -o get-docker.sh
77-
sudo sh get-docker.sh
78-
79-
- name: Verify Docker installation
80-
run: docker --version
81-
82-
- name: Install Dagger CLI
83-
run: |
84-
cd /usr/local
85-
curl -L https://dl.dagger.io/dagger/install.sh | DAGGER_VERSION=0.12.3 sudo sh
86-
cd -
87-
88-
- name: Build Ground Control with Dagger
89-
run: dagger run go run ci/main.go ground-control
25+
version: latest
26+
verb: call
27+
module: github.com/Mehul-Kumar/harbor-satellite
28+
args: start --name=satellite --source=. --release=./ci --GITHUB-TOKEN=env:GITHUB_TOKEN --version=$GITHUB_SHA --REPO_OWNER=$GITHUB_USERNAME --REPO_NAME=harbor-satellite --RELEASE_NAME=satellite
29+
cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }}
9030
env:
9131
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9232
GITHUB_USERNAME: ${{ github.repository_owner }}
93-
GITHUB_REPOSITORY: ${{ github.repository }}
9433
GITHUB_SHA: ${{ github.sha }}

ci/.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/dagger.gen.go linguist-generated
2+
/internal/dagger/** linguist-generated
3+
/internal/querybuilder/** linguist-generated
4+
/internal/telemetry/** linguist-generated

ci/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/dagger.gen.go
2+
/internal/dagger
3+
/internal/querybuilder
4+
/internal/telemetry

ci/config/config.go

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

ci/ground_control.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"log/slog"
7+
8+
"container-registry.com/harbor-satellite/ci/internal/dagger"
9+
)
10+
11+
func (m *HarborSatellite) StartGroundControlCI(ctx context.Context, source *dagger.Directory, release *dagger.Directory, GITHUB_TOKEN, VERSION, REPO_OWNER, REPO_NAME, RELEASE_NAME, name string) error {
12+
// Build Ground Control
13+
slog.Info("Building Ground Control")
14+
outputDir := m.Build(ctx, source, name)
15+
16+
release_output, err := m.Release(ctx, outputDir, release, GITHUB_TOKEN, VERSION, REPO_OWNER, REPO_NAME, RELEASE_NAME, name)
17+
if err != nil {
18+
slog.Error("Failed to release Ground Control")
19+
slog.Error(err.Error())
20+
slog.Error((fmt.Sprintf("Release Directory: %s", release_output)))
21+
return err
22+
}
23+
return nil
24+
}
25+
26+
func (m *HarborSatellite) ExecuteTestsForGroundControl(ctx context.Context, source *dagger.Directory) (string, error) {
27+
goContainer := dag.Container().
28+
From(DEFAULT_GO)
29+
30+
containerWithDocker, err := m.Attach(ctx, goContainer, "24.0")
31+
if err != nil {
32+
return "", err
33+
}
34+
dockerHost, err := containerWithDocker.EnvVariable(ctx, "DOCKER_HOST")
35+
if err != nil {
36+
return "", err
37+
}
38+
fmt.Printf("Docker Host: %s\n", dockerHost)
39+
40+
goContainer = containerWithDocker.
41+
WithMountedDirectory("/app", source).
42+
WithWorkdir("/app").
43+
WithExec([]string{"go", "test", "./..."})
44+
45+
output, err := goContainer.Stdout(ctx)
46+
if err != nil {
47+
return output, err
48+
}
49+
fmt.Print(output)
50+
return output, nil
51+
}

ci/ground_control/ground_control.go

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

0 commit comments

Comments
 (0)