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

feat: Add Ground Control #32

Merged
merged 9 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ require (

)

require github.com/spf13/viper v1.19.0
require (
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
)

require (
cloud.google.com/go v0.112.1 // indirect
Expand Down Expand Up @@ -346,7 +349,6 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/stefanberger/go-pkcs11uri v0.0.0-20230803200340-78284954bff6 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/swaggo/files v0.0.0-20220610200504-28940afbdbfe // indirect
github.com/swaggo/http-swagger v1.3.4 // indirect
Expand Down
46 changes: 46 additions & 0 deletions ground-control/.air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"

[build]
args_bin = []
bin = "./main"
cmd = "make build"
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
post_cmd = []
pre_cmd = []
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false

[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"

[log]
main_only = false
time = false

[misc]
clean_on_exit = false

[screen]
clear_on_rebuild = false
keep_scroll = true
29 changes: 29 additions & 0 deletions ground-control/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with "go test -c"
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
tmp/

# IDE specific files
.vscode
.idea

# .env file
.env

# Project build
main
72 changes: 72 additions & 0 deletions ground-control/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Simple Makefile for a Go project

# Build the application
all: build

build:
@echo "Building..."

@go build -o main cmd/main.go

# Run the application
run:
@go run cmd/main.go

# Create DB container
docker-run:
@if docker compose up 2>/dev/null; then \
: ; \
else \
echo "Falling back to Docker Compose V1"; \
docker-compose up; \
fi

# Shutdown DB container
docker-down:
@if docker compose down 2>/dev/null; then \
: ; \
else \
echo "Falling back to Docker Compose V1"; \
docker-compose down; \
fi

seed-db:
@go run ./seed/main.go

db-status:
@GOOSE_DRIVER=postgres GOOSE_DBSTRING=$(dsn) goose -dir=$(migrationPath) status

up:
@GOOSE_DRIVER=postgres GOOSE_DBSTRING=$(dsn) goose -dir=$(migrationPath) up

reset:
@GOOSE_DRIVER=postgres GOOSE_DBSTRING=$(dsn) goose -dir=$(migrationPath) reset

# Test the application
test:
@echo "Testing..."
@go test ./tests -v

# Clean the binary
clean:
@echo "Cleaning..."
@rm -f main

# Live Reload
watch:
@if command -v air > /dev/null; then \
air; \
echo "Watching...";\
else \
read -p "Go's 'air' is not installed on your machine. Do you want to install it? [Y/n] " choice; \
if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \
go install github.com/cosmtrek/air@latest; \
air; \
echo "Watching...";\
else \
echo "You chose not to install air. Exiting..."; \
exit 1; \
fi; \
fi

.PHONY: all build run test clean
18 changes: 18 additions & 0 deletions ground-control/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"fmt"

"container-registry.com/harbor-satellite/ground-control/internal/server"
_ "github.com/joho/godotenv/autoload"
)

func main() {
server := server.NewServer()

fmt.Printf("Ground Control running on port %s\n", server.Addr)
err := server.ListenAndServe()
if err != nil {
panic(fmt.Sprintf("cannot start server: %s", err))
}
}
25 changes: 25 additions & 0 deletions ground-control/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
services:
gc:
build: .
env_file:
- .env
ports:
- "8080:8080"
volumes:
- .:/app
command: air ./cmd/main.go

psql:
image: postgres:alpine
container_name: postgres
environment:
POSTGRES_DB: ${DB_DATABASE}
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_PASSWORD: ${DB_PASSWORD}
ports:
- "${DB_PORT}:5432"
volumes:
- psql_volume:/var/lib/postgresql/data

volumes:
psql_volume:
9 changes: 9 additions & 0 deletions ground-control/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM golang:1.22.4

WORKDIR /app

RUN go install github.com/air-verse/air@latest

COPY . .

RUN go mod download
9 changes: 9 additions & 0 deletions ground-control/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module container-registry.com/harbor-satellite/ground-control

go 1.22.4

require (
github.com/gorilla/mux v1.8.1
github.com/joho/godotenv v1.5.1
github.com/lib/pq v1.10.9
)
6 changes: 6 additions & 0 deletions ground-control/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
31 changes: 31 additions & 0 deletions ground-control/internal/database/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 81 additions & 0 deletions ground-control/internal/database/groups.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions ground-control/internal/database/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading