Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ builds:
- arm64
ldflags: *build-ldflags

- id: windows-build
binary: mass
env:
- CGO_ENABLED=0
goos:
- windows
goarch:
- amd64
- arm64
ldflags: *build-ldflags

archives:
- id: linux-archives
builds:
Expand All @@ -39,6 +50,11 @@ archives:
- darwin-build
name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}"

- id: windows-archives
builds:
- windows-build
name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}"

checksum:
name_template: 'checksums.txt'

Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ build:
$(MAKE) build.macos; \
elif [ "$$(uname -s)" = "Linux" ]; then \
$(MAKE) build.linux; \
elif echo "$$(uname -s)" | grep -q -E "^(MINGW|MSYS|Windows)"; then \
$(MAKE) build.windows; \
else \
echo "Error: Unsupported operating system. Please use 'make build.macos' or 'make build.linux' directly."; \
echo "Error: Unsupported operating system. Please use 'make build.macos', 'make build.linux', or 'make build.windows' directly."; \
exit 1; \
Comment on lines +57 to 61
fi

Expand All @@ -67,6 +69,10 @@ build.macos: bin
build.linux: bin
GOOS=linux GOARCH=amd64 go build -o bin/mass-linux-amd64 -ldflags=${LD_FLAGS}

.PHONY: build.windows
build.windows: bin
GOOS=windows GOARCH=amd64 go build -o bin/mass-windows-amd64.exe -ldflags=${LD_FLAGS}

.PHONY: install.macos
install.macos: build.macos
rm -f ${INSTALL_PATH}/mass
Expand Down
7 changes: 6 additions & 1 deletion cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/signal"
"path"
"runtime"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -128,7 +129,11 @@ func setupLogging(level string) {

func handleSignals(ctx context.Context, s *server.BundleServer) {
c := make(chan os.Signal, 2)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
signals := []os.Signal{os.Interrupt}
if runtime.GOOS != "windows" {
signals = append(signals, syscall.SIGTERM)
}
signal.Notify(c, signals...)
go func(s *server.BundleServer) {
for sig := range c {
slog.Info("Shutting down", "signal", sig)
Expand Down
4 changes: 2 additions & 2 deletions pkg/bundle/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package bundle

import (
"path"
"path/filepath"

"github.com/massdriver-cloud/mass/pkg/provisioners"
"github.com/massdriver-cloud/massdriver-sdk-go/massdriver/client"
Expand All @@ -23,7 +23,7 @@ func (b *Bundle) Build(buildPath string, mdClient *client.Client) error {
combined := b.CombineParamsConnsMetadata()
for _, step := range b.Steps {
prov := provisioners.NewProvisioner(step.Provisioner)
err = prov.ExportMassdriverInputs(path.Join(buildPath, step.Path), combined)
err = prov.ExportMassdriverInputs(filepath.Join(buildPath, step.Path), combined)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"embed"
"encoding/json"
"fmt"
"path"
"path/filepath"
"regexp"

"github.com/massdriver-cloud/mass/pkg/files"
Expand Down Expand Up @@ -67,7 +67,7 @@ type Secret struct {
// Unmarshal reads and parses the massdriver.yaml file from the given directory into a Bundle.
func Unmarshal(readDirectory string) (*Bundle, error) {
unmarshalledBundle := &Bundle{}
if err := files.Read(path.Join(readDirectory, "massdriver.yaml"), unmarshalledBundle); err != nil {
if err := files.Read(filepath.Join(readDirectory, "massdriver.yaml"), unmarshalledBundle); err != nil {
return nil, err
}

Expand Down
7 changes: 3 additions & 4 deletions pkg/bundle/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"maps"
"os"
"path"
"path/filepath"
"regexp"
"sort"
Expand Down Expand Up @@ -266,7 +265,7 @@ func getExistingParamsPath(templateName string) (string, error) {
if !pathInfo.IsDir() {
return errors.New("path must be a directory containing a Terraform/OpenTofu module")
}
matches, err := filepath.Glob(path.Join(input, "*.tf"))
matches, err := filepath.Glob(filepath.Join(input, "*.tf"))
if err != nil {
return errors.New("unable to read directory")
}
Expand All @@ -288,10 +287,10 @@ func getExistingParamsPath(templateName string) (string, error) {
if !pathInfo.IsDir() {
return errors.New("path must be a directory containing a helm chart")
}
if _, chartErr := os.Stat(path.Join(input, "Chart.yaml")); errors.Is(chartErr, os.ErrNotExist) {
if _, chartErr := os.Stat(filepath.Join(input, "Chart.yaml")); errors.Is(chartErr, os.ErrNotExist) {
return errors.New("path does not contain 'Chart.yaml' file, and therefore isn't a valid Helm chart")
}
if _, valuesErr := os.Stat(path.Join(input, "values.yaml")); errors.Is(valuesErr, os.ErrNotExist) {
if _, valuesErr := os.Stat(filepath.Join(input, "values.yaml")); errors.Is(valuesErr, os.ErrNotExist) {
return errors.New("path does not contain 'values.yaml' file, and therefore isn't a valid Helm chart")
}
return nil
Expand Down
1 change: 1 addition & 0 deletions pkg/bundle/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (p *Publisher) PackageBundle(ctx context.Context, bundleDir string, tag str
if err != nil {
return err
}
bundleRelativePath = filepath.ToSlash(bundleRelativePath)

if ignoreMatcher != nil && ignoreMatcher.MatchesPath(bundleRelativePath) {
return nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/bundle/write_schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"fmt"
"os"
"path"
"path/filepath"
)

const idURLPattern = "https://schemas.massdriver.cloud/schemas/bundles/%s/schema-%s.json"
Expand Down Expand Up @@ -38,10 +38,10 @@ func (b *Bundle) WriteSchemas(buildPath string) error {
return err
}

filepath := fmt.Sprintf("/schema-%s.json", task.label)
filename := fmt.Sprintf("schema-%s.json", task.label)

// #nosec G306
err = os.WriteFile(path.Join(buildPath, filepath), content, 0644)
err = os.WriteFile(filepath.Join(buildPath, filename), content, 0644)

if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions pkg/commands/bundle/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"maps"
"os"
"path"
"path/filepath"
"strings"

"github.com/manifoldco/promptui"
Expand All @@ -20,7 +20,7 @@ import (
func RunImport(buildPath string, skipVerify bool) error {
fmt.Println("Checking IaC for missing parameters...")

mdYamlPath := path.Join(buildPath, "massdriver.yaml")
mdYamlPath := filepath.Join(buildPath, "massdriver.yaml")
fileBytes, readErr := os.ReadFile(mdYamlPath)
if readErr != nil {
return readErr
Expand All @@ -41,7 +41,7 @@ func RunImport(buildPath string, skipVerify bool) error {
missing := map[string]any{}
for _, step := range b.Steps {
prov := provisioners.NewProvisioner(step.Provisioner)
inputs, readProvErr := prov.ReadProvisionerInputs(path.Join(buildPath, step.Path))
inputs, readProvErr := prov.ReadProvisionerInputs(filepath.Join(buildPath, step.Path))
if readProvErr != nil {
return readProvErr
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/commands/bundle/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package bundle
import (
"fmt"
"os"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -31,7 +30,7 @@ func RunNew(data *templates.TemplateData) error {

for _, step := range b.Steps {
prov := provisioners.NewProvisioner(step.Provisioner)
if err := prov.InitializeStep(path.Join(data.OutputDir, step.Path), data.ExistingParamsPath); err != nil {
if err := prov.InitializeStep(filepath.Join(data.OutputDir, step.Path), data.ExistingParamsPath); err != nil {
return fmt.Errorf("failed to initialize step %q: %w", step.Path, err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package params
import (
"errors"
"fmt"
"path"
"path/filepath"

"github.com/massdriver-cloud/airlock/pkg/bicep"
"github.com/massdriver-cloud/airlock/pkg/helm"
Expand All @@ -24,7 +24,7 @@ func GetFromPath(templateName, paramsPath string) (string, error) {
case "terraform-module", "opentofu-module":
importResult = opentofu.TofuToSchema(paramsPath)
case "helm-chart":
importResult = helm.HelmToSchema(path.Join(paramsPath, "values.yaml"))
importResult = helm.HelmToSchema(filepath.Join(paramsPath, "values.yaml"))
case "bicep-template":
importResult = bicep.BicepToSchema(paramsPath)
default:
Expand Down
10 changes: 5 additions & 5 deletions pkg/provisioners/bicep.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/json"
"errors"
"os"
"path"
"path/filepath"

"github.com/massdriver-cloud/airlock/pkg/bicep"
)
Expand All @@ -17,7 +17,7 @@ type BicepProvisioner struct{}
// ExportMassdriverInputs appends auto-generated Bicep param declarations from the massdriver schema to the step's template.
func (p *BicepProvisioner) ExportMassdriverInputs(stepPath string, variables map[string]any) error {
// read existing bicep params for this step
bicepParamsImport := bicep.BicepToSchema(path.Join(stepPath, "template.bicep"))
bicepParamsImport := bicep.BicepToSchema(filepath.Join(stepPath, "template.bicep"))
if bicepParamsImport.Schema == nil {
return errors.New("failed to read existing Bicep param declarations: " + bicepParamsImport.PrettyDiags())
}
Expand All @@ -41,7 +41,7 @@ func (p *BicepProvisioner) ExportMassdriverInputs(stepPath string, variables map
return transpileErr
}

bicepFile, openErr := os.OpenFile(path.Join(stepPath, "template.bicep"), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
bicepFile, openErr := os.OpenFile(filepath.Join(stepPath, "template.bicep"), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
if openErr != nil {
return openErr
}
Expand All @@ -59,7 +59,7 @@ func (p *BicepProvisioner) ExportMassdriverInputs(stepPath string, variables map

// ReadProvisionerInputs reads the Bicep parameter declarations from the step's template file.
func (p *BicepProvisioner) ReadProvisionerInputs(stepPath string) (map[string]any, error) {
bicepParamsImport := bicep.BicepToSchema(path.Join(stepPath, "template.bicep"))
bicepParamsImport := bicep.BicepToSchema(filepath.Join(stepPath, "template.bicep"))

schemaBytes, marshallErr := json.Marshal(bicepParamsImport.Schema)
if marshallErr != nil {
Expand All @@ -85,5 +85,5 @@ func (p *BicepProvisioner) InitializeStep(stepPath string, sourcePath string) er
return errors.New("path is a directory not a bicep template")
}

return copyFile(sourcePath, path.Join(stepPath, "template.bicep"))
return copyFile(sourcePath, filepath.Join(stepPath, "template.bicep"))
}
8 changes: 4 additions & 4 deletions pkg/provisioners/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"errors"
"os"
"path"
"path/filepath"

"github.com/massdriver-cloud/airlock/pkg/helm"
)
Expand All @@ -20,7 +20,7 @@ func (p *HelmProvisioner) ExportMassdriverInputs(_ string, _ map[string]any) err

// ReadProvisionerInputs reads the Helm values.yaml and returns its schema as a map.
func (p *HelmProvisioner) ReadProvisionerInputs(stepPath string) (map[string]any, error) {
helmParamsImport := helm.HelmToSchema(path.Join(stepPath, "values.yaml"))
helmParamsImport := helm.HelmToSchema(filepath.Join(stepPath, "values.yaml"))

schemaBytes, marshallErr := json.Marshal(helmParamsImport.Schema)
if marshallErr != nil {
Expand All @@ -46,10 +46,10 @@ func (p *HelmProvisioner) InitializeStep(stepPath string, sourcePath string) err
return errors.New("path is not a directory containing a helm chart")
}

if _, chartErr := os.Stat(path.Join(sourcePath, "Chart.yaml")); errors.Is(chartErr, os.ErrNotExist) {
if _, chartErr := os.Stat(filepath.Join(sourcePath, "Chart.yaml")); errors.Is(chartErr, os.ErrNotExist) {
return errors.New("path does not contain 'Chart.yaml' file, and therefore isn't a valid Helm chart")
}
if _, valuesErr := os.Stat(path.Join(sourcePath, "values.yaml")); errors.Is(valuesErr, os.ErrNotExist) {
if _, valuesErr := os.Stat(filepath.Join(sourcePath, "values.yaml")); errors.Is(valuesErr, os.ErrNotExist) {
return errors.New("path does not contain 'values.yaml' file, and therefore isn't a valid Helm chart")
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/provisioners/opentofu.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"os"
"path"
"path/filepath"

"github.com/massdriver-cloud/airlock/pkg/opentofu"
)
Expand All @@ -15,7 +15,7 @@ type OpentofuProvisioner struct{}

// ExportMassdriverInputs generates the _massdriver_variables.tf file from the massdriver schema.
func (p *OpentofuProvisioner) ExportMassdriverInputs(stepPath string, variables map[string]any) (retErr error) {
massdriverVarsFile := path.Join(stepPath, "_massdriver_variables.tf")
massdriverVarsFile := filepath.Join(stepPath, "_massdriver_variables.tf")
massdriverVarsBackup := massdriverVarsFile + ".bak"

// If _massdriver_variables.tf already exists, rename it so airlock won't read it
Expand Down Expand Up @@ -101,7 +101,7 @@ func (p *OpentofuProvisioner) InitializeStep(stepPath string, sourcePath string)
}

// remove the dummy main.tf if we are copying from a source
maintfPath := path.Join(stepPath, "main.tf")
maintfPath := filepath.Join(stepPath, "main.tf")
if _, maintfErr := os.Stat(maintfPath); maintfErr == nil {
err := os.Remove(maintfPath)
if err != nil {
Expand Down
15 changes: 6 additions & 9 deletions pkg/templates/file_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import (
"fmt"
"io/fs"
"os"
"path"
"path/filepath"
"strings"

"github.com/osteele/liquid"
)
Expand All @@ -35,7 +33,7 @@ func (f *fileManager) mkDirOrWriteFile(filePath string, info fs.FileInfo, walkEr
}

relativeWritePath := relativeWritePath(filePath, f.readDirectory)
outputPath := path.Join(f.writeDirectory, relativeWritePath)
outputPath := filepath.Join(f.writeDirectory, relativeWritePath)
if info.IsDir() {
if _, checkDirExistsErr := os.Stat(outputPath); errors.Is(checkDirExistsErr, os.ErrNotExist) {
if isBundleRootDirectory(relativeWritePath) {
Expand Down Expand Up @@ -108,12 +106,11 @@ func (f *fileManager) writeToFile(outputPath string, outBytes []byte) error {
}

func relativeWritePath(currentFilePath, readDirectory string) string {
path := strings.Replace(currentFilePath, readDirectory, "", 1)
if path == "" {
path = "."
rel, err := filepath.Rel(readDirectory, currentFilePath)
if err != nil {
return "."
}

return path
return rel
Comment on lines 108 to +113
}

func makeWriteDirectoryAndParents(writeDirectory string) error {
Expand All @@ -129,5 +126,5 @@ func isBundleRootDirectory(relativeWritePath string) bool {
}

func isInsideBundleRootDirectory(relativeWritePath string) bool {
return filepath.Dir(relativeWritePath) == "/"
return filepath.Dir(relativeWritePath) == "."
}
3 changes: 1 addition & 2 deletions pkg/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package templates
import (
"errors"
"os"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -84,7 +83,7 @@ func Render(data *TemplateData) error {
}

fm := &fileManager{
readDirectory: path.Join(templatesPath, data.TemplateName),
readDirectory: filepath.Join(templatesPath, data.TemplateName),
writeDirectory: data.OutputDir,
templateData: data,
templateRootDirectory: templatesPath,
Expand Down
Loading