Skip to content

Commit

Permalink
Merge branch 'release/2.6.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamDumpleton committed Sep 8, 2023
2 parents b336721 + 430a73b commit c908030
Show file tree
Hide file tree
Showing 45 changed files with 8,082 additions and 102 deletions.
112 changes: 111 additions & 1 deletion .github/workflows/build-and-publish-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,34 @@ jobs:
name: educates-linux-amd64
path: client-programs/educates-linux-amd64

build-client-programs-linux-arm64:
name: Build (clients) / arm64@linux
runs-on: ubuntu-latest

steps:
- name: Check out the repository
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: "1.19.0"

- name: Build educates client program
shell: bash
run: |
rm -rf client-programs/pkg/renderer/files
mkdir client-programs/pkg/renderer/files
cp -rp workshop-images/base-environment/opt/eduk8s/etc/themes client-programs/pkg/renderer/files/
cd client-programs
REPOSITORY_TAG=${GITHUB_REF##*/}
GOOS=linux GOARCH=arm64 go build -o educates-linux-arm64 -ldflags "-X 'main.projectVersion=$REPOSITORY_TAG'" cmd/educates/main.go
- uses: actions/upload-artifact@v3
with:
name: educates-linux-arm64
path: client-programs/educates-linux-arm64

build-client-programs-darwin-amd64:
name: Build (clients) / amd64@darwin
runs-on: macos-latest
Expand Down Expand Up @@ -391,8 +419,8 @@ jobs:
name: Programs
runs-on: ubuntu-latest
needs:
- publish-carvel-bundles
- build-client-programs-linux-amd64
- build-client-programs-linux-arm64
- build-client-programs-darwin-amd64
- build-client-programs-darwin-arm64

Expand All @@ -403,6 +431,12 @@ jobs:
name: educates-linux-amd64
path: client-programs

- name: Restore educates-linux-arm64
uses: actions/download-artifact@v3
with:
name: educates-linux-arm64
path: client-programs

- name: Restore educates-darwin-amd64
uses: actions/download-artifact@v3
with:
Expand Down Expand Up @@ -434,15 +468,75 @@ jobs:
--registry-username=${{github.actor}} \
--registry-password=${{secrets.GITHUB_TOKEN}}
publish-docker-extension:
name: Extension
runs-on: ubuntu-latest
needs:
- publish-client-programs

steps:
- name: Check out the repository
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker buildx
uses: docker/setup-buildx-action@v2
# related issues for pinning buildkit
# https://github.com/docker/build-push-action/issues/761
# https://github.com/containerd/containerd/issues/7972
# https://github.com/containerd/containerd/pull/6995
with:
driver-opts: |
image=moby/buildkit:v0.10.6
- name: Generate container image metadata
id: meta
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/${{github.repository_owner}}/educates-docker-extension
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
- name: Login to GitHub container registry
uses: docker/login-action@v2
with:
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
registry: ghcr.io

- name: Calculate variables
shell: bash
run: |
echo "REPOSITORY_TAG=${GITHUB_REF##*/}" >>${GITHUB_ENV}
- name: Build and push docker-extension image
uses: docker/build-push-action@v3
with:
context: docker-extension
platforms: linux/amd64,linux/arm64
build-args: |
REPOSITORY=ghcr.io/${{github.repository_owner}}
TAG=${{env.REPOSITORY_TAG}}
tags: ${{steps.meta.outputs.tags}}
push: true

release-artifacts:
name: Release
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs:
- publish-carvel-bundles
- build-client-programs-linux-amd64
- build-client-programs-linux-arm64
- build-client-programs-darwin-amd64
- build-client-programs-darwin-arm64
- publish-docker-extension

steps:
- name: Restore educates-cluster-essentials.yaml
Expand All @@ -460,6 +554,11 @@ jobs:
with:
name: educates-linux-amd64

- name: Restore educates-linux-arm64
uses: actions/download-artifact@v3
with:
name: educates-linux-arm64

- name: Restore educates-darwin-amd64
uses: actions/download-artifact@v3
with:
Expand All @@ -479,6 +578,7 @@ jobs:
shell: bash
run: |
sha256sum educates-linux-amd64 >> checksums.txt
sha256sum educates-linux-arm64 >> checksums.txt
sha256sum educates-darwin-amd64 >> checksums.txt
sha256sum educates-darwin-arm64 >> checksums.txt
echo "```" >> release-notes.md
Expand Down Expand Up @@ -537,6 +637,16 @@ jobs:
asset_name: educates-linux-amd64
asset_content_type: application/octet-stream

- name: Upload educates-linux-arm64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
upload_url: ${{steps.create_release.outputs.upload_url}}
asset_path: educates-linux-arm64
asset_name: educates-linux-arm64
asset_content_type: application/octet-stream

- name: Upload educates-darwin-amd64
uses: actions/upload-release-asset@v1
env:
Expand Down
20 changes: 19 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,28 @@ build-client-programs: client-programs-educates

push-client-programs : build-client-programs
ifeq ($(UNAME_SYSTEM),darwin)
(cd client-programs; GOOS=linux GOARCH=$(TARGET_MACHINE) go build -o bin/educates-linux-$(TARGET_MACHINE) cmd/educates/main.go)
(cd client-programs; GOOS=linux GOARCH=amd64 go build -o bin/educates-linux-amd64 cmd/educates/main.go)
(cd client-programs; GOOS=linux GOARCH=arm64 go build -o bin/educates-linux-arm64 cmd/educates/main.go)
endif
ifeq ($(UNAME_SYSTEM),linux)
ifeq ($(TARGET_PLATFORM),arm64)
(cd client-programs; GOOS=linux GOARCH=amd64 go build -o bin/educates-linux-amd64 cmd/educates/main.go)
endif
ifeq ($(TARGET_PLATFORM),amd64)
(cd client-programs; GOOS=linux GOARCH=arm64 go build -o bin/educates-linux-arm64 cmd/educates/main.go)
endif
endif
imgpkg push -i $(IMAGE_REPOSITORY)/educates-client-programs:$(PACKAGE_VERSION) -f client-programs/bin

build-docker-extension : push-client-programs
$(MAKE) -C docker-extension build-extension REPOSITORY=$(IMAGE_REPOSITORY) TAG=$(PACKAGE_VERSION)

install-docker-extension : build-docker-extension
$(MAKE) -C docker-extension install-extension REPOSITORY=$(IMAGE_REPOSITORY) TAG=$(PACKAGE_VERSION)

update-docker-extension : build-docker-extension
$(MAKE) -C docker-extension update-extension REPOSITORY=$(IMAGE_REPOSITORY) TAG=$(PACKAGE_VERSION)

deploy-workshop:
kubectl apply -f https://github.com/vmware-tanzu-labs/lab-k8s-fundamentals/releases/download/5.0/workshop.yaml
kubectl apply -f https://github.com/vmware-tanzu-labs/lab-k8s-fundamentals/releases/download/5.0/trainingportal.yaml
Expand Down
36 changes: 34 additions & 2 deletions client-programs/pkg/cmd/cluster_workshop_deploy_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type ClusterWorkshopDeployOptions struct {
Orphaned string
Overdue string
Refresh string
Repository string
Environ []string
WorkshopFile string
WorkshopVersion string
Expand Down Expand Up @@ -85,7 +86,7 @@ func (o *ClusterWorkshopDeployOptions) Run() error {

// Update the training portal, creating it if necessary.

err = deployWorkshopResource(dynamicClient, workshop, o.Portal, o.Capacity, o.Reserved, o.Initial, o.Expires, o.Overtime, o.Deadline, o.Orphaned, o.Overdue, o.Refresh, o.Environ)
err = deployWorkshopResource(dynamicClient, workshop, o.Portal, o.Capacity, o.Reserved, o.Initial, o.Expires, o.Overtime, o.Deadline, o.Orphaned, o.Overdue, o.Refresh, o.Repository, o.Environ)

if err != nil {
return err
Expand Down Expand Up @@ -207,6 +208,13 @@ func (p *ProjectInfo) NewClusterWorkshopDeployCmd() *cobra.Command {
"version of the workshop being published",
)

c.Flags().StringVar(
&o.Repository,
"image-repository",
"",
"the address of the image repository",
)

c.Flags().StringArrayVar(
&o.DataValuesFlags.EnvFromStrings,
"data-values-env",
Expand Down Expand Up @@ -250,7 +258,7 @@ func (p *ProjectInfo) NewClusterWorkshopDeployCmd() *cobra.Command {

var trainingPortalResource = schema.GroupVersionResource{Group: "training.educates.dev", Version: "v1beta1", Resource: "trainingportals"}

func deployWorkshopResource(client dynamic.Interface, workshop *unstructured.Unstructured, portal string, capacity uint, reserved uint, initial uint, expires string, overtime string, deadline string, orphaned string, overdue string, refresh string, environ []string) error {
func deployWorkshopResource(client dynamic.Interface, workshop *unstructured.Unstructured, portal string, capacity uint, reserved uint, initial uint, expires string, overtime string, deadline string, orphaned string, overdue string, refresh string, registry string, environ []string) error {
trainingPortalClient := client.Resource(trainingPortalResource)

trainingPortal, err := trainingPortalClient.Get(context.TODO(), portal, metav1.GetOptions{})
Expand Down Expand Up @@ -432,6 +440,11 @@ func deployWorkshopResource(client dynamic.Interface, workshop *unstructured.Uns
}
}

type RegistryDetails struct {
Host string `json:"host"`
Namespace string `json:"namespace,omitempty"`
}

type WorkshopDetails struct {
Name string `json:"name"`
Capacity int64 `json:"capacity,omitempty"`
Expand All @@ -443,6 +456,7 @@ func deployWorkshopResource(client dynamic.Interface, workshop *unstructured.Uns
Orphaned string `json:"orphaned,omitempty"`
Overdue string `json:"overdue,omitempty"`
Refresh string `json:"refresh,omitempty"`
Registry *RegistryDetails `json:"registry,omitempty"`
Environ []EnvironDetails `json:"env"`
}

Expand All @@ -464,6 +478,24 @@ func deployWorkshopResource(client dynamic.Interface, workshop *unstructured.Uns
workshopDetails.Capacity = int64(capacity)
}

if registry != "" {
parts := strings.SplitN(registry, "/", 2)

host := parts[0]
var namespace string

if len(parts) > 1 {
namespace = parts[1]
}

registryDetails := RegistryDetails{
Host: host,
Namespace: namespace,
}

workshopDetails.Registry = &registryDetails
}

var workshopDetailsMap map[string]interface{}

data, _ := json.Marshal(workshopDetails)
Expand Down
56 changes: 55 additions & 1 deletion client-programs/pkg/cmd/cluster_workshop_serve_cmd.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package cmd

import (
"io/ioutil"
"os"
"path"
"path/filepath"

"github.com/adrg/xdg"
"github.com/pkg/errors"
"github.com/spf13/cobra"
yttcmd "github.com/vmware-tanzu/carvel-ytt/pkg/cmd/template"
Expand Down Expand Up @@ -65,13 +68,53 @@ type ClusterWorkshopServeOptions struct {
LocalPort int
HugoPort int
Token string
RefreshToken bool
Files bool
WorkshopFile string
WorkshopVersion string
PatchWorkshop bool
DataValuesFlags yttcmd.DataValuesFlags
}

func generateAccessToken(refresh bool) (string, error) {
configFileDir := path.Join(xdg.DataHome, "educates")
accessTokenFile := path.Join(configFileDir, "live-reload-token.dat")

var accessToken string

if refresh {
accessToken = randomPassword(32)

err := ioutil.WriteFile(accessTokenFile, []byte(accessToken), 0644)

if err != nil {
return "", err
}
} else {
if _, err := os.Stat(accessTokenFile); err == nil {
accessTokenBytes, err := ioutil.ReadFile(accessTokenFile)

if err != nil {
return "", err
}

accessToken = string(accessTokenBytes)
} else if os.IsNotExist(err) {
accessToken = randomPassword(32)

err = ioutil.WriteFile(accessTokenFile, []byte(accessToken), 0644)

if err != nil {
return "", err
}
} else {
return "", err
}
}

return accessToken, nil
}

func (o *ClusterWorkshopServeOptions) Run() error {
var err error

Expand Down Expand Up @@ -105,7 +148,11 @@ func (o *ClusterWorkshopServeOptions) Run() error {
// If going to patch hosted workshop, ensure we have an access token.

if o.PatchWorkshop && token == "" {
token = randomPassword(16)
token, err = generateAccessToken(o.RefreshToken)

if err != nil {
return errors.Wrap(err, "error generating access token")
}
}

// If patching hosted workshop create an apply the updated configuration.
Expand Down Expand Up @@ -251,6 +298,13 @@ func (p *ProjectInfo) NewClusterWorkshopServeCmd() *cobra.Command {
"",
"access token for protecting access to server",
)
c.Flags().BoolVarP(
&o.RefreshToken,
"refresh-token",
"",
false,
"forcibly refreshes the default generated access token",
)
c.Flags().BoolVarP(
&o.Files,
"allow-files-download",
Expand Down
1 change: 1 addition & 0 deletions client-programs/pkg/cmd/docker_cmd_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func (p *ProjectInfo) NewDockerCmdGroup() *cobra.Command {
Message: "Available Commands:",
Commands: []*cobra.Command{
p.NewDockerWorkshopCmdGroup(),
p.NewDockerExtensionCmdGroup(),
},
},
}
Expand Down
Loading

0 comments on commit c908030

Please sign in to comment.