Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre release #17

Merged
merged 11 commits into from
Oct 6, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.backup
.direnv/
.env
.vscode
Expand Down
6 changes: 3 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ project_name: cloudexec
builds:
- ldflags:
- -s -w
- -X main.version={{.Version}}
- -X main.commit={{.FullCommit}}
- -X main.date={{.CommitDate}}
- -X main.Version={{.Version}}
- -X main.Commit={{.FullCommit}}
- -X main.Date={{.CommitDate}}
env:
- CGO_ENABLED=0
- GOFLAGS=-mod=readonly -trimpath
Expand Down
24 changes: 20 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
SHELL=bash

# Capture version, commit, and date
GIT_COMMIT=$(shell git rev-list -1 HEAD)
GIT_DATE=$(shell git log -1 --format=%cd --date=format:'%Y-%m-%d-%H:%M:%S')
VERSION="$(shell cat VERSION | tr -d '\n\r')"
bohendo marked this conversation as resolved.
Show resolved Hide resolved

# Build the Go app with ldflags
build:
@mkdir -p dist
@cd cmd/cloudexec && go build -o ../../dist/cloudexec
cd cmd/cloudexec && go build -ldflags "-X 'main.Version=$(VERSION)' -X 'main.Commit=$(GIT_COMMIT)' -X 'main.Date=$(GIT_DATE)'" -o ../../dist/cloudexec

format:
trunk fmt
Expand All @@ -17,8 +25,16 @@ lint:
go fmt pkg/state/*.go
shellcheck cmd/cloudexec/user_data.sh.tmpl

existing_installation=$(shell nix profile list | grep cloudexec | cut -d " " -f 1)
# smuggles git info in the VERSION file to work around nix flake hermicity
nix-install:
nix build
nix profile remove $(existing_installation)
@set -e; \
cp -f ./VERSION ./.VERSION.backup; \
trap 'mv -f ./.VERSION.backup ./VERSION' EXIT; \
echo "commit=$(GIT_COMMIT)" >> ./VERSION; \
echo "date=$(GIT_DATE)" >> ./VERSION; \
echo "nix build"; \
nix build; \
echo nix profile remove $(shell nix profile list | grep cloudexec | cut -d " " -f 1); \
nix profile remove $(shell nix profile list | grep cloudexec | cut -d " " -f 1); \
echo nix profile install ./result; \
bohendo marked this conversation as resolved.
Show resolved Hide resolved
nix profile install ./result
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0
4 changes: 2 additions & 2 deletions cmd/cloudexec/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ func processOpValue(value string) (string, error) {
cmd.Stderr = &stderr
output, err := cmd.Output()
if err != nil {
fmt.Println(stderr.String())
return "", fmt.Errorf("Failed to process 1password reference for %s: %w", value, err)
// err says "exit status 1" so not very helpful, omit it from the following message
return "", fmt.Errorf("Failed to process 1password reference for %s: %s", value, stderr.String())
}
return strings.TrimSpace(string(output)), nil
}
Expand Down
20 changes: 10 additions & 10 deletions cmd/cloudexec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import (
)

var (
version = "dev"
commit = "none"
date = "unknown"
configFilePath = fmt.Sprintf("%s/.config/cloudexec/config.toml", os.Getenv("HOME"))
launchConfigFilePath = "./cloudexec.toml"
Version = "dev"
Commit = "none"
Date = "unknown"
ConfigFilePath = fmt.Sprintf("%s/.config/cloudexec/config.toml", os.Getenv("HOME"))
LaunchConfigFilePath = "./cloudexec.toml"
)

func main() {
Expand All @@ -34,7 +34,7 @@ func main() {
dropletName := fmt.Sprintf("cloudexec-%v", username)

// Attempt to load the configuration
config, configErr := LoadConfig(configFilePath)
config, configErr := LoadConfig(ConfigFilePath)

app := &cli.App{
Name: "cloudexec",
Expand Down Expand Up @@ -112,16 +112,16 @@ func main() {
}

// Check if a local cloudexec.toml exists
if _, err := os.Stat(launchConfigFilePath); os.IsNotExist(err) {
if _, err := os.Stat(LaunchConfigFilePath); os.IsNotExist(err) {
// Check if the path to a launch config is provided
if c.Args().Len() < 1 {
return fmt.Errorf("please provide a path to a cloudexec.toml file or create one in the current directory")
}
launchConfigFilePath = c.Args().Get(0)
LaunchConfigFilePath = c.Args().Get(0)
}

// Load the launch configuration
lc, err := LoadLaunchConfig(launchConfigFilePath)
lc, err := LoadLaunchConfig(LaunchConfigFilePath)
if err != nil {
return err
}
Expand Down Expand Up @@ -503,7 +503,7 @@ func main() {
Usage: "Gets the version of the app",
Aliases: []string{"v"},
Action: func(*cli.Context) error {
fmt.Printf("cloudexec %s, commit %s, built at %s", version, commit, date)
fmt.Printf("cloudexec %s, commit %s, built at %s", Version, Commit, Date)
return nil
},
},
Expand Down
20 changes: 18 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,30 @@

default = cloudexec;

cloudexec = pkgs.buildGoModule {
cloudexec = let
version = let
result = builtins.match "([^\n]*).*" (builtins.readFile ./VERSION);
in if result != null then builtins.head result else "unknown";
gitCommit = let
result = builtins.match ".*commit=([^\n]*).*" (builtins.readFile ./VERSION);
in if result != null then builtins.head result else "unknown";
gitDate = let
result = builtins.match ".*date=([^\n]*).*" (builtins.readFile ./VERSION);
in if result != null then builtins.head result else "unknown";
in pkgs.buildGoModule {
pname = "cloudexec";
version = "0.0.1"; # TBD
version = "${version}";
src = ./.;
vendorSha256 = "sha256-xiiMcjo+hRllttjYXB3F2Ms2gX43r7/qgwxr4THNhsk=";
nativeBuildInputs = [
pkgs.git
pkgs.go_1_20
];
ldflags = [
"-X main.Version=${version}"
"-X main.Commit=${gitCommit}"
"-X main.Date=${gitDate}"
];
bohendo marked this conversation as resolved.
Show resolved Hide resolved
};

vscode = pkgs.vscode-with-extensions.override {
Expand Down