-
Notifications
You must be signed in to change notification settings - Fork 55
Feat: Adding ci/cd pipeline using dagger #37
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f0a5a01
adds dagger ci for building binary and releasing them
Mehul-Kumar-27 283f6b6
release test
Mehul-Kumar-27 b413639
fixing the permission
Mehul-Kumar-27 efab9b4
fixing flow
Mehul-Kumar-27 3ad87bb
code rabbit review
Mehul-Kumar-27 5d9d16e
coderabbit fixes
Mehul-Kumar-27 654eadd
improving output handelling while running the test cases
Mehul-Kumar-27 7a41bfe
adding dagger funcitons and improving ci
Mehul-Kumar-27 71c8f5f
releasing the ground control and satellite binaries to github using d…
Mehul-Kumar-27 0d3a746
coderabbit review and added README.md for installation
Mehul-Kumar-27 5741796
fixing docker connection
Mehul-Kumar-27 ad7dee0
fixing
Mehul-Kumar-27 5d050d0
ground-control
Mehul-Kumar-27 272b7ad
fixing ground control commit
Mehul-Kumar-27 f2b274b
tempelate renaming
Mehul-Kumar-27 eb5e1fe
tags
Mehul-Kumar-27 eb9bda2
fixig the release process
Mehul-Kumar-27 8bb9651
fixing the releaes process with tag creations and version type
Mehul-Kumar-27 b4756a2
code rabbit fixes and fixing the url in goreleaser.yml
Mehul-Kumar-27 5a839e6
fixes
Mehul-Kumar-27 86381c8
adding workflow dispatch
Mehul-Kumar-27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,77 @@ | ||
| name: Build | ||
|
|
||
| on: | ||
| # Build only triggers once lint and test workflow successfully completes | ||
| workflow_run: | ||
| workflows: [Lint] | ||
| types: | ||
| - completed | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| dagger-build: | ||
| dagger-build-satellite: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| packages: write | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Build the binary for the satellite | ||
| uses: dagger/dagger-for-github@v5 | ||
| with: | ||
| version: latest | ||
| verb: call | ||
| module: github.com/container-registry/harbor-satellite | ||
| args: build --source=. --name=satellite | ||
|
|
||
| - name: Release on Github | ||
| uses: dagger/dagger-for-github@v5 | ||
| with: | ||
| version: latest | ||
| verb: call | ||
| module: github.com/container-registry/harbor-satellite | ||
| args: release --source=. --name=satellite --token=$GITHUB_TOKEN | ||
|
|
||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| GITHUB_USERNAME: ${{ github.repository_owner }} | ||
| GITHUB_SHA: ${{ github.sha }} | ||
| ### Uncomment the below line if you wish to see the traces of the workflow on dagger cloud | ||
| ### register to dagger cloud and get the token | ||
| #### https://dagger.cloud/ | ||
| # cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }} | ||
|
|
||
| build-ground-control: | ||
| runs-on: ubuntu-latest | ||
| # unless you specify the success on the event, | ||
| # 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). | ||
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | ||
| permissions: | ||
| contents: write | ||
| packages: write | ||
| steps: | ||
| - | ||
| name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| - | ||
| name: Setup go | ||
| uses: actions/setup-go@v4 | ||
| with: | ||
| go-version: '>=1.22' | ||
| - | ||
| name: Install | ||
| run: go get dagger.io/dagger@latest | ||
| - | ||
| name: Install Dagger CLI | ||
| run: cd /usr/local && { curl -L https://dl.dagger.io/dagger/install.sh | sh; cd -; } | ||
| - | ||
| name: Build with Dagger | ||
| run: dagger run go run ci/main.go | ||
|
|
||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Build the binary for ground control | ||
| uses: dagger/dagger-for-github@v5 | ||
| with: | ||
| version: latest | ||
| verb: call | ||
| module: github.com/container-registry/harbor-satellite | ||
| args: build --source=./ground-control --name=ground-control | ||
|
|
||
| - name: Release on Github | ||
| uses: dagger/dagger-for-github@v5 | ||
| with: | ||
| version: latest | ||
| verb: call | ||
| module: github.com/container-registry/harbor-satellite | ||
| args: release --source=. --name=ground-control --token=$GITHUB_TOKEN | ||
|
|
||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| GITHUB_USERNAME: ${{ github.repository_owner }} | ||
| GITHUB_SHA: ${{ github.sha }} | ||
| ### Uncomment the below line if you wish to see the traces of the workflow on dagger cloud | ||
| ### register to dagger cloud and get the token | ||
| #### https://dagger.cloud/ | ||
| # cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,4 +25,6 @@ go.work | |
| dist/ | ||
|
|
||
| # Remove DS_Store | ||
| .DS_Store | ||
| .DS_Store | ||
| zot/cache.db | ||
| secrets.txt | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # This is an example .goreleaser.yml file with some sensible defaults. | ||
| # Make sure to check the documentation at https://goreleaser.com | ||
|
|
||
| # The lines below are called `modelines`. See `:help modeline` | ||
| # Feel free to remove those if you don't want/need to use them. | ||
| # yaml-language-server: $schema=https://goreleaser.com/static/schema.json | ||
| # vim: set ts=2 sw=2 tw=0 fo=cnqoj | ||
|
|
||
| version: 2 | ||
| project_name: harbor-satellite | ||
|
|
||
| git: | ||
| ignore_tags: | ||
| - "*-ground-control" | ||
| builds: | ||
| - main: "./main.go" | ||
| binary: "{{ .Env.APP_NAME }}" | ||
| env: | ||
| - CGO_ENABLED=0 | ||
| ldflags: | ||
| - -w -s -X github.com/container-registry/harbor-satellite/internal/version.GitCommit={{.FullCommit}} | ||
| goos: | ||
| - linux | ||
| - darwin | ||
| goarch: | ||
| - amd64 | ||
| - arm64 | ||
| ignore: | ||
| - goos: windows | ||
| goarch: arm | ||
| - goos: windows | ||
| goarch: arm64 | ||
| mod_timestamp: "{{ .CommitTimestamp }}" | ||
|
|
||
|
|
||
| release: | ||
| name_template: "{{ .Tag }}" | ||
|
|
||
| archives: | ||
| - format: tar.gz | ||
| # this name template makes the OS and Arch compatible with the results of `uname`. | ||
| name_template: >- | ||
| {{ .Env.APP_NAME }}_ | ||
| {{- title .Os }}_ | ||
| {{- if eq .Arch "amd64" }}x86_64 | ||
| {{- else if eq .Arch "386" }}i386 | ||
| {{- else }}{{ .Arch }}{{ end }} | ||
| {{- if .Arm }}v{{ .Arm }}{{ end }} | ||
| # use zip for windows archives | ||
| format_overrides: | ||
| - goos: windows | ||
| format: zip | ||
|
|
||
| changelog: | ||
| sort: asc | ||
| filters: | ||
| exclude: | ||
| - "^docs:" | ||
| - "^test:" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /dagger.gen.go linguist-generated | ||
| /internal/dagger/** linguist-generated | ||
| /internal/querybuilder/** linguist-generated | ||
| /internal/telemetry/** linguist-generated |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /dagger.gen.go | ||
| /internal/dagger | ||
| /internal/querybuilder | ||
| /internal/telemetry |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Harbor Satellite CI/CD Pipeline | ||
|
|
||
| This repository uses [Dagger](https://docs.dagger.io/) for testing, building, and releasing Harbor Satellite. | ||
|
|
||
| ## Setting Up Dagger for Harbor Satellite | ||
|
|
||
| Follow the steps below to set up Dagger: | ||
|
|
||
| ### 1. Install Dagger CLI | ||
|
|
||
| Choose your operating system and install the Dagger CLI: | ||
|
|
||
| - **macOS:** | ||
| ```sh | ||
| brew install dagger/tap/dagger | ||
| - **Windows:** | ||
| ```sh | ||
| Invoke-WebRequest -UseBasicParsing -Uri https://dl.dagger.io/dagger/install.ps1 | Invoke-Expression; Install-Dagger | ||
| - **Linux:** | ||
| ```sh | ||
| curl -L https://dl.dagger.io/dagger/install.sh | BIN_DIR=$HOME/.local/bin sh | ||
|
|
||
| ### 2. Verify Installation | ||
| Run the following command to verify the Dagger installation: | ||
| - ```sh | ||
| dagger --version | ||
| If you encounter any errors, refer to the [detailed installation guide](https://docs.dagger.io/install). | ||
|
|
||
| ### 3. Generate Go Code | ||
| Once the Dagger CLI is installed, navigate to the root folder of harbor-satellite and run: | ||
|
|
||
| - ```sh | ||
| dagger develop | ||
|
|
||
| This command will generate Go code in the ./ci folder. | ||
|
|
||
| ### 4. Folder Structure | ||
| After running dagger develop, your ./ci folder should contain the following structure: | ||
| - ```sh | ||
| ci/ | ||
| ├── dagger.gen.go | ||
| ├── ground_control.go | ||
| ├── internal | ||
| │ ├── dagger | ||
| │ ├── querybuilder | ||
| │ └── telemetry | ||
| ├── satellite.go | ||
| ├── README.md | ||
| ├── release.sh | ||
| └── utils.go | ||
| If you encounter any issues during this process, consult the [Dagger Quickstart Guide](https://docs.dagger.io/quickstart/daggerize) for more detailed instructions. | ||
|
|
||
| ## Running Dagger Functions | ||
| To view available functions, run: | ||
| - ```sh | ||
| dagger functions | ||
| To run a particular function, run: | ||
| - ```sh | ||
| dagger call <function_name> --args | ||
| - #### Example: Building Satellite Binaries | ||
| To build the satellite binaries, use the following command: | ||
| - ```sh | ||
| dagger call build --source=. --name=satellite export --path=./bin | ||
| This would spin up a container and install required dependencies and build various architecture binaries and export them to the host on path ./bin for testing on the host. | ||
| - #### Example: Releasing to GitHub | ||
| To release the project on GitHub, use the following command | ||
| - ```sh | ||
| dagger call release --directory=. --token=<your_github_token> --name=satellite | ||
| The above function would then proceed to release the project on github for the name provided. The above function also takes argument `--release-type` which would tell the release what kind of release it is i.e major, minor or path, The default value is set to be path release | ||
| - #### Example: Releasing to GitHub with type of release | ||
| To release the project on GitHub, use the following command | ||
| - ```sh | ||
| dagger call release --directory=. --token=<your_github_token> --name=satellite --release-type=minor | ||
| The above function would release the minor version for the project mentioned | ||
Mehul-Kumar-27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "container-registry.com/harbor-satellite/ci/internal/dagger" | ||
| ) | ||
|
|
||
| // Would execute the tests for the ground control. Source should be the path to the path to main.go file. | ||
| func (m *HarborSatellite) ExecuteTestsForGroundControl(ctx context.Context, source *dagger.Directory) (string, error) { | ||
| goContainer := dag.Container(). | ||
Mehul-Kumar-27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| From(DEFAULT_GO) | ||
|
|
||
| containerWithDocker, err := m.Attach(ctx, goContainer, "24.0") | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
Mehul-Kumar-27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| dockerHost, err := containerWithDocker.EnvVariable(ctx, "DOCKER_HOST") | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| fmt.Printf("Docker Host: %s\n", dockerHost) | ||
|
|
||
| goContainer = containerWithDocker. | ||
| WithMountedDirectory("/app", source). | ||
| WithWorkdir("/app"). | ||
| WithExec([]string{"go", "test", "./..."}) | ||
|
|
||
| output, err := goContainer.Stdout(ctx) | ||
| if err != nil { | ||
| return output, err | ||
| } | ||
| fmt.Print(output) | ||
| return output, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.