-
Notifications
You must be signed in to change notification settings - Fork 2
feat: reference extended base image in install-config #63
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 6 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
c12f131
update: add build image to install codesphere, refactor installer, ad…
siherrmann b5d5fba
Merge branch 'main' into reference-base-image
siherrmann 9009a5b
chore(docs): Auto-update docs and licenses
siherrmann 0120619
fix: fix issues after main merge, small updates
siherrmann e74c5db
Merge branch 'reference-base-image' of https://github.com/codesphere-…
siherrmann 889dc3a
chore(docs): Auto-update docs and licenses
siherrmann b2ecd0a
refac: refactor image file to not repeat docker podman if else
siherrmann cfbb6e9
update: clean up filewriter, add write function, add dockerfile updat…
siherrmann b0cacee
fix: fix lima-config, go did not install
siherrmann 03cf176
feat: add build image command, add update dockerfile command, unify p…
siherrmann 2169a41
Merge branch 'reference-base-image' of https://github.com/codesphere-…
siherrmann 12b9f1e
update: update build image command description
siherrmann b8c09a0
update: update build image error on missing registry
siherrmann 98fac5a
update: update docker from update to regexp, add tests
siherrmann 3a7a00a
update: update global options to pointer
siherrmann 3ec9e76
update: update dockerfile from update to only workspace agent images
siherrmann b12bde2
Merge branch 'main' into reference-base-image
siherrmann 5d2a8ad
update: go mod tidy
siherrmann e6a4e25
update: regenerate docs
siherrmann 12b8cac
chore(docs): Auto-update docs and licenses
siherrmann 27bfd83
update: update image name handling
siherrmann 460732f
update: remove required from description of non required flag
siherrmann 8616407
Merge branch 'reference-base-image' of https://github.com/codesphere-…
siherrmann 71f560f
Merge branch 'main' into reference-base-image
siherrmann 30329b1
chore(docs): Auto-update docs and licenses
siherrmann 425e547
fix: fix lint issues unhandled errors
siherrmann 467965c
Merge branch 'reference-base-image' of https://github.com/codesphere-…
siherrmann fb45e37
fix: fix lint error unhandled error
siherrmann e0e3837
update: small PR updates
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
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,26 @@ | ||
| // 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" | ||
| ) | ||
|
|
||
| // BuildCmd represents the build command | ||
| type BuildCmd struct { | ||
| cmd *cobra.Command | ||
| } | ||
|
|
||
| func AddBuildCmd(rootCmd *cobra.Command, opts *GlobalOptions) { | ||
| build := BuildCmd{ | ||
| cmd: &cobra.Command{ | ||
| Use: "build", | ||
| Short: "Build and push images to a registry", | ||
| Long: io.Long(`Build and push container images to a registry using the provided configuration.`), | ||
| }, | ||
| } | ||
| rootCmd.AddCommand(build.cmd) | ||
| AddBuildImagesCmd(build.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,105 @@ | ||
| // Copyright (c) Codesphere Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "log" | ||
|
|
||
| "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/util" | ||
| "github.com/codesphere-cloud/oms/internal/version" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // BuildImagesCmd represents the build images command | ||
| type BuildImagesCmd struct { | ||
| cmd *cobra.Command | ||
| Opts *BuildImagesOpts | ||
| Env env.Env | ||
| } | ||
|
|
||
| type BuildImagesOpts struct { | ||
| *GlobalOptions | ||
| Config string | ||
| } | ||
|
|
||
| func (c *BuildImagesCmd) RunE(_ *cobra.Command, args []string) error { | ||
| cm := installer.NewConfig() | ||
| im := system.NewImage(context.Background()) | ||
|
|
||
| err := c.BuildAndPushImages(cm, im) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to build and push images: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func AddBuildImagesCmd(build *cobra.Command, opts *GlobalOptions) { | ||
| buildImages := BuildImagesCmd{ | ||
| cmd: &cobra.Command{ | ||
| Use: "images", | ||
| Short: "Build and push container images", | ||
| Long: io.Long(`Build and push container images based on the configuration file. | ||
| Extracts necessary images configuration to get the bomRef and processes them.`), | ||
| }, | ||
| Opts: &BuildImagesOpts{GlobalOptions: opts}, | ||
| Env: env.NewEnv(), | ||
| } | ||
| buildImages.cmd.Flags().StringVarP(&buildImages.Opts.Config, "config", "c", "", "Path to the configuration YAML file") | ||
|
|
||
| util.MarkFlagRequired(buildImages.cmd, "config") | ||
|
|
||
| build.AddCommand(buildImages.cmd) | ||
|
|
||
| buildImages.cmd.RunE = buildImages.RunE | ||
| } | ||
|
|
||
| func (c *BuildImagesCmd) BuildAndPushImages(cm installer.ConfigManager, im system.ImageManager) error { | ||
| config, err := cm.ParseConfigYaml(c.Opts.Config) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to parse config: %w", err) | ||
| } | ||
|
|
||
| if len(config.Codesphere.DeployConfig.Images) == 0 { | ||
| return fmt.Errorf("no images defined in the config") | ||
| } | ||
| if len(config.Registry.Server) == 0 { | ||
| return fmt.Errorf("registry server not defined in the config") | ||
siherrmann marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| v := &version.Build{} | ||
| codesphereVersion := v.Version() | ||
|
|
||
| for imageName, imageConfig := range config.Codesphere.DeployConfig.Images { | ||
| for flavorName, flavorConfig := range imageConfig.Flavors { | ||
| log.Printf("Processing image '%s' with flavor '%s'", imageName, flavorName) | ||
| if flavorConfig.Image.Dockerfile == "" { | ||
| log.Printf("Skipping flavor '%s', no dockerfile defined", flavorName) | ||
| continue | ||
| } | ||
|
|
||
| targetImage := fmt.Sprintf("%s/%s-%s:%s", config.Registry.Server, imageName, flavorName, codesphereVersion) | ||
|
|
||
| err := im.BuildImage(flavorConfig.Image.Dockerfile, targetImage, ".") | ||
| if err != nil { | ||
| return fmt.Errorf("failed to build image %s: %w", targetImage, err) | ||
| } | ||
|
|
||
| err = im.PushImage(targetImage) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to push image %s: %w", targetImage, err) | ||
| } | ||
|
|
||
| log.Printf("Successfully built and pushed image: %s", targetImage) | ||
| } | ||
| } | ||
|
|
||
| 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.