Skip to content

Commit

Permalink
actions/apt_action: Add property 'update'
Browse files Browse the repository at this point in the history
This property is a boolean value indicating if `apt update` will be run
before install package. Default value is 'true'.

Signed-off-by: Trung Do <[email protected]>
Signed-off-by: Daniel Sangorrin <[email protected]>
  • Loading branch information
dothanhtrung authored and sjoerdsimons committed Dec 2, 2020
1 parent fa6d9d5 commit 458b7b3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions actions/apt_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Yaml syntax:
- action: apt
recommends: bool
unauthenticated: bool
update: bool
packages:
- package1
- package2
Expand All @@ -20,6 +21,8 @@ Optional properties:
- recommends -- boolean indicating if suggested packages will be installed
- unauthenticated -- boolean indicating if unauthenticated packages can be installed
- update -- boolean indicating if `apt update` will be run. Default 'true'.
*/
package actions

Expand All @@ -31,9 +34,15 @@ type AptAction struct {
debos.BaseAction `yaml:",inline"`
Recommends bool
Unauthenticated bool
Update bool
Packages []string
}

func NewAptAction() *AptAction {
a := &AptAction{Update: true}
return a
}

func (apt *AptAction) Run(context *debos.DebosContext) error {
apt.LogStart()
aptOptions := []string{"apt-get", "-y"}
Expand All @@ -52,11 +61,14 @@ func (apt *AptAction) Run(context *debos.DebosContext) error {
c := debos.NewChrootCommandForContext(*context)
c.AddEnv("DEBIAN_FRONTEND=noninteractive")

err := c.Run("apt", "apt-get", "update")
if err != nil {
return err
if apt.Update {
err := c.Run("apt", "apt-get", "update")
if err != nil {
return err
}
}
err = c.Run("apt", aptOptions...)

err := c.Run("apt", aptOptions...)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion actions/recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (y *YamlAction) UnmarshalYAML(unmarshal func(interface{}) error) error {
case "run":
y.Action = &RunAction{}
case "apt":
y.Action = &AptAction{}
y.Action = NewAptAction()
case "ostree-commit":
y.Action = &OstreeCommitAction{}
case "ostree-deploy":
Expand Down

0 comments on commit 458b7b3

Please sign in to comment.