This repository has been archived by the owner on Oct 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Initial implementation to create single OCi image #4
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1ad0845
Initial implementation to create single OCi image
leo8a f1f8dbc
Remove oc binary from Dockerfile
leo8a b8a821e
Refactor nsenter cmds to use runInHostNamespace function
leo8a d8c3e74
Remove rpm-ostree.json from seed image
leo8a 4989a41
Refactor runInHostNamespace function to also return rawOutput
leo8a e90faa9
Dump out code from github.com/coreos/rpmostree-client-go/pkg/client
leo8a 519e5d3
Refactor rpm-ostree-client to add support for runInHostNamespace
leo8a e19c750
Refactor rpm-ostree cmds to use new rpm-ostree-client.go
leo8a 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 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 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,110 @@ | ||
/* | ||
Copyright 2023. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// This client lifts code from: https://github.com/coreos/rpmostree-client-go/blob/main/pkg/client/client.go | ||
|
||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
// Status summarizes the current worldview of the rpm-ostree daemon. | ||
// The deployment list is the primary data. | ||
type Status struct { | ||
// Deployments is the list of bootable filesystem trees. | ||
Deployments []Deployment | ||
// Transaction is the active transaction, if any. | ||
Transaction *[]string | ||
} | ||
|
||
// Deployment represents a bootable filesystem tree | ||
type Deployment struct { | ||
ID string `json:"id"` | ||
OSName string `json:"osname"` | ||
Serial int32 `json:"serial"` | ||
BaseChecksum *string `json:"base-checksum"` | ||
Checksum string `json:"checksum"` | ||
Version string `json:"version"` | ||
Timestamp uint64 `json:"timestamp"` | ||
Booted bool `json:"booted"` | ||
Staged bool `json:"staged"` | ||
LiveReplaced string `json:"live-replaced,omitempty"` | ||
Origin string `json:"origin"` | ||
CustomOrigin []string `json:"custom-origin"` | ||
ContainerImageReference string `json:"container-image-reference"` | ||
RequestedPackages []string `json:"requested-packages"` | ||
RequestedBaseRemovals []string `json:"requested-base-removals"` | ||
Unlocked *string `json:"unlocked"` | ||
} | ||
|
||
// Client is a handle for interacting with a rpm-ostree based system. | ||
type Client struct { | ||
clientid string | ||
} | ||
|
||
// NewClient creates a new rpm-ostree client. The client identifier should be a short, unique and ideally machine-readable string. | ||
// This could be as simple as `examplecorp-management-agent`. | ||
// If you want to be more verbose, you could use a URL, e.g. `https://gitlab.com/examplecorp/management-agent`. | ||
func NewClient(id string) Client { | ||
return Client{ | ||
clientid: id, | ||
} | ||
} | ||
|
||
func (client *Client) newCmd(args ...string) []byte { | ||
rawOutput, _ := runInHostNamespace("rpm-ostree", args...) | ||
return rawOutput | ||
} | ||
|
||
// VersionData represents the static information about rpm-ostree. | ||
type VersionData struct { | ||
Version string `yaml:"Version"` | ||
Features []string `yaml:"Features"` | ||
Git string `yaml:"Git"` | ||
} | ||
|
||
type rpmOstreeVersionData struct { | ||
Root VersionData `yaml:"rpm-ostree"` | ||
} | ||
|
||
// RpmOstreeVersion returns the running rpm-ostree version number | ||
func (client *Client) RpmOstreeVersion() (*VersionData, error) { | ||
buf := client.newCmd("--version") | ||
|
||
var q rpmOstreeVersionData | ||
|
||
if err := yaml.Unmarshal(buf, &q); err != nil { | ||
return nil, fmt.Errorf("failed to parse `rpm-ostree --version` output: %w", err) | ||
} | ||
|
||
return &q.Root, nil | ||
} | ||
|
||
// QueryStatus loads the current system state. | ||
func (client *Client) QueryStatus() (*Status, error) { | ||
var q Status | ||
buf := client.newCmd("status", "--json") | ||
|
||
if err := json.Unmarshal(buf, &q); err != nil { | ||
return nil, fmt.Errorf("failed to parse `rpm-ostree status --json` output: %w", err) | ||
} | ||
|
||
return &q, 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far we still need the rpm-ostree.json file for the restore process
I'm actually testing all "one image" process to see how it works, I'll keep you posted :)
Once we validate it, we probably should try the way Colin suggested and see how it goes :)