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 updates #8

Merged
merged 21 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 137 additions & 24 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ name: Build and Test App

on:
push:
branches:
- "main"
tags:
- "v*.*.*"
release:
types: [created]
pull_request:
branches: [ "main" ]

env:
REGISTRY_IMAGE: nimbleape/iceperf-agent

jobs:
test:
name: Test
Expand Down Expand Up @@ -42,39 +45,149 @@ jobs:
XIRSYS_HTTP_USERNAME: ${{ secrets.XIRSYS_HTTP_USERNAME }}
XIRSYS_HTTP_PASSWORD: ${{ secrets.XIRSYS_HTTP_PASSWORD }}
XIRSYS_REQUEST_URL: ${{ secrets.XIRSYS_REQUEST_URL }}
build:
name: Build
build-docker:
name: Build Docker
needs:
- test
concurrency:
group: ${{ github.workflow }}-${{ matrix.os }}-${{ github.ref }}
group: ${{ github.workflow }}-${{ matrix.platform }}-${{ github.ref }}
cancel-in-progress: true
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- os: macos-latest-xlarge
binary-name: iceperf-darwin-arm64
- os: windows-latest
binary-name: iceperf-windows-x86-64
- os: ubuntu-latest
binary-name: iceperf-linux-x86-64
runs-on: ${{ matrix.os }}
platform:
- linux/amd64
# - linux/arm/v6
- linux/arm/v7
- linux/arm64
# - linux/riscv64
steps:
- uses: actions/checkout@v4
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV

- name: Set up Go
uses: actions/setup-go@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
go-version: '1.22.x'
images: ${{ env.REGISTRY_IMAGE }}

- name: Install dependencies
run: go get ./cmd/iceperf
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Build
run: go build -o ${{ matrix.binary-name }} ./cmd/iceperf
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
with:
files: ${{ matrix.binary-name }}
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true

- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"

- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
runs-on: ubuntu-latest
needs:
- build-docker
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)

- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
build:
name: Build Binary
needs:
- test
concurrency:
group: ${{ github.workflow }}-${{ matrix.goos }}-${{ matrix.goarch }}-${{ github.ref }}
cancel-in-progress: true
runs-on: ubuntu-latest
strategy:
matrix:
# build and publish in parallel: linux/386, linux/amd64, linux/arm64, windows/386, windows/amd64, darwin/amd64, darwin/arm64
goos: [linux, windows, darwin]
goarch: [amd64, arm64, riscv64]
exclude:
- goarch: arm64
goos: windows
- goarch: riscv64
goos: windows
- goarch: riscv64
goos: darwin
steps:
- uses: actions/checkout@v4

# - name: Set up Go
# uses: actions/setup-go@v4
# with:
# go-version: '1.22.x'

# - name: Install dependencies
# run: go get ./cmd/iceperf

- uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
project_path: "./cmd/iceperf"
overwrite: true

# - name: Build
# run: go build -o ${{ matrix.binary-name }} ./cmd/iceperf

# - name: Release
# uses: softprops/action-gh-release@v2
# if: startsWith(github.ref, 'refs/tags/')
# with:
# files: ${{ matrix.binary-name }}
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM golang:1.22.5-bullseye AS builder

WORKDIR /app

COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .

RUN go build -o /iceperf-agent cmd/iceperf/main.go

FROM debian:bullseye-slim

WORKDIR /

RUN apt-get update && apt-get install -y ca-certificates

COPY --from=builder /iceperf-agent .

RUN ls -lsa /

ENTRYPOINT ["./iceperf-agent"]
CMD ["-config", "config.yaml"]
113 changes: 113 additions & 0 deletions adapters/api/driver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package api

import (
"encoding/json"
"errors"
"io"
"log/slog"
"net/http"
"strings"

"github.com/nimbleape/iceperf-agent/adapters"
"github.com/nimbleape/iceperf-agent/config"
"github.com/pion/webrtc/v4"
"github.com/rs/xid"
)

type Driver struct {
Config *config.ICEConfig
Logger *slog.Logger
}

type ApiIceServer struct {
URLs []string `json:"urls,omitempty"`
Username string `json:"username,omitempty"`
Credential string `json:"credential,omitempty"`
}

type ProviderRes struct {
IceServers []ApiIceServer `json:"iceServers"`
DoThroughput bool `json:"doThroughput"`
}
type ApiResponse struct {
Providers map[string]ProviderRes `json:"providers"`
Node string `json:"node"`
}

func (d *Driver) GetIceServers(testRunId xid.ID) (map[string]adapters.IceServersConfig, string, error) {
providersAndIceServers := make(map[string]adapters.IceServersConfig)

if d.Config.RequestUrl != "" {

client := &http.Client{}

req, err := http.NewRequest("POST", d.Config.RequestUrl, strings.NewReader(`{"testRunID": "`+testRunId.String()+`"}`))
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", "Bearer "+d.Config.ApiKey)

if err != nil {
// log.WithFields(log.Fields{
// "error": err,
// }).Error("Error forming http request")
return providersAndIceServers, "", err
}

res, err := client.Do(req)
if err != nil {
// log.WithFields(log.Fields{
// "error": err,
// }).Error("Error doing http response")
return providersAndIceServers, "", err
}

defer res.Body.Close()
//check the code of the response
if res.StatusCode != 200 {
err = errors.New("error from our api")
return providersAndIceServers, "", err
}

responseData, err := io.ReadAll(res.Body)
if err != nil {
// log.WithFields(log.Fields{
// "error": err,
// }).Error("Error reading http response")
return providersAndIceServers, "", err
}
// log.Info("got a response back from cloudflare api")

responseServers := ApiResponse{}
json.Unmarshal([]byte(responseData), &responseServers)

// log.WithFields(log.Fields{
// "response": responseServers,
// }).Info("http response")

node := responseServers.Node

for k, q := range responseServers.Providers {

iceServers := []webrtc.ICEServer{}
for _, r := range q.IceServers {

s := webrtc.ICEServer{
URLs: r.URLs,
}

if r.Username != "" {
s.Username = r.Username
}
if r.Credential != "" {
s.Credential = r.Credential
}
iceServers = append(iceServers, s)
}
providersAndIceServers[k] = adapters.IceServersConfig{
DoThroughput: q.DoThroughput,
IceServers: iceServers,
}
}
return providersAndIceServers, node, nil
}
return providersAndIceServers, "", nil
}
Loading
Loading