Skip to content

Commit

Permalink
Add option to local file system mount for workshop assets when deploy…
Browse files Browse the repository at this point in the history
…ed to docker.
  • Loading branch information
GrahamDumpleton committed Nov 21, 2022
1 parent a55bda0 commit b6ed70b
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions client-programs/pkg/cmd/docker_workshop_deploy_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,33 @@ type DockerWorkshopDeployOptions struct {
Version string
Cluster string
KubeConfig string
Assets string
}

const containerScript = `exec bash -s << "EOF"
mkdir -p /opt/eduk8s/config
cat > /opt/eduk8s/config/workshop.yaml << "EOS"
{{ .WorkshopConfig -}}
EOS
{{ if .Assets -}}
cat > /opt/eduk8s/config/vendir-assets-01.yaml << "EOS"
apiVersion: vendir.k14s.io/v1alpha1
kind: Config
directories:
- path: /opt/assets/files
contents:
- directory:
path: /opt/eduk8s/mnt/assets
path: .
EOS
{{ else -}}
{{ range $k, $v := .VendirFilesConfig -}}
{{ $off := inc $k -}}
cat > /opt/eduk8s/config/vendir-assets-{{ printf "%02d" $off }}.yaml << "EOS"
{{ $v -}}
EOS
{{ end -}}
{{ end -}}
{{ if .VendirPackagesConfig -}}
cat > /opt/eduk8s/config/vendir-packages.yaml << "EOS"
{{ .VendirPackagesConfig -}}
Expand Down Expand Up @@ -194,7 +208,7 @@ func (o *DockerWorkshopDeployOptions) Run(cmd *cobra.Command) error {
return errors.Wrap(err, "unable to generate workshop ports config")
}

if workshopVolumesConfig, err = generateWorkshopVolumeMounts(workshop); err != nil {
if workshopVolumesConfig, err = generateWorkshopVolumeMounts(workshop, o.Assets); err != nil {
return err
}

Expand All @@ -219,13 +233,15 @@ func (o *DockerWorkshopDeployOptions) Run(cmd *cobra.Command) error {
VendirFilesConfig []string
VendirPackagesConfig string
KubeConfig string
Assets string
}

inputs := TemplateInputs{
WorkshopConfig: workshopConfigData,
VendirFilesConfig: vendirFilesConfigData,
VendirPackagesConfig: vendirPackagesConfigData,
KubeConfig: kubeConfigData,
Assets: o.Assets,
}

funcMap := template.FuncMap{
Expand Down Expand Up @@ -465,6 +481,12 @@ func (p *ProjectInfo) NewDockerWorkshopDeployCmd() *cobra.Command {
"",
"path to kubeconfig to connect to workshop",
)
c.Flags().StringVar(
&o.Assets,
"assets",
"",
"local directory path to workshop assets",
)

return c
}
Expand Down Expand Up @@ -630,7 +652,7 @@ func generateWorkshopImageName(workshop *unstructured.Unstructured, repository s
return image, nil
}

func generateWorkshopVolumeMounts(workshop *unstructured.Unstructured) ([]composetypes.ServiceVolumeConfig, error) {
func generateWorkshopVolumeMounts(workshop *unstructured.Unstructured, assets string) ([]composetypes.ServiceVolumeConfig, error) {
filesMounts := []composetypes.ServiceVolumeConfig{
{
Type: "volume",
Expand All @@ -639,6 +661,22 @@ func generateWorkshopVolumeMounts(workshop *unstructured.Unstructured) ([]compos
},
}

if assets != "" {
assets = filepath.Clean(assets)
assets, err := filepath.Abs(assets)

if err != nil {
return []composetypes.ServiceVolumeConfig{}, errors.Wrap(err, "can't resolve local workshop assets path")
}

filesMounts = append(filesMounts, composetypes.ServiceVolumeConfig{
Type: "bind",
Source: assets,
Target: "/opt/eduk8s/mnt/assets",
ReadOnly: true,
})
}

dockerEnabled, found, _ := unstructured.NestedBool(workshop.Object, "spec", "session", "applications", "docker", "enabled")

if found && dockerEnabled {
Expand Down

0 comments on commit b6ed70b

Please sign in to comment.