Skip to content

Commit

Permalink
fix: log into registry.redhat.io
Browse files Browse the repository at this point in the history
Signed-off-by: Matej Vasek <[email protected]>
  • Loading branch information
matejvasek committed Aug 24, 2023
1 parent c6d3de9 commit 253edc3
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test-e2e-oncluster-runtime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ jobs:
run: ./hack/create-testing-func-image.sh
- name: Allocate Cluster
run: ./hack/allocate.sh
- name: Pull secrets for KinD cluster
env:
RH_REG_USR: ${{ secrets.RH_REG_USR }}
RH_REG_PWD: ${{ secrets.RH_REG_PWD }}
run: go run ./hack/kind_pull_secrtes.go
- name: Deploy Tekton
run: ./hack/tekton.sh
- name: Deploy Test Git Server
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/test-e2e-oncluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ jobs:
run: ./hack/create-testing-func-image.sh
- name: Allocate Cluster
run: ./hack/allocate.sh
- name: Pull secrets for KinD cluster
env:
RH_REG_USR: ${{ secrets.RH_REG_USR }}
RH_REG_PWD: ${{ secrets.RH_REG_PWD }}
run: go run ./hack/kind_pull_secrtes.go
- name: Deploy Tekton
run: ./hack/tekton.sh
- name: Deploy Test Git Server
Expand Down
73 changes: 73 additions & 0 deletions hack/kind_pull_secrtes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package main

Check failure on line 1 in hack/kind_pull_secrtes.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

: # knative.dev/func/hack

import (
"archive/tar"
"bytes"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"os"
"os/signal"
"syscall"

"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
)

func main() {

Check failure on line 18 in hack/kind_pull_secrtes.go

View workflow job for this annotation

GitHub Actions / Check Source (1.20.2, ubuntu-latest)

other declaration of main (typecheck)

Check failure on line 18 in hack/kind_pull_secrtes.go

View workflow job for this annotation

GitHub Actions / analyze / Go vulnerability Detection

other declaration of main

Check failure on line 18 in hack/kind_pull_secrtes.go

View workflow job for this annotation

GitHub Actions / build / Build

other declaration of main

Check failure on line 18 in hack/kind_pull_secrtes.go

View workflow job for this annotation

GitHub Actions / Unit Test (1.20.2, 17, ubuntu-latest)

other declaration of main

Check failure on line 18 in hack/kind_pull_secrtes.go

View workflow job for this annotation

GitHub Actions / Unit Test (1.20.2, 17, windows-latest)

other declaration of main

Check failure on line 18 in hack/kind_pull_secrtes.go

View workflow job for this annotation

GitHub Actions / Unit Test (1.20.2, 17, macos-latest)

other declaration of main

Check failure on line 18 in hack/kind_pull_secrtes.go

View workflow job for this annotation

GitHub Actions / test / Unit Tests

other declaration of main

Check failure on line 18 in hack/kind_pull_secrtes.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

other declaration of main (typecheck)

Check failure on line 18 in hack/kind_pull_secrtes.go

View workflow job for this annotation

GitHub Actions / Podman Test (1.20.2, ubuntu-latest)

other declaration of main

Check failure on line 18 in hack/kind_pull_secrtes.go

View workflow job for this annotation

GitHub Actions / Integration Test (1.20.2, ubuntu-latest)

other declaration of main
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel()
err := copySecrets(ctx)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}

func copySecrets(ctx context.Context) error {
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
return fmt.Errorf("cannot get docker client: %w", err)
}

auth := base64.StdEncoding.EncodeToString([]byte(os.Getenv("RH_REG_USR") + ":" + os.Getenv("RH_REG_PWD")))

config := map[string]any{
"auths": map[string]any{
"registry.redhat.io": map[string]string{"auth": auth},
},
}

configData, err := json.Marshal(&config)
if err != nil {
return fmt.Errorf("cannot marshal config: %w", err)
}

var buff bytes.Buffer
tw := tar.NewWriter(&buff)
err = tw.WriteHeader(&tar.Header{
Name: "config.json",
Typeflag: tar.TypeReg,
Size: int64(len(configData)),
Mode: 0600,
})
if err != nil {
return fmt.Errorf("cannot write tar header: %w", err)
}
_, err = tw.Write(configData)
if err != nil {
return fmt.Errorf("cannot write file to tar: %w", err)
}
err = tw.Close()
if err != nil {
return fmt.Errorf("cannot close tar: %w", err)
}

err = cli.CopyToContainer(ctx, "func-control-plane", "/var/lib/kubelet/", &buff, types.CopyToContainerOptions{})
if err != nil {
return fmt.Errorf("cannot copy to container: %w", err)
}

return nil
}

0 comments on commit 253edc3

Please sign in to comment.