Skip to content

Commit 6a701d8

Browse files
authored
Merge pull request #8 from flatrun/feat/deployment-improvements
fix(deployments): Ensure deployment work & tests
2 parents e96e652 + 5559c5d commit 6a701d8

File tree

85 files changed

+4139
-80
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+4139
-80
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ jobs:
2525
GOOS=linux GOARCH=amd64 go build -o flatrun-linux-amd64 ./cmd/agent
2626
GOOS=linux GOARCH=arm64 go build -o flatrun-linux-arm64 ./cmd/agent
2727
28-
- name: Test
29-
run: go test -v ./...
28+
- name: Unit Tests
29+
run: make test-unit
3030

3131
- name: Upload Linux AMD64 binary
3232
uses: actions/upload-artifact@v4
@@ -56,3 +56,27 @@ jobs:
5656
uses: golangci/golangci-lint-action@v4
5757
with:
5858
version: latest
59+
60+
e2e-tests:
61+
runs-on: ubuntu-latest
62+
needs: build
63+
steps:
64+
- uses: actions/checkout@v4
65+
66+
- name: Set up Go
67+
uses: actions/setup-go@v5
68+
with:
69+
go-version: '1.21'
70+
71+
- name: Set up Docker Buildx
72+
uses: docker/setup-buildx-action@v3
73+
74+
- name: Start E2E environment
75+
run: make test-e2e-setup
76+
77+
- name: Run E2E tests
78+
run: make test-e2e-run
79+
80+
- name: Cleanup E2E environment
81+
if: always()
82+
run: make test-e2e-cleanup

.github/workflows/release.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ jobs:
1919
steps:
2020
- uses: actions/checkout@v4
2121

22+
- name: Read version from file
23+
id: version
24+
run: echo "version=$(cat VERSION)" >> $GITHUB_OUTPUT
25+
2226
- name: Create Release
2327
uses: whilesmart/workflows/go/release@main
2428
with:
2529
token: ${{ secrets.GITHUB_TOKEN }}
2630
binary_name: flatrun-agent
2731
build_path: ./cmd/agent
28-
version: ${{ github.event.inputs.version }}
32+
version: ${{ github.event.inputs.version || steps.version.outputs.version }}
2933
platforms: '["linux/amd64", "linux/arm64", "darwin/amd64", "darwin/arm64"]'
34+
ldflags: "-X github.com/flatrun/agent/pkg/version.Version=${{ github.event.inputs.version || steps.version.outputs.version }} -X github.com/flatrun/agent/pkg/version.BuildTime=$(date -u +%Y-%m-%d_%H:%M:%S) -X github.com/flatrun/agent/pkg/version.GitCommit=${{ github.sha }}"

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ flatrun-linux-*
88
*.so
99
*.dylib
1010

11-
# Test binary
12-
*.test
13-
1411
# Output of the go coverage tool
1512
*.out
1613

Makefile

Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
1-
.PHONY: help build run test clean deps lint lint-install fmt vet
1+
.PHONY: help build run test test-unit test-e2e test-e2e-docker test-e2e-setup test-e2e-run test-e2e-short test-e2e-cleanup test-coverage clean deps lint lint-install fmt vet
22

33
BINARY_NAME=flatrun-agent
4-
VERSION?=dev
4+
VERSION?=$(shell cat VERSION 2>/dev/null || echo "dev")
55
BUILD_TIME=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
66
GIT_COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
7-
LDFLAGS=-ldflags "-X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME) -X main.GitCommit=$(GIT_COMMIT)"
7+
LDFLAGS=-ldflags "-X github.com/flatrun/agent/pkg/version.Version=$(VERSION) -X github.com/flatrun/agent/pkg/version.BuildTime=$(BUILD_TIME) -X github.com/flatrun/agent/pkg/version.GitCommit=$(GIT_COMMIT)"
8+
9+
E2E_API_URL?=http://localhost:18090/api
10+
E2E_DEPLOYMENTS_PATH?=/tmp/flatrun-e2e-deployments
811

912
help:
1013
@echo "FlatRun Agent - Build commands"
1114
@echo ""
12-
@echo "make deps - Install dependencies"
13-
@echo "make build - Build binary"
14-
@echo "make run - Run in development mode"
15-
@echo "make test - Run tests"
16-
@echo "make lint - Run golangci-lint"
17-
@echo "make lint-install - Install golangci-lint"
18-
@echo "make fmt - Format code with gofmt"
19-
@echo "make vet - Run go vet"
20-
@echo "make clean - Clean build artifacts"
15+
@echo "make deps - Install dependencies"
16+
@echo "make build - Build binary"
17+
@echo "make run - Run in development mode"
18+
@echo "make test - Run unit tests"
19+
@echo "make test-unit - Run unit tests only"
20+
@echo "make test-e2e - Run E2E tests (requires running agent)"
21+
@echo "make test-e2e-docker - Run full E2E tests in Docker (setup + run + cleanup)"
22+
@echo "make test-e2e-setup - Start E2E Docker test environment"
23+
@echo "make test-e2e-run - Run E2E tests against Docker environment"
24+
@echo "make test-e2e-short - Run E2E tests (skip long-running)"
25+
@echo "make test-e2e-cleanup - Clean up Docker test environment"
26+
@echo "make test-coverage - Run tests with coverage report"
27+
@echo "make lint - Run golangci-lint"
28+
@echo "make lint-install - Install golangci-lint"
29+
@echo "make fmt - Format code with gofmt"
30+
@echo "make vet - Run go vet"
31+
@echo "make clean - Clean build artifacts"
2132

2233
deps:
2334
go mod download
@@ -29,8 +40,58 @@ build: deps
2940
run: deps
3041
go run cmd/agent/main.go --config config.example.yml
3142

32-
test:
33-
go test -v ./...
43+
test: test-unit
44+
45+
test-unit:
46+
@echo "Running unit tests..."
47+
go test -v ./templates/...
48+
go test -v ./internal/...
49+
go test -v ./pkg/...
50+
51+
test-e2e:
52+
@echo "Running E2E tests (requires running agent on port 8090)..."
53+
go test -v ./test/e2e/...
54+
55+
test-e2e-setup:
56+
@echo "Setting up E2E Docker test environment..."
57+
@mkdir -p $(E2E_DEPLOYMENTS_PATH)/nginx/conf.d
58+
@mkdir -p $(E2E_DEPLOYMENTS_PATH)/nginx/certs
59+
@chmod -R 777 $(E2E_DEPLOYMENTS_PATH) 2>/dev/null || true
60+
@docker network create web 2>/dev/null || true
61+
cd test/e2e && docker compose -f docker-compose.test.yml up -d --build
62+
@echo "Waiting for services to be healthy..."
63+
@timeout 120 bash -c 'until docker exec flatrun-e2e-agent wget -q -O /dev/null http://127.0.0.1:8090/api/health 2>/dev/null; do sleep 2; done' || (echo "Agent failed to start" && exit 1)
64+
@chmod -R 777 $(E2E_DEPLOYMENTS_PATH) 2>/dev/null || true
65+
@echo "E2E environment ready at $(E2E_API_URL)"
66+
67+
test-e2e-run:
68+
@echo "Running E2E tests against Docker environment..."
69+
FLATRUN_API_URL=$(E2E_API_URL) FLATRUN_DEPLOYMENTS_PATH=$(E2E_DEPLOYMENTS_PATH) go test -v -timeout 10m ./test/e2e/...
70+
71+
test-e2e-docker: test-e2e-setup test-e2e-run
72+
@echo "E2E tests completed. Run 'make test-e2e-cleanup' to remove containers."
73+
74+
test-e2e-docker-full: test-e2e-setup test-e2e-run test-e2e-cleanup
75+
@echo "E2E tests completed and cleaned up."
76+
77+
test-e2e-short:
78+
@echo "Running E2E tests (short mode)..."
79+
FLATRUN_API_URL=$(E2E_API_URL) FLATRUN_DEPLOYMENTS_PATH=$(E2E_DEPLOYMENTS_PATH) go test -v -short -timeout 5m ./test/e2e/...
80+
81+
test-e2e-cleanup:
82+
@echo "Cleaning up E2E test environment..."
83+
cd test/e2e && docker compose -f docker-compose.test.yml down -v --remove-orphans 2>/dev/null || true
84+
@docker network rm web 2>/dev/null || true
85+
@rm -rf $(E2E_DEPLOYMENTS_PATH)/* 2>/dev/null || true
86+
@echo "Cleanup complete"
87+
88+
test-coverage:
89+
@echo "Running tests with coverage..."
90+
go test -coverprofile=coverage.out ./...
91+
go tool cover -html=coverage.out -o coverage.html
92+
@echo "Coverage report generated: coverage.html"
93+
94+
test-all: test-unit test-e2e
3495

3596
lint:
3697
@command -v golangci-lint > /dev/null 2>&1 && golangci-lint run ./... || \

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.3

cmd/agent/main.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,20 @@ import (
1111
"github.com/flatrun/agent/internal/api"
1212
"github.com/flatrun/agent/internal/watcher"
1313
"github.com/flatrun/agent/pkg/config"
14-
)
15-
16-
var (
17-
Version = "dev"
18-
BuildTime = "unknown"
19-
GitCommit = "unknown"
14+
"github.com/flatrun/agent/pkg/version"
2015
)
2116

2217
func main() {
2318
configPath := flag.String("config", "config.yml", "Path to configuration file")
24-
version := flag.Bool("version", false, "Print version information")
19+
showVersion := flag.Bool("version", false, "Print version information")
2520
flag.Parse()
2621

27-
if *version {
22+
if *showVersion {
23+
info := version.Get()
2824
fmt.Printf("Flatrun Agent\n")
29-
fmt.Printf("Version: %s\n", Version)
30-
fmt.Printf("Build Time: %s\n", BuildTime)
31-
fmt.Printf("Git Commit: %s\n", GitCommit)
25+
fmt.Printf("Version: %s\n", info.Version)
26+
fmt.Printf("Build Time: %s\n", info.BuildTime)
27+
fmt.Printf("Git Commit: %s\n", info.GitCommit)
3228
os.Exit(0)
3329
}
3430

@@ -37,7 +33,7 @@ func main() {
3733
log.Fatalf("Failed to load config: %v", err)
3834
}
3935

40-
log.Printf("Starting Flatrun Agent v%s", Version)
36+
log.Printf("Starting Flatrun Agent v%s", version.Version)
4137
log.Printf("Deployments path: %s", cfg.DeploymentsPath)
4238
log.Printf("API listening on: %s:%d", cfg.API.Host, cfg.API.Port)
4339

0 commit comments

Comments
 (0)