-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #306 from hhhhsdxxxx/henry.hj/nydusify
nydusify support pack subcommand
- Loading branch information
Showing
10 changed files
with
814 additions
and
0 deletions.
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
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,40 @@ | ||
package packer | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/dragonflyoss/image-service/contrib/nydusify/pkg/utils" | ||
) | ||
|
||
type Artifact struct { | ||
OutputDir string | ||
} | ||
|
||
func NewArtifact(outputDir string) (Artifact, error) { | ||
res := Artifact{OutputDir: outputDir} | ||
if err := res.ensureOutputDir(); err != nil { | ||
return Artifact{}, err | ||
} | ||
return res, nil | ||
} | ||
|
||
func (a Artifact) bootstrapPath(metaFileName string) string { | ||
return filepath.Join(a.OutputDir, metaFileName) | ||
} | ||
|
||
func (a Artifact) outputJSONPath() string { | ||
return filepath.Join(a.OutputDir, "output.json") | ||
} | ||
|
||
func (a Artifact) blobFilePath(blobFileName string) string { | ||
return filepath.Join(a.OutputDir, blobFileName) | ||
} | ||
|
||
// ensureOutputDir use user defined outputDir or defaultOutputDir, and make sure dir exists | ||
func (a *Artifact) ensureOutputDir() error { | ||
if utils.IsEmptyString(a.OutputDir) { | ||
a.OutputDir = defaultOutputDir | ||
} | ||
return os.MkdirAll(a.OutputDir, 0755) | ||
} |
Oops, something went wrong.