forked from k0sproject/rig
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BusyBox/Alpine support (k0sproject#94)
The BusyBox stat and touch binaries differ from their GNU counterparts in some ways that are relevant to rig: The stat binary won't accept the --printf flag, but it accepts the -c flag in the same way GNU stat does. The -c command won't accept backslash escapes, though. Hence fall back to the pipe character as delimiter. The touch binary won't parse time zones and sub-second precision times. Accommodate for that by normalizing the time to UTC and only use sub- second precision timestamps if it's not BusyBox touch. This will loose precision, but that's probably better than failing completely. Make localhost connections use the SHELL instead of hard-coding bash. Make the rigfs helper shell script POSIX compatible. Add an OS support package for Alpine that uses apk for package installations. Add a minimal footloose-compatible Dockerfile for Alpine 3.18 to the tests and execute it as part of the CI.
- Loading branch information
Showing
10 changed files
with
149 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ test/rigtest | |
test/footloose.yaml | ||
test/Library | ||
test/.ssh | ||
test/*.iid |
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
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,52 @@ | ||
package linux | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/alessio/shellescape" | ||
"github.com/k0sproject/rig" | ||
"github.com/k0sproject/rig/exec" | ||
"github.com/k0sproject/rig/os" | ||
"github.com/k0sproject/rig/os/registry" | ||
) | ||
|
||
// Alpine provides OS support for Alpine Linux. | ||
type Alpine struct { | ||
os.Linux | ||
} | ||
|
||
func init() { | ||
registry.RegisterOSModule( | ||
func(os rig.OSVersion) bool { | ||
return os.ID == "alpine" | ||
}, | ||
func() interface{} { | ||
return &Alpine{} | ||
}, | ||
) | ||
} | ||
|
||
// InstallPackage installs packages via apk. | ||
func (l Alpine) InstallPackage(host os.Host, pkgs ...string) error { | ||
if err := host.Execf("apk update", exec.Sudo(host)); err != nil { | ||
return fmt.Errorf("failed to update apk cache: %w", err) | ||
} | ||
|
||
if len(pkgs) < 1 { | ||
return nil | ||
} | ||
|
||
var cmd strings.Builder | ||
cmd.WriteString("apk add --") | ||
for _, pkg := range pkgs { | ||
cmd.WriteRune(' ') | ||
cmd.WriteString(shellescape.Quote(pkg)) | ||
} | ||
|
||
if err := host.Exec(cmd.String(), exec.Sudo(host)); err != nil { | ||
return fmt.Errorf("failed to install apk packages: %w", err) | ||
} | ||
|
||
return nil | ||
} |
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,13 @@ | ||
FROM docker.io/library/alpine:3.18.3 | ||
|
||
RUN apk add --no-cache \ | ||
alpine-base \ | ||
openssh-server \ | ||
bash \ | ||
&& rc-update add syslog boot \ | ||
&& rc-update add sshd default \ | ||
&& rc-update add local default \ | ||
# disable ttys | ||
&& sed -i -e 's/^\(tty[0-9]\)/# \1/' /etc/inittab \ | ||
# no greetings | ||
&& truncate -c -s0 /etc/issue /etc/motd |
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