-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat): Format, label, resize and mount devices through configuration
- Loading branch information
Showing
85 changed files
with
11,746 additions
and
1,564 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/ebs-bootstrap* | ||
coverage.* |
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
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,14 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
# https://stackoverflow.com/questions/59895/get-the-source-directory-of-a-bash-script-from-within-the-script-itself | ||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
cd "${SCRIPT_DIR}/.." | ||
|
||
go test -coverprofile=coverage.out ./... | ||
go tool cover -html=coverage.out -o coverage.html | ||
rm -rf coverage.out | ||
|
||
# The HTML file can either be opened locally or served through HTTP using a CLI tool like miniserve | ||
# https://github.com/svenstaro/miniserve. The latter is great if you are work | ||
# e.g `miniserve coverage.html` |
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 |
---|---|---|
@@ -1,44 +1,90 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"log" | ||
"ebs-bootstrap/internal/config" | ||
"ebs-bootstrap/internal/service" | ||
"ebs-bootstrap/internal/utils" | ||
"ebs-bootstrap/internal/state" | ||
"os" | ||
|
||
"github.com/reecetech/ebs-bootstrap/internal/action" | ||
"github.com/reecetech/ebs-bootstrap/internal/backend" | ||
"github.com/reecetech/ebs-bootstrap/internal/config" | ||
"github.com/reecetech/ebs-bootstrap/internal/layer" | ||
"github.com/reecetech/ebs-bootstrap/internal/service" | ||
"github.com/reecetech/ebs-bootstrap/internal/utils" | ||
) | ||
|
||
func main() { | ||
// Disable Timetamp | ||
log.SetFlags(0) | ||
e := utils.NewExecRunner() | ||
ds := &service.LinuxDeviceService{Runner: e} | ||
ns := &service.AwsNVMeService{} | ||
fs := &service.UnixFileService{} | ||
dts := &service.EbsDeviceTranslator{DeviceService: ds, NVMeService: ns} | ||
|
||
dt, err := dts.GetTranslator() | ||
if err != nil { | ||
log.Fatal(err) | ||
// Services | ||
erf := utils.NewExecRunnerFactory() | ||
ufs := service.NewUnixFileService() | ||
lds := service.NewLinuxDeviceService(erf) | ||
uos := service.NewUnixOwnerService() | ||
ans := service.NewAwsNitroNVMeService() | ||
fssf := service.NewLinuxFileSystemServiceFactory(erf) | ||
|
||
// Warnings | ||
warnings(uos) | ||
|
||
// Config + Flags | ||
c, err := config.New(os.Args) | ||
checkError(err) | ||
|
||
// Service + Config Consumers | ||
db := backend.NewLinuxDeviceBackend(lds, fssf) | ||
fb := backend.NewLinuxFileBackend(ufs) | ||
ub := backend.NewLinuxOwnerBackend(uos) | ||
dmb := backend.NewLinuxDeviceMetricsBackend(lds, fssf) | ||
dae := action.NewDefaultActionExecutor() | ||
|
||
// Modify Config | ||
modifiers := []config.Modifier{ | ||
config.NewAwsNVMeDriverModifier(ans, lds), | ||
} | ||
for _, m := range modifiers { | ||
checkError(m.Modify(c)) | ||
} | ||
config, err := config.New(os.Args, dt, fs) | ||
|
||
// Validate Config | ||
validators := []config.Validator{ | ||
config.NewFileSystemValidator(), | ||
config.NewModeValidator(), | ||
config.NewResizeThresholdValidator(), | ||
config.NewDeviceValidator(lds), | ||
config.NewMountPointValidator(), | ||
config.NewMountOptionsValidator(), | ||
config.NewOwnerValidator(uos), | ||
} | ||
for _, v := range validators { | ||
checkError(v.Validate(c)) | ||
} | ||
|
||
// Layers | ||
le := layer.NewExponentialBackoffLayerExecutor(c, dae, layer.DefaultExponentialBackoffParameters()) | ||
layers := []layer.Layer{ | ||
layer.NewFormatDeviceLayer(db), | ||
layer.NewLabelDeviceLayer(db), | ||
layer.NewCreateDirectoryLayer(fb), | ||
layer.NewMountDeviceLayer(db, fb), | ||
layer.NewResizeDeviceLayer(db, dmb), | ||
layer.NewChangeOwnerLayer(ub, fb), | ||
layer.NewChangePermissionsLayer(fb), | ||
} | ||
checkError(le.Execute(layers)) | ||
} | ||
|
||
func checkError(err error) { | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
for name, device := range config.Devices { | ||
d, err := state.NewDevice(name, ds, fs) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
err = d.Diff(config) | ||
if err == nil { | ||
log.Printf("🟢 %s: No changes detected", name) | ||
continue | ||
} | ||
if device.Mode == "healthcheck" { | ||
log.Fatal(err) | ||
} | ||
func warnings(owns service.OwnerService) { | ||
user, err := owns.GetCurrentUser() | ||
if err != nil { | ||
return | ||
} | ||
if user.Id != 0 { | ||
log.Println("🚧 Not running as root user. Device operations might yield unexpected results") | ||
} | ||
} |
This file was deleted.
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,9 @@ | ||
devices: | ||
/dev/vdb: | ||
fs: xfs | ||
label: external-vol | ||
mountPoint: /mnt/app | ||
group: ubuntu | ||
user: ubuntu | ||
permissions: 0644 | ||
resizeFs: true |
Oops, something went wrong.