Skip to content

Commit

Permalink
Build debs and rpms for general linux (#44)
Browse files Browse the repository at this point in the history
* WIP - fpm for deb + rpm

* Add zip extension to zipfile

* Cut 1.0.0

* Some fixes

* Use usr/sbin/goat
* Add environment variables GOAT_LOG_LEVEL and GOAT_TAG_PREFIX
  • Loading branch information
sevagh authored Nov 7, 2018
1 parent ecc5743 commit fd9838a
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 94 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bin/
rpm-package/goat
goat
pkg/
40 changes: 30 additions & 10 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
NAME:=goat
VERSION:=0.9.0
VERSION:=1.0.0
OS:=linux
ARCH:=amd64
GOAT_FILES?=$$(find . -name '*.go' | grep -v vendor)
BINPATH=usr/sbin

all: build

build: deps
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo -ldflags '-w -extldflags "-static" -X main.VERSION=$(VERSION)' -o bin/$(NAME)
strip bin/$(NAME)
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -a -tags netgo -ldflags '-w -extldflags "-static" -X main.VERSION=$(VERSION)' -o $(BINPATH)/$(NAME)
strip $(BINPATH)/$(NAME)

test:
@go vet ./...
Expand All @@ -22,18 +25,35 @@ fmt:
lint:
-gometalinter.v2 --enable-all $(GOAT_FILES) --exclude=_test.go

package_all: pkgclean build deb rpm zip

zip:
@zip pkg/$(NAME)_$(VERSION)_$(OS)_$(ARCH).zip -j $(BINPATH)/$(NAME)

deb:
@mkdir -p pkg
fpm -s dir -t deb -n $(NAME) -v $(VERSION) -C . \
-p pkg/$(NAME)_VERSION_ARCH.deb \
-d "mdadm" \
--deb-systemd ./goat@.service \
$(BINPATH)

rpm:
@mkdir -p pkg
fpm -s dir -t rpm -n $(NAME) -v $(VERSION) -C . \
-p pkg/$(NAME)_VERSION_ARCH.rpm \
-d "mdadm" \
--rpm-systemd ./goat@.service \
$(BINPATH)

pkgclean:
@rm -rf pkg

lintsetup:
@go get -u gopkg.in/alecthomas/gometalinter.v2
@gometalinter.v2 --install 2>&1 >/dev/null
@go install ./...

clean:
-rm -rf bin

rpm: build
@cp bin/goat rpm-package/
GOAT_VERSION=$(VERSION) $(MAKE) -C ./rpm-package/

dev-env: ## Build a local development environment using Docker
@docker run -it --rm \
-v $(shell pwd):/go/src/github.com/sevagh/$(NAME) \
Expand Down
41 changes: 34 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
[![ReportCard](http://goreportcard.com/badge/sevagh/goat)](http://goreportcard.com/report/sevagh/goat) [![GitHub tag](https://img.shields.io/github/tag/sevagh/goat.svg)](https://github.com/sevagh/goat/releases)

# goat :goat:

### Attach EBS volumes and ENIs to running EC2 instances
Expand All @@ -16,16 +14,45 @@ It's necessary for the instance to have an IAM Role with _at least_ access to th

Unfortunately, resource-level permissions are [currently not supported](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/ec2-api-permissions.html#ec2-api-unsupported-resource-permissions) for attaching network interfaces. This means that to use `goat@eni`, your instances must have full permissions for __all__ ENIs.

### RPM-based install
### Install and run

Goat is a Go binary that should be able to run on any Linux instance.

In the releases tab you can find a zip of the binary, and a `.deb` and `.rpm` package with systemd support generated by [fpm](https://github.com/jordansissel/fpm).

To use goat, run it during the launch process of your EC2 instance - you can `systemctl enable goat@TARGET` and `systemctl start goat@TARGET` (where TARGET is one of ebs or eni).

It's a Linux-specific tool which needs `mdadm` to work for the RAID features.

#### Usage

Goat is systemd-based and has been developed for CentOS. Install the rpm from the releases page:
In the most basic case, you should run `goat ebs` or `goat eni`.

Full usage:

```
$ sudo yum install -y https://github.com/sevagh/goat/releases/download/0.6.0/goat-0.6.0-1.fc27.x86_64.rpm
$ sudo systemctl enable goat@ebs
$ sudo systemctl start goat@ebs
Usage: goat [OPTIONS] ebs|eni
OPTIONS
-debug
Interactive debug prompts
-logLevel string
Log level (default "info")
-tagPrefix string
Prefix for GOAT related tags (default "GOAT-IN")
-version
Display version and exit
```

### Environment variables

You can use the environment variables:

* `GOAT_LOG_LEVEL`
* `GOAT_TAG_PREFIX`

Set these the same as `-logLevel` and `-tagPrefix` - the environment variables take precedence.

### Additional dependencies for ENI

Goat by itself is sufficient for the EBS feature, but needs help for setting up an ENI. Refer to [this](./docs/ENI.md#setting-up-the-eni---ec2-net-utils) document.
Expand Down
4 changes: 2 additions & 2 deletions rpm-package/goat@.service → goat@.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ Description=GOAT: EC2-%i attach utility
Documentation=https://github.com/sevagh/goat
Requires=network.target remote-fs.target
After=network.target remote-fs.target
ConditionPathExists=/usr/bin/goat
ConditionPathExists=/usr/sbin/goat

[Service]
Type=oneshot
User=root
Group=root
ExecStart=/usr/bin/goat "%i" --log-level=info
ExecStart=/usr/sbin/goat "%i"
SyslogIdentifier=goat

[Install]
Expand Down
34 changes: 29 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,44 @@ func main() {
debugPtr := flag.Bool("debug", false, "Interactive debug prompts")
tagPrefixPtr := flag.String("tagPrefix", "GOAT-IN", "Prefix for GOAT related tags")

tagPrefixEnv := os.Getenv("GOAT_TAG_PREFIX")
logLevelEnv := os.Getenv("GOAT_LOG_LEVEL")

flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: goat [OPTIONS] ebs|eni\n\nOPTIONS\n")
flag.PrintDefaults()
}

flag.Parse()

if *versionPtr {
fmt.Printf("goat %s", VERSION)
fmt.Println("goat ", VERSION)
os.Exit(0)
}

if flag.NArg() != 1 {
log.Fatalf("Usage: goat [OPTIONS] ebs|eni")
flag.Usage()
os.Exit(1)
}

command := flag.Args()[0]

logLevel := ""
if logLevelEnv != "" {
logLevel = logLevelEnv // env var takes precedence
} else {
logLevel = *logLevelPtr
}

tagPrefix := ""
if tagPrefixEnv != "" {
tagPrefix = tagPrefixEnv
} else {
tagPrefix = *tagPrefixPtr
}

log.SetOutput(os.Stderr)
if level, err := log.ParseLevel(*logLevelPtr); err != nil {
if level, err := log.ParseLevel(logLevel); err != nil {
log.Fatalf("%v", err)
} else {
log.SetLevel(level)
Expand All @@ -39,9 +63,9 @@ func main() {

log.Printf("Running goat for %s", command)
if command == "ebs" {
GoatEbs(*debugPtr, *tagPrefixPtr)
GoatEbs(*debugPtr, tagPrefix)
} else if command == "eni" {
GoatEni(*debugPtr, *tagPrefixPtr)
GoatEni(*debugPtr, tagPrefix)
} else {
log.Fatalf("Unrecognized command: %s", command)
}
Expand Down
5 changes: 0 additions & 5 deletions rpm-package/GNUmakefile

This file was deleted.

63 changes: 0 additions & 63 deletions rpm-package/specfile.spec

This file was deleted.

0 comments on commit fd9838a

Please sign in to comment.