-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Extend baseimage #25
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9692682
WIP: Extract package
NautiluX 0d7d125
add dockerfile generation
NautiluX fa38647
update: add tests to extend and generate dockerfile
siherrmann 0a0fce1
clean-up: change fmt to log, unify logs, remove unused comments, add …
siherrmann 7e3cbd7
Merge branch 'main' into extend-baseimage
siherrmann d2ee75b
fix: fix linter errors
siherrmann 63b6801
Merge branch 'extend-baseimage' of https://github.com/codesphere-clou…
siherrmann 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 |
|---|---|---|
|
|
@@ -29,3 +29,4 @@ bin/ | |
| oms-cli | ||
| oms-service | ||
| dist/ | ||
| oms-workdir/ | ||
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
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,27 @@ | ||
| // Copyright (c) Codesphere Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "github.com/codesphere-cloud/cs-go/pkg/io" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| type BetaCmd struct { | ||
| cmd *cobra.Command | ||
| } | ||
|
|
||
| func AddBetaCmd(rootCmd *cobra.Command, opts *GlobalOptions) { | ||
| beta := BetaCmd{ | ||
| cmd: &cobra.Command{ | ||
| Use: "beta", | ||
| Short: "Commands for early testing", | ||
| Long: io.Long(`OMS CLI commands for early adoption and testing. | ||
| Be aware that that usage and behavior may change as the features are developed.`), | ||
| }, | ||
| } | ||
| rootCmd.AddCommand(beta.cmd) | ||
|
|
||
| AddExtendCmd(beta.cmd, opts) | ||
| } |
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
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,27 @@ | ||
| // Copyright (c) Codesphere Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "github.com/codesphere-cloud/cs-go/pkg/io" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // ExtendCmd represents the extend command | ||
| type ExtendCmd struct { | ||
| cmd *cobra.Command | ||
| } | ||
|
|
||
| func AddExtendCmd(rootCmd *cobra.Command, opts *GlobalOptions) { | ||
| extend := ExtendCmd{ | ||
| cmd: &cobra.Command{ | ||
| Use: "extend", | ||
| Short: "Extend Codesphere ressources such as base images.", | ||
| Long: io.Long(`Extend Codesphere ressources such as base images to customize them for your needs.`), | ||
| }, | ||
| } | ||
| rootCmd.AddCommand(extend.cmd) | ||
|
|
||
| AddExtendBaseimageCmd(extend.cmd, opts) | ||
| } | ||
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,103 @@ | ||
| // Copyright (c) Codesphere Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "log" | ||
| "path" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/codesphere-cloud/cs-go/pkg/io" | ||
| "github.com/codesphere-cloud/oms/internal/env" | ||
| "github.com/codesphere-cloud/oms/internal/installer" | ||
| "github.com/codesphere-cloud/oms/internal/system" | ||
| "github.com/codesphere-cloud/oms/internal/tmpl" | ||
| ) | ||
|
|
||
| // ExtendBaseimageCmd represents the baseimage command | ||
| type ExtendBaseimageCmd struct { | ||
| cmd *cobra.Command | ||
| Opts *ExtendBaseimageOpts | ||
| Env env.Env | ||
| } | ||
|
|
||
| type ExtendBaseimageOpts struct { | ||
| *GlobalOptions | ||
| Package string | ||
| Dockerfile string | ||
| Force bool | ||
| } | ||
|
|
||
| const baseimagePath = "./codesphere/images" | ||
| const defaultBaseimage = "workspace-agent-24.04.tar" | ||
|
|
||
| func (c *ExtendBaseimageCmd) RunE(_ *cobra.Command, args []string) error { | ||
| if c.Opts.Package == "" { | ||
| return errors.New("required option package not set") | ||
| } | ||
|
|
||
| workdir := c.Env.GetOmsWorkdir() | ||
| p := installer.NewPackage(workdir, c.Opts.Package) | ||
|
|
||
| err := c.ExtendBaseimage(p, args) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to extend baseimage: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func AddExtendBaseimageCmd(extend *cobra.Command, opts *GlobalOptions) { | ||
| baseimage := ExtendBaseimageCmd{ | ||
| cmd: &cobra.Command{ | ||
| Use: "baseimage", | ||
| Short: "Extend Codesphere's workspace base image for customization", | ||
| Long: io.Long(`Loads the baseimage from Codesphere package and generates a Dockerfile based on it. | ||
| This enables you to extend Codesphere's base image with specific dependencies. | ||
|
|
||
| To use the custom base image, you need to push the resulting image to your container registry and | ||
| reference it in your install-config for the Codesphere installation process to pick it up and include it in Codesphere`), | ||
| }, | ||
| Opts: &ExtendBaseimageOpts{GlobalOptions: opts}, | ||
| Env: env.NewEnv(), | ||
| } | ||
| baseimage.cmd.Flags().StringVarP(&baseimage.Opts.Package, "package", "p", "", "Package file (e.g. codesphere-v1.2.3-installer.tar.gz) to load base image from") | ||
| baseimage.cmd.Flags().StringVarP(&baseimage.Opts.Dockerfile, "dockerfile", "d", "Dockerfile", "Output Dockerfile to generate for extending the base image") | ||
| baseimage.cmd.Flags().BoolVarP(&baseimage.Opts.Force, "force", "f", false, "Enforce package extraction") | ||
| extend.AddCommand(baseimage.cmd) | ||
| baseimage.cmd.RunE = baseimage.RunE | ||
| } | ||
|
|
||
| func (c *ExtendBaseimageCmd) ExtendBaseimage(p *installer.Package, args []string) error { | ||
| baseImageTarPath := path.Join(baseimagePath, defaultBaseimage) | ||
| err := p.ExtractDependency(baseImageTarPath, c.Opts.Force) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to extract package to workdir: %w", err) | ||
| } | ||
|
|
||
| extractedBaseImagePath := p.GetDependencyPath(baseImageTarPath) | ||
| d := system.NewDockerEngine() | ||
|
|
||
| imagenames, err := d.GetImageNames(p.FileIO, extractedBaseImagePath) | ||
| if err != nil || len(imagenames) == 0 { | ||
| return fmt.Errorf("failed to read image tags: %w", err) | ||
| } | ||
| log.Println(imagenames) | ||
|
|
||
| err = tmpl.GenerateDockerfile(p.FileIO, c.Opts.Dockerfile, imagenames[0]) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to generate dockerfile: %w", err) | ||
| } | ||
|
|
||
| log.Printf("Loading container image from package into local docker daemon: %s", extractedBaseImagePath) | ||
| err = d.LoadLocalContainerImage(extractedBaseImagePath) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to load baseimage file %s: %w", baseImageTarPath, err) | ||
| } | ||
|
|
||
| return nil | ||
| } |
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.