-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dont use resolveconf on systemd (#70)
* dont use resolveconf on system * build * copy resolv conf * custom handling of resolve conf * generated code
- Loading branch information
Showing
4 changed files
with
97 additions
and
4 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,61 @@ | ||
package builder | ||
|
||
// taken from here: https://github.com/hashicorp/packer/blob/81522dced0b25084a824e79efda02483b12dc7cd/builder/amazon/chroot/step_chroot_provision.go | ||
|
||
import ( | ||
"context" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/hashicorp/packer/helper/multistep" | ||
"github.com/hashicorp/packer/packer" | ||
) | ||
|
||
// stepHandleResolvConf provisions the instance within a chroot. | ||
type stepHandleResolvConf struct { | ||
ChrootKey string | ||
Delete bool | ||
} | ||
|
||
func (s *stepHandleResolvConf) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { | ||
mountPath := state.Get(s.ChrootKey).(string) | ||
ui := state.Get("ui").(packer.Ui) | ||
|
||
const origResolvConf = "/etc/resolv.conf" | ||
destResolvConf := filepath.Join(mountPath, origResolvConf) | ||
|
||
if s.Delete { | ||
err := os.Remove(destResolvConf) | ||
if err != nil { | ||
ui.Error(err.Error()) | ||
return multistep.ActionHalt | ||
} | ||
} else { | ||
// copy file over: | ||
err := copyFile(destResolvConf, origResolvConf) | ||
if err != nil { | ||
ui.Error(err.Error()) | ||
return multistep.ActionHalt | ||
} | ||
} | ||
|
||
return multistep.ActionContinue | ||
} | ||
|
||
func (s *stepHandleResolvConf) Cleanup(state multistep.StateBag) {} | ||
|
||
func copyFile(dst, src string) error { | ||
in, err := os.Open(src) | ||
if err != nil { | ||
return err | ||
} | ||
defer in.Close() | ||
out, err := os.Create(dst) | ||
if err != nil { | ||
return err | ||
} | ||
defer out.Close() | ||
_, err = io.Copy(out, in) | ||
return err | ||
} |
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