-
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 9 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,64 @@ | ||
| name: Build | ||
|
|
||
| on: | ||
| # Build only triggers once lint and test workflow successfully completes | ||
| workflow_run: | ||
| workflows: [Lint] | ||
| types: | ||
| - completed | ||
|
|
||
| jobs: | ||
| dagger-build: | ||
| dagger-build-satellite: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| packages: write | ||
| # 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' }} | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Call Dagger Function to build and publish on Github | ||
| uses: dagger/dagger-for-github@v5 | ||
| with: | ||
| version: latest | ||
| verb: call | ||
| module: github.com/container-registry/harbor-satellite | ||
| args: start --name=satellite --source=. --release=./ci --GITHUB-TOKEN=$GITHUB_TOKEN --version=$GITHUB_SHA --REPO_OWNER=$GITHUB_USERNAME --REPO_NAME=harbor-satellite --RELEASE_NAME=satellite | ||
| ### 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 }} | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| GITHUB_USERNAME: ${{ github.repository_owner }} | ||
| GITHUB_SHA: ${{ github.sha }} | ||
|
|
||
| build-ground-control: | ||
| runs-on: ubuntu-latest | ||
| # unless you specify the success on the event, | ||
| permissions: | ||
| contents: write | ||
| packages: write | ||
| # 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' }} | ||
| 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: Call Dagger Function to build and publish on Github | ||
| uses: dagger/dagger-for-github@v5 | ||
| with: | ||
| version: latest | ||
| verb: call | ||
| module: github.com/container-registry/harbor-satellite | ||
| args: start --name=ground-control --source=./ground-control --release=./ci --GITHUB-TOKEN=$GITHUB_TOKEN --version=$GITHUB_SHA --REPO_OWNER=$GITHUB_USERNAME --REPO_NAME=harbor-satellite --RELEASE_NAME=ground-control | ||
| ### 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 }} | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| GITHUB_USERNAME: ${{ github.repository_owner }} | ||
| GITHUB_SHA: ${{ github.sha }} |
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,51 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "log/slog" | ||
|
|
||
| "container-registry.com/harbor-satellite/ci/internal/dagger" | ||
| ) | ||
|
|
||
| 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 { | ||
| // Build Ground Control | ||
| slog.Info("Building Ground Control") | ||
| outputDir := m.Build(ctx, source, name) | ||
|
|
||
| release_output, err := m.Release(ctx, outputDir, release, GITHUB_TOKEN, VERSION, REPO_OWNER, REPO_NAME, RELEASE_NAME, name) | ||
| if err != nil { | ||
| slog.Error("Failed to release Ground Control") | ||
| slog.Error(err.Error()) | ||
| slog.Error((fmt.Sprintf("Release Directory: %s", release_output))) | ||
| return err | ||
| } | ||
| return nil | ||
Mehul-Kumar-27 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| 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
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,91 @@ | ||
| #!/bin/bash | ||
|
|
||
| function check_if_success() { | ||
| if [ $? -ne 0 ]; then | ||
| echo "Error running last command" | ||
| exit $? | ||
Mehul-Kumar-27 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fi | ||
| } | ||
|
|
||
| function print_help() { | ||
| echo "Usage: | ||
| ./release.sh | ||
|
|
||
| Make sure the following environment variables are set: | ||
| GITHUB_API_TOKEN - Your GitHub API token | ||
| VERSION - The tag name for the release (e.g., v1.0.0) | ||
| REPO_OWNER - The GitHub username or organization name | ||
| REPO_NAME - The repository name | ||
| RELEASE_NAME - The name of the release (e.g., \"Release v1.0.0\") | ||
| OUT_DIR - Directory containing the pre-built binaries | ||
| PRERELEASE - Set to 'true' for a prerelease, otherwise leave empty or set to 'false' | ||
|
|
||
| Example: | ||
| export GITHUB_API_TOKEN=your_token | ||
| export VERSION=v1.0.0 | ||
| export REPO_OWNER=your_username | ||
| export REPO_NAME=your_repo | ||
| export RELEASE_NAME=\"Release v1.0.0\" | ||
| export OUT_DIR=./bin | ||
| export PRERELEASE=false | ||
| ./release.sh" | ||
| } | ||
|
|
||
| if [ "$1" == "--help" ] || [ "-h" == "$1" ]; then | ||
| print_help | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Check for required environment variables | ||
| if [ -z "$GITHUB_API_TOKEN" ] || [ -z "$VERSION" ] || [ -z "$REPO_OWNER" ] || [ -z "$REPO_NAME" ] || [ -z "$RELEASE_NAME" ] || [ -z "$OUT_DIR" ]; then | ||
| echo "Missing one or more required environment variables." | ||
| print_help | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Tag Name: $VERSION" | ||
| echo "Release Name: $RELEASE_NAME" | ||
| echo "Prerelease: $PRERELEASE" | ||
| echo "Repo Owner: $REPO_OWNER" | ||
| echo "Repo Name: $REPO_NAME" | ||
|
|
||
| # Ensure PRERELEASE is a valid boolean value | ||
| if [ "$PRERELEASE" = "true" ]; then | ||
| PRERELEASE_JSON="true" | ||
| else | ||
| PRERELEASE_JSON="false" | ||
| fi | ||
|
|
||
| # Create GitHub release | ||
| GITHUB_URL="https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases" | ||
| JSON=$(cat <<EOF | ||
| { | ||
| "tag_name": "$VERSION", | ||
| "name": "$RELEASE_NAME", | ||
| "body": "$RELEASE_NAME", | ||
| "prerelease": $PRERELEASE_JSON | ||
| } | ||
| EOF | ||
| ) | ||
|
|
||
| echo "Creating GitHub release..." | ||
| RESP=$(curl -s -X POST --data "$JSON" -H "Content-Type: application/json" -H "Authorization: token $GITHUB_API_TOKEN" $GITHUB_URL) | ||
| check_if_success | ||
|
|
||
| UPLOAD_URL=$(echo "$RESP" | sed -n 's/.*"upload_url": "\([^{]*\){.*/\1/p') | ||
| if [ -z "$UPLOAD_URL" ]; then | ||
| echo "Failed to create release or extract upload URL." | ||
| echo "Response: $RESP" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Upload the binaries | ||
| for pkg in "$OUT_DIR"/* | ||
| do | ||
| echo "Uploading $pkg" | ||
| FILENAME=$(basename "$pkg") | ||
| UPLOAD=$(curl -s --data-binary @"$pkg" -H "Content-Type: application/octet-stream" -H "Authorization: token $GITHUB_API_TOKEN" "$UPLOAD_URL?name=$FILENAME") | ||
Mehul-Kumar-27 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| check_if_success | ||
| done | ||
|
|
||
| echo "Release $RELEASE_NAME deployed successfully." | ||
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.