diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..30339b4 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,101 @@ +name: release + +on: + push: + tags: + - 'v*' + +jobs: + build_linux: + runs-on: ubuntu-latest + defaults: + run: + shell: bash + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.19' + + - name: Build Linux + run: 'make release' + + - name: Upload Linux Build + uses: actions/upload-artifact@v3 + with: + name: linux_build_${{ github.run_id }} + path: build + + build_darwin: + runs-on: macos-latest + defaults: + run: + shell: bash + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.19' + + - name: Build Darwin + run: 'make release' + + - name: Upload Darwin Build + uses: actions/upload-artifact@v3 + with: + name: darwin_build_${{ github.run_id }} + path: build + + release: + runs-on: ubuntu-latest + needs: [build_linux, build_darwin] + steps: + - uses: actions/checkout@v3 + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: false + + - name: Download Linux Build + uses: actions/download-artifact@v3 + with: + name: linux_build_${{ github.run_id }} + + - name: Download Darwin Build + uses: actions/download-artifact@v3 + with: + name: darwin_build_${{ github.run_id }} + + - name: Upload Release Assets + id: upload_release_assets + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: '*.zip' + tag: ${{ github.ref }} + overwrite: true + file_glob: true + + update_latest: + runs-on: ubuntu-latest + needs: [release] + defaults: + run: + shell: bash + steps: + - uses: actions/setup-go@v4 + with: + go-version: '1.19' + - name: Update go package to latest + run: go install github.com/robgonnella/ops@"${GITHUB_REF#refs/tags/}" diff --git a/Makefile b/Makefile index c75d83a..c27a15d 100644 --- a/Makefile +++ b/Makefile @@ -1,30 +1,109 @@ -PREFIX = $(shell pwd)/build +#### Vars #### + +platform = $(shell uname -s) + +prefix = $(shell pwd)/build + +app_name = ops go_deps = $(shell find . -name '*.go') +tag = $(shell git describe --tags $(shell git rev-list --tags --max-count=1)) + +flags = -ldflags '-s -w' + +#### Build Objects #### +component = $(app_name)_$(tag) +component_path = $(prefix)/$(component) + +linux_objects = $(component_path)_linux_amd64 \ +$(component_path)_linux_arm_5 \ +$(component_path)_linux_arm_6 \ +$(component_path)_linux_arm_7 \ +$(component_path)_linux_arm64 + +darwin_object = $(component_path)_darwin_amd64 \ +$(component_path)_darwin_arm64 + +#### Gather Objects #### + +ifeq ($(platform),Linux) +objects := $(linux_objects) +else +objects := $(darwin_object) +endif + +#### Zip File Objects #### +$(foreach o,$(objects), $(eval zips += $(o).zip)) + +#### Helper Functions #### + +define get_goos +$(word 3, $(subst _, ,$1)) +endef + +define get_goarch +$(word 4, $(subst _, ,$1)) +endef + +define get_goarm +$(word 5, $(subst _, ,$1)) +endef + +#### Rules Section #### + +# builds main executable .PHONY: all -all: $(PREFIX)/ops +all: $(app_name) -$(PREFIX)/ops: $(go_deps) - cd cli && go build -ldflags '-s -w' -o $(@) +# builds main executable +$(prefix)/$(app_name): $(go_deps) + go build $(flags) -o $(@) -$(PREFIX)/ops-dev: $(go_deps) - cd cli && go build -race -ldflags '-s -w' -o $(@) +# build main executable +.PHONY: $(app_name) +$(app_name): $(prefix)/$(app_name) -.PHONY: ops -ops: $(PREFIX)/ops +# build develpment version of main executable +$(prefix)/$(app_name)-dev: $(go_deps) + go build -race $(flags) -o $(@) +# build develpment version of main executable .PHONY: dev -dev: $(PREFIX)/ops-dev +dev: $(prefix)/$(app_name)-dev + +# installs main executable in user's default bin for golang +.PHONY: install +install: + go install $(flags) + +# cross compiles binaries for linux and darwin +$(objects): $(go_deps) + $(eval goos=$(call get_goos, $(@))) + $(eval goarch=$(call get_goarch, $(@))) + $(eval goarm=$(call get_goarm, $(@))) + GOOS=$(goos) GOARCH=$(goarch) GOARM=$(goarm) go build $(flags) -o $(@) + +# creates zips of pre-built binaries +$(zips): $(objects) + zip -j $(@) $(@:.zip=) + +# generates a relase of all pre-built binaries +.PHONY: release +release: $(zips) +# run tests .PHONY: test test: go test -v -race ./... +# generate mocks .PHONY: mock mock: go generate ./... +# remove buid directory and installed executable .PHONY: clean clean: - rm -rf $(PREFIX) + rm -f $(GOPATH)/bin/$(app_name) + rm -rf $(prefix) diff --git a/README.md b/README.md index d60f765..9e70d03 100644 --- a/README.md +++ b/README.md @@ -2,37 +2,76 @@ ## On-Prem Server Management -## Getting Started +Ops is a terminal UI application for managing on-premise bare-metal servers +and VMs. It allows you see servers currently on your network and quickly ssh to +them. Within the UI, you can create and manage multiple network configurations, +you can choose a default set of ssh credentials to use for all servers, and you +can override those defaults for individual IPs where needed. -- Install dependencies +This project is heavily inspired by [derailed]'s amazing work on [k9s] for +managing kubernetes clusters via a terminal ui application. -```bash -brew install go -brew install nmap -brew install ansible -``` +## Installation -- Ensure the path variables are set for golang: +- homebrew +```bash +brew install ops ``` -export GOPATH="$HOME/go" -PATH="${GOPATH}/bin:$PATH" -``` - -- Build ops +- source build & pre-built binaries + - dependencies + - golang + - make + - ansible + - nmap + - install pre-built binaries + - https://github.com/robgonnella/ops/releases + - build from source ```bash -make ops +git clone https://github.com/robgonnella/ops.git +cd ops +make install ``` -- launch ops ui and scan network +## Usage + +On first launch a default configuration will be generated based on your machines +default network settings. If your machine is not connected to a network the app +will fail to start. + +- start application ```bash -./build/ops +ops ``` - clear database file and log file ```bash -./build/ops clear +ops clear ``` + +## Files and Config + +- `ops.db`: Configurations and server details are stored locally on your machine + in a sqlite database located in your machines default cache directory. On Unix + systems, it returns `$XDG_CACHE_HOME` if non-empty, else `$HOME/.cache`. On + Darwin, it returns `$HOME/Library/Caches`. +- `ops.log`: Additional logging `~/.config/ops/ops.log` + +## Technologies + +- [tview] is used to build the frontend. This is a wonderful open source + terminal ui library provided by [rivo]! +- [nmap] is used on the backend to perform arp scanning of networks to find + and track devices. +- [ansible] is also used on the backend to gather additional details about a + device where ssh is granted + +[rivo]: https://github.com/rivo +[tview]: https://github.com/rivo/tview +[ansible]: https://docs.ansible.com/ +[nmap]: https://nmap.org/ +[k9s]: https://github.com/derailed/k9s +[derailed]: https://github.com/derailed diff --git a/cli/main.go b/main.go similarity index 100% rename from cli/main.go rename to main.go