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

Combined pr #22

Merged
merged 34 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4dc5001
updating build create to stream output
msaxon May 24, 2024
6e16941
adding middleware to add the content-type header when missing
msaxon May 24, 2024
7a47b2a
removing extra logs
msaxon May 24, 2024
7ea9e3e
updating stream to go to stderr
msaxon May 24, 2024
5acdb4e
Merge branch 'main' into streaming-output
msaxon May 29, 2024
af9dee1
skipping create build test for now
msaxon May 29, 2024
10153ea
Update internal/output/stream.go
msaxon May 29, 2024
cfce324
adding value writer
msaxon May 29, 2024
a89c6da
adding flag to pull previous deploy settings
msaxon May 28, 2024
a75152a
adding file sources and check for new version
msaxon May 29, 2024
739de5f
fixing formatting and some flag names
msaxon May 29, 2024
3c5e7ee
Setup object-based deployment configuration merge with test
drewfead May 29, 2024
47cd658
Make lint happy
drewfead May 29, 2024
6050a6d
making fields not required
msaxon May 30, 2024
df3f4bb
removing app id from config
msaxon May 30, 2024
7a79ac1
updating text writer to print as a table
msaxon May 28, 2024
30a5c80
Make text output formatting more flexible
drewfead May 30, 2024
d5b9c37
Add more formatting to test
drewfead May 30, 2024
ac40738
Make test pass
drewfead May 30, 2024
802f046
Wire up text formatter when output type is text
drewfead May 30, 2024
6c11cc5
Go mod tidy
drewfead May 30, 2024
a7c4d72
Remove CreatedBy from textual output
drewfead May 30, 2024
5953a85
removing extra flag names for additional container ports
msaxon May 30, 2024
5767f7e
add install scripts
zlangbert May 30, 2024
6f6c996
Merge branch 'install-script' into combined-pr
msaxon May 30, 2024
58669c3
Merge branch 'flexible-text-formatting' into combined-pr
msaxon May 30, 2024
d92fc7f
Merge branch 'config-file-aliases' into combined-pr
msaxon May 30, 2024
921cded
Merge branch 'value-writer-2' into combined-pr
msaxon May 30, 2024
431f168
Merge branch 'deployment-defaults' into combined-pr
msaxon May 30, 2024
32bff8e
fixing issue with app ID and linter
msaxon May 30, 2024
0adbc42
fixing circular marshal call on delete build
msaxon May 30, 2024
c1414d9
skipping flaky test
msaxon May 30, 2024
58b5146
fixing alias name
msaxon Jun 4, 2024
02a275c
fixing test
msaxon Jun 4, 2024
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ vet: ## Run vet on all code with the go vet command.
##@ Tests
.PHONY: test
test: ## Unit test all modules.
go test -v -race ./...
go test -v -parallel=1 -race ./...

.PHONY: test-short
test-short: ## Unit test all modules in short mode.
go test -v -race -short ./...
go test -v -parallel=1 -race -short ./...

##@ Misc.
# The help target prints out all targets with their descriptions organized
Expand Down
9 changes: 8 additions & 1 deletion example/config.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
build:
id: 1
id: 11
deployment:
idle-timeout-enabled: true
rooms-per-process: 1
transport-type: tcp
container-port: 8090
requested-memory-mb: 1024
requested-cpu: 0.5
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.22.2

require (
github.com/cenkalti/backoff/v4 v4.3.0
github.com/dustin/go-humanize v1.0.1
github.com/ericlagergren/decimal v0.0.0-20240411145413-00de7ca16731
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK3
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/ericlagergren/decimal v0.0.0-20240411145413-00de7ca16731 h1:R/ZjJpjQKsZ6L/+Gf9WHbt31GG8NMVcpRqUE+1mMIyo=
github.com/ericlagergren/decimal v0.0.0-20240411145413-00de7ca16731/go.mod h1:M9R1FoZ3y//hwwnJtO51ypFGwm8ZfpxPT/ZLtO1mcgQ=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
Expand Down
33 changes: 33 additions & 0 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
$repoOwner = "hathora-ci"
$repoName = "ci"
$binaryName = "hathora"

# Get the latest release tag from GitHub
$latestRelease = (Invoke-WebRequest "https://api.github.com/repos/$repoOwner/$repoName/releases/latest" | ConvertFrom-Json).tag_name

# Detect the architecture
$arch = $env:PROCESSOR_ARCHITECTURE
if ($arch -eq "AMD64") {
$arch = "amd64"
} elseif ($arch -eq "ARM64") {
$arch = "arm64"
} else {
Write-Error "Unsupported architecture: $arch"
exit 1
}

# Set the download URL for the Windows binary based on the architecture
$downloadUrl = "https://github.com/$repoOwner/$repoName/releases/download/$latestRelease/$binaryName-windows-$arch.exe"

# Set the install directory
$installDir = "$env:LOCALAPPDATA\Microsoft\WindowsApps"

# Download the binary
Write-Host "Downloading $binaryName for $arch..."
Invoke-WebRequest -Uri $downloadUrl -OutFile "$binaryName.exe"

# Install the binary
Write-Host "Installing $binaryName to $installDir..."
Move-Item -Path "$binaryName.exe" -Destination $installDir

Write-Host "Installation complete!"
86 changes: 86 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env bash

set -e

REPO_OWNER="hathora"
REPO_NAME="ci"
BINARY_NAME="hathora-ci"

# Get the latest release tag from GitHub
LATEST_RELEASE=$(curl -s https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases/latest | grep "tag_name" | cut -d '"' -f 4)

# Detect the operating system and architecture
OS=$(uname | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)

case "$OS" in
linux*)
case "$ARCH" in
x86_64)
DOWNLOAD_URL="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${LATEST_RELEASE}/${BINARY_NAME}-linux-amd64"
;;
aarch64)
DOWNLOAD_URL="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${LATEST_RELEASE}/${BINARY_NAME}-linux-arm64"
;;
*)
echo "Unsupported architecture: $ARCH"
exit 1
;;
esac
INSTALL_DIR="/usr/local/bin"
;;
darwin*)
case "$ARCH" in
x86_64)
DOWNLOAD_URL="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${LATEST_RELEASE}/${BINARY_NAME}-darwin-amd64"
;;
arm64)
DOWNLOAD_URL="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${LATEST_RELEASE}/${BINARY_NAME}-darwin-arm64"
;;
*)
echo "Unsupported architecture: $ARCH"
exit 1
;;
esac
INSTALL_DIR="/usr/local/bin"
;;
msys*|cygwin*|mingw*)
case "$ARCH" in
x86_64)
DOWNLOAD_URL="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${LATEST_RELEASE}/${BINARY_NAME}-windows-amd64"
;;
arm64)
DOWNLOAD_URL="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${LATEST_RELEASE}/${BINARY_NAME}-windows-arm64"
;;
*)
echo "Unsupported architecture: $ARCH"
exit 1
;;
esac
INSTALL_DIR="${USERPROFILE}\\AppData\\Local\\Microsoft\\WindowsApps"
;;
*)
echo "Unsupported operating system: $OS"
exit 1
;;
esac

# Download the binary
echo "Downloading ${BINARY_NAME} version ${LATEST_RELEASE}..."
curl -s -L -o "${BINARY_NAME}" "${DOWNLOAD_URL}"

# Make the binary executable (Linux and macOS only)
if [[ "$OS" == "linux"* ]] || [[ "$OS" == "darwin"* ]]; then
chmod +x "${BINARY_NAME}"
fi

# Install the binary
echo "Installing ${BINARY_NAME} to ${INSTALL_DIR}..."
if [[ "$OS" == "msys"* ]] || [[ "$OS" == "cygwin"* ]] || [[ "$OS" == "mingw"* ]]; then
mv "${BINARY_NAME}" "${INSTALL_DIR}"
else
sudo mv "${BINARY_NAME}" "${INSTALL_DIR}"
fi

echo "Installation complete!"

4 changes: 2 additions & 2 deletions internal/archive/targz.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func ArchiveTGZ(srcFolder string) (string, error) {

ignoreMatchers, err := getIgnoreMatchers(
srcFolder,
filepath.Join(srcFolder, ".dockerignore"),
filepath.Join(srcFolder, ".gitignore"))
".dockerignore",
".gitignore")

if err != nil {
return "", err
Expand Down
2 changes: 2 additions & 0 deletions internal/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func App() *cli.Command {
Flags: GlobalFlags,
Version: BuildVersion,
Before: func(ctx context.Context, cmd *cli.Command) error {
handleNewVersionAvailable(BuildVersion)

if isCallForHelp(cmd) {
return nil
}
Expand Down
41 changes: 15 additions & 26 deletions internal/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"context"
"fmt"
"github.com/hathora/ci/internal/output"
"os"

"github.com/hathora/ci/internal/archive"
Expand Down Expand Up @@ -67,7 +68,7 @@ var Build = &cli.Command{
Name: createCommandName,
Aliases: []string{"create-build"},
Usage: "create a build",
Flags: subcommandFlags(buildTagFlag),
Flags: subcommandFlags(buildTagFlag, fileFlag),
Action: func(ctx context.Context, cmd *cli.Command) error {
build, err := BuildConfigFrom(cmd)
if err != nil {
Expand All @@ -77,7 +78,7 @@ var Build = &cli.Command{

buildTag := sdk.String(cmd.String(buildTagFlag.Name))

res, err := build.SDK.BuildV2.CreateBuild(
createRes, err := build.SDK.BuildV2.CreateBuild(
ctx,
shared.CreateBuildParams{
BuildTag: buildTag,
Expand All @@ -88,32 +89,15 @@ var Build = &cli.Command{
return fmt.Errorf("failed to create a build: %w", err)
}

return build.Output.Write(res.Build, os.Stdout)
},
},
{
Name: "run",
Aliases: []string{"run-build"},
Usage: "run a build by id",
Flags: subcommandFlags(buildIDFlag, fileFlag),
Action: func(ctx context.Context, cmd *cli.Command) error {
build, err := OneBuildConfigFrom(cmd)
if err != nil {
return err
}
build.Log.Debug("running a build...")

filePath := cmd.String(fileFlag.Name)
file, err := archive.RequireTGZ(filePath)
if err != nil {
return fmt.Errorf("no tgz file available for run: %w", err)
}

build.Log.Debug("using archive file", zap.Any("file", file))

res, err := build.SDK.BuildV2.RunBuild(
runRes, err := build.SDK.BuildV2.RunBuild(
ctx,
build.BuildID,
createRes.Build.BuildID,
operations.RunBuildRequestBody{
File: operations.RunBuildFile{
FileName: file.Name,
Expand All @@ -122,15 +106,18 @@ var Build = &cli.Command{
},
build.AppID,
)

if err != nil {
return fmt.Errorf("failed to run build: %w", err)
}

return build.Output.Write(&DefaultResult{
Success: true,
Message: "Build ran successfully",
Code: res.StatusCode,
}, os.Stdout)
err = output.StreamOutput(runRes.Stream, os.Stderr)

if err != nil {
return fmt.Errorf("failed to stream output to console: %w", err)
}

return build.Output.Write(createRes.Build, os.Stdout)
},
},
{
Expand Down Expand Up @@ -183,6 +170,7 @@ var (
Aliases: []string{"bt"},
Sources: cli.NewValueSourceChain(
cli.EnvVar(buildFlagEnvVar("TAG")),
altsrc.File(configFlag.Name, "build.tag"),
),
Usage: "tag to associate an external version with a build",
}
Expand All @@ -192,6 +180,7 @@ var (
Aliases: []string{"f"},
Sources: cli.NewValueSourceChain(
cli.EnvVar(buildFlagEnvVar("FILE")),
altsrc.File(configFlag.Name, "build.file"),
),
Usage: "filepath of the built game server binary or archive",
Required: true,
Expand Down
Loading
Loading