Skip to content

Commit

Permalink
[#365,#366] Change consolidation PR (#367)
Browse files Browse the repository at this point in the history
* Add SSH key validation steps
* Add the ground-work for passphrase support
* fix linting issues
* Fix test and _some_ goimports
* remove test
* hide passphrase flags
* hide passphrase flags
* expose config in ci
* make agent lighter in weight
* fix hiding of flags
* Be more forceful with SortedService ordering
* Do I really need to test this? Gah!
* Do I really need to test this? Gah!
* Do I really need to test this? Gah!
* Do I really need to test this? Gah!
* use yq instead
* use yq instead
* test sortedservices properly
* updates for linting
* Change all references from pygmy-go to pygmy.
* hmm... silly fail
* Update legacy pygmy-go references
  • Loading branch information
fubarhouse committed Jan 25, 2022
1 parent 93af147 commit e273e01
Show file tree
Hide file tree
Showing 22 changed files with 301 additions and 174 deletions.
54 changes: 29 additions & 25 deletions .github/workflows/pygmy.yml
Expand Up @@ -48,7 +48,7 @@ jobs:
# - name: Switch Docker daemon mode to Linux
# run: Start-Process $Env:ProgramFiles\Docker\Docker\DockerCli.exe -ArgumentList "-SwitchLinuxEngine"
# - name: Build
# run: docker build -t pygmy-go .
# run: docker build -t pygmy.
# - name: Run status command
# run: builds/${PYGMY_PATH} --config examples/pygmy.basic.yml status;
# - name: Run version command
Expand Down Expand Up @@ -82,29 +82,33 @@ jobs:
sudo dpkg -i --ignore-depends=docker-ce lando-stable.deb;
- name: Compile
run: go build -o pygmy-go-linux-amd64
run: go build -o pygmy-linux-amd64

- name: Basic test
run: |
./pygmy-go-linux-amd64 pull;
./pygmy-go-linux-amd64 pull;
./pygmy-go-linux-amd64 status;
./pygmy-go-linux-amd64 --config examples/pygmy.basic.yml up;
./pygmy-go-linux-amd64 --config examples/pygmy.basic.yml status;
./pygmy-go-linux-amd64 --config examples/pygmy.basic.yml version;
./pygmy-linux-amd64 pull;
./pygmy-linux-amd64 pull;
./pygmy-linux-amd64 status;
./pygmy-linux-amd64 --config examples/pygmy.basic.yml up;
./pygmy-linux-amd64 --config examples/pygmy.basic.yml status;
./pygmy-linux-amd64 --config examples/pygmy.basic.yml version;
- name: Show pygmy image versions
run: |
docker ps -a --filter "label=pygmy.name"
- name: Export configuration
run: ./pygmy-linux-amd64 export -o ./exported-config.yml

- name: Show configuration
run: cat ./exported-config.yml

- name: SSH Key test
run: |
./pygmy-go-linux-amd64 addkey /home/runner/.ssh/id_rsa.pub;
./pygmy-go-linux-amd64 addkey /home/runner/.ssh/id_pwd.pub;
./pygmy-go-linux-amd64 status;
./pygmy-go-linux-amd64 status | grep 'id_rsa';
./pygmy-linux-amd64 addkey /home/runner/.ssh/id_rsa.pub;
./pygmy-linux-amd64 status;
./pygmy-linux-amd64 status | grep 'id_rsa';
docker run --rm -i --volumes-from amazeeio-ssh-agent uselagoon/php-7.4-cli /usr/bin/ssh-add -l | grep 'id_rsa';
# ./pygmy-go-linux-amd64 status | grep 'id_pwd';
- name: Resolv file test
run: |
Expand Down Expand Up @@ -151,7 +155,7 @@ jobs:
sleep 5;
curl --HEAD http://drupal9-example-advanced.docker.amazee.io;
curl --HEAD http://drupal9-example-advanced.docker.amazee.io | grep "X-LAGOON";
../../pygmy-go-linux-amd64 --config ../../examples/pygmy.basic.yml status | grep '\- http://drupal9-example-advanced.docker.amazee.io';
../../pygmy-linux-amd64 --config ../../examples/pygmy.basic.yml status | grep '\- http://drupal9-example-advanced.docker.amazee.io';
docker-compose -p drupal9-advanced down;
docker-compose -p drupal9-advanced rm;
cd ../../;
Expand All @@ -164,7 +168,7 @@ jobs:
sleep 5;
curl --HEAD http://drupal9-base.docker.amazee.io;
curl --HEAD http://drupal9-base.docker.amazee.io | grep "X-LAGOON";
../../pygmy-go-linux-amd64 --config ../../examples/pygmy.basic.yml status | grep '\- http://drupal9-base.docker.amazee.io';
../../pygmy-linux-amd64 --config ../../examples/pygmy.basic.yml status | grep '\- http://drupal9-base.docker.amazee.io';
docker-compose -p drupal-base down;
docker-compose -p drupal-base rm;
cd ../../;
Expand All @@ -177,7 +181,7 @@ jobs:
sleep 5;
curl --HEAD http://drupal9-postgres.docker.amazee.io;
curl --HEAD http://drupal9-postgres.docker.amazee.io | grep "X-LAGOON";
../../pygmy-go-linux-amd64 --config ../../examples/pygmy.basic.yml status | grep '\- http://drupal9-postgres.docker.amazee.io';
../../pygmy-linux-amd64 --config ../../examples/pygmy.basic.yml status | grep '\- http://drupal9-postgres.docker.amazee.io';
docker-compose -p drupal-postgres down;
docker-compose -p drupal-postgres rm;
cd ../../;
Expand All @@ -189,7 +193,7 @@ jobs:
docker-compose -p node up -d;
curl --HEAD http://node.docker.amazee.io;
curl --HEAD http://node.docker.amazee.io | grep "X-LAGOON";
../../pygmy-go-linux-amd64 --config ../../examples/pygmy.basic.yml status | grep '\- http://node.docker.amazee.io';
../../pygmy-linux-amd64 --config ../../examples/pygmy.basic.yml status | grep '\- http://node.docker.amazee.io';
docker-compose -p node down;
docker-compose -p node rm;
cd ../../;
Expand Down Expand Up @@ -227,7 +231,7 @@ jobs:
sleep 5;
curl --HEAD http://wordpress-example-simple.docker.amazee.io;
curl --HEAD http://wordpress-example-simple.docker.amazee.io | grep "X-LAGOON";
../../pygmy-go-linux-amd64 --config ../../examples/pygmy.basic.yml status | grep '\- http://wordpress-example-simple.docker.amazee.io';
../../pygmy-linux-amd64 --config ../../examples/pygmy.basic.yml status | grep '\- http://wordpress-example-simple.docker.amazee.io';
docker-compose -p wordpress-simple down;
docker-compose -p wordpress-simple rm;
cd ../../;
Expand All @@ -244,17 +248,17 @@ jobs:
- name: Test the down command
run: |
./pygmy-go-linux-amd64 --config examples/pygmy.basic.yml down | grep 'Successfully stopped amazeeio';
./pygmy-go-linux-amd64 --config examples/pygmy.basic.yml status | grep '\[ \] amazeeio-' | grep 'is not running';
./pygmy-go-linux-amd64 --config examples/pygmy.basic.yml status | grep 'Running as container amazeeio-' && false || true;
./pygmy-go-linux-amd64 --config examples/pygmy.basic.yml up;
./pygmy-go-linux-amd64 --config examples/pygmy.basic.yml status | grep 'Running as container amazeeio-' && true || false;
./pygmy-linux-amd64 --config examples/pygmy.basic.yml down | grep 'Successfully stopped amazeeio';
./pygmy-linux-amd64 --config examples/pygmy.basic.yml status | grep '\[ \] amazeeio-' | grep 'is not running';
./pygmy-linux-amd64 --config examples/pygmy.basic.yml status | grep 'Running as container amazeeio-' && false || true;
./pygmy-linux-amd64 --config examples/pygmy.basic.yml up;
./pygmy-linux-amd64 --config examples/pygmy.basic.yml status | grep 'Running as container amazeeio-' && true || false;
- name: Cowsay test
run: ./pygmy-go-linux-amd64 --config examples/pygmy.basic.yml up | grep 'holy ship' || true;
run: ./pygmy-linux-amd64 --config examples/pygmy.basic.yml up | grep 'holy ship' || true;

- name: Cleanup pygmy
run: ./pygmy-go-linux-amd64 clean;
run: ./pygmy-linux-amd64 clean;

- name: Cleanup after tests.
run: |
Expand Down
18 changes: 9 additions & 9 deletions .goreleaser.yml
Expand Up @@ -3,16 +3,16 @@ env:
- GOPROXY=https://gocenter.io

archives:
- id: pygmy-go
- id: pygmy
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
builds:
- pygmy-go
- id: pygmy-go-static
- pygmy
- id: pygmy-static
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}_static"
builds:
- pygmy-go-static
- pygmy-static
builds:
- id: pygmy-go
- id: pygmy
env:
- CGO_ENABLED=0
goos:
Expand All @@ -24,7 +24,7 @@ builds:
- amd64
- arm
- arm64
- id: pygmy-go-static
- id: pygmy-static
env:
- CGO_ENABLED=0
flags:
Expand All @@ -41,13 +41,13 @@ builds:

brews:
- ids:
- pygmy-go
- pygmy
tap:
owner: pygmystack
name: homebrew-pygmy
folder: Formula
homepage: "https://github.com/pygmystack/pygmy"
description: "amazee.io's local development helper tool"
skip_upload: false
test: system "#{bin}/pygmy-go version"
install: bin.install "pygmy-go"
test: system "#{bin}/pygmy version"
install: bin.install "pygmy"
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

44 changes: 22 additions & 22 deletions Dockerfile
Expand Up @@ -8,28 +8,28 @@ COPY service/ /go/src/github.com/pygmystack/pygmy/service/

WORKDIR /go/src/github.com/pygmystack/pygmy/
RUN GO111MODULE=on go mod verify
RUN GO111MODULE=on GOOS=linux GOARCH=386 go build -o pygmy-go-linux-386 .
RUN GO111MODULE=on GOOS=linux GOARCH=386 CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' -o pygmy-go-linux-386-static .
RUN GO111MODULE=on GOOS=linux GOARCH=arm go build -o pygmy-go-linux-arm .
RUN GO111MODULE=on GOOS=linux GOARCH=arm CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' -o pygmy-go-linux-arm-static .
RUN GO111MODULE=on GOOS=linux GOARCH=arm64 go build -o pygmy-go-linux-arm64 .
RUN GO111MODULE=on GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' -o pygmy-go-linux-arm64-static .
RUN GO111MODULE=on GOOS=linux GOARCH=amd64 go build -o pygmy-go-linux-amd64 .
RUN GO111MODULE=on GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' -o pygmy-go-linux-amd64-static .
RUN GO111MODULE=on GOOS=darwin GOARCH=amd64 go build -o pygmy-go-darwin-amd64 .
RUN GO111MODULE=on GOOS=darwin GOARCH=arm64 go build -o pygmy-go-darwin-arm64 .
RUN GO111MODULE=on GOOS=windows GOARCH=amd64 go build -o pygmy-go.exe .
RUN GO111MODULE=on GOOS=linux GOARCH=386 go build -o pygmy-linux-386 .
RUN GO111MODULE=on GOOS=linux GOARCH=386 CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' -o pygmy-linux-386-static .
RUN GO111MODULE=on GOOS=linux GOARCH=arm go build -o pygmy-linux-arm .
RUN GO111MODULE=on GOOS=linux GOARCH=arm CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' -o pygmy-linux-arm-static .
RUN GO111MODULE=on GOOS=linux GOARCH=arm64 go build -o pygmy-linux-arm64 .
RUN GO111MODULE=on GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' -o pygmy-linux-arm64-static .
RUN GO111MODULE=on GOOS=linux GOARCH=amd64 go build -o pygmy-linux-amd64 .
RUN GO111MODULE=on GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' -o pygmy-linux-amd64-static .
RUN GO111MODULE=on GOOS=darwin GOARCH=amd64 go build -o pygmy-darwin-amd64 .
RUN GO111MODULE=on GOOS=darwin GOARCH=arm64 go build -o pygmy-darwin-arm64 .
RUN GO111MODULE=on GOOS=windows GOARCH=amd64 go build -o pygmy.exe .

FROM alpine
WORKDIR /app
COPY --from=builder /go/src/github.com/pygmystack/pygmy/pygmy-go-linux-386 .
COPY --from=builder /go/src/github.com/pygmystack/pygmy/pygmy-go-linux-386-static .
COPY --from=builder /go/src/github.com/pygmystack/pygmy/pygmy-go-linux-arm .
COPY --from=builder /go/src/github.com/pygmystack/pygmy/pygmy-go-linux-arm-static .
COPY --from=builder /go/src/github.com/pygmystack/pygmy/pygmy-go-linux-arm64 .
COPY --from=builder /go/src/github.com/pygmystack/pygmy/pygmy-go-linux-arm64-static .
COPY --from=builder /go/src/github.com/pygmystack/pygmy/pygmy-go-linux-amd64 .
COPY --from=builder /go/src/github.com/pygmystack/pygmy/pygmy-go-linux-amd64-static .
COPY --from=builder /go/src/github.com/pygmystack/pygmy/pygmy-go-darwin-amd64 .
COPY --from=builder /go/src/github.com/pygmystack/pygmy/pygmy-go-darwin-arm64 .
COPY --from=builder /go/src/github.com/pygmystack/pygmy/pygmy-go.exe .
COPY --from=builder /go/src/github.com/pygmystack/pygmy/pygmy-linux-386 .
COPY --from=builder /go/src/github.com/pygmystack/pygmy/pygmy-linux-386-static .
COPY --from=builder /go/src/github.com/pygmystack/pygmy/pygmy-linux-arm .
COPY --from=builder /go/src/github.com/pygmystack/pygmy/pygmy-linux-arm-static .
COPY --from=builder /go/src/github.com/pygmystack/pygmy/pygmy-linux-arm64 .
COPY --from=builder /go/src/github.com/pygmystack/pygmy/pygmy-linux-arm64-static .
COPY --from=builder /go/src/github.com/pygmystack/pygmy/pygmy-linux-amd64 .
COPY --from=builder /go/src/github.com/pygmystack/pygmy/pygmy-linux-amd64-static .
COPY --from=builder /go/src/github.com/pygmystack/pygmy/pygmy-darwin-amd64 .
COPY --from=builder /go/src/github.com/pygmystack/pygmy/pygmy-darwin-arm64 .
COPY --from=builder /go/src/github.com/pygmystack/pygmy/pygmy.exe .
10 changes: 5 additions & 5 deletions Makefile
Expand Up @@ -3,16 +3,16 @@ SHELL := /bin/bash
DIR := ${CURDIR}

build:
docker build -t pygmy-go .
docker build -t pygmy .
@echo "Removing binaries from previous build"
docker run --rm -v $(DIR):/data pygmy-go sh -c 'rm -f /data/builds/pygmy-go*'
docker run --rm -v $(DIR):/data pygmy sh -c 'rm -f /data/builds/pygmy*'
@echo "Done"
@echo "Copying binaries to build directory"
docker run --rm -v $(DIR):/data pygmy-go sh -c 'cp pygmy-g* /data/builds/.'
docker run --rm -v $(DIR):/data pygmy sh -c 'cp pygmy* /data/builds/.'
@echo "Done"
@echo "Enjoy using pygmy-go binaries in the $(DIR)/build directory."
@echo "Enjoy using pygmy binaries in the $(DIR)/build directory."

clean:
docker image rm -f pygmy-go
docker image rm -f pygmy
docker image prune -f --filter="label=stage=builder"

29 changes: 16 additions & 13 deletions README.md
Expand Up @@ -21,7 +21,7 @@ past on Windows.

## Is Pygmy running?

These instructions will currently install the new version as `pygmy-go` so that the
These instructions will currently install the new version as `pygmy` so that the
old version is still available if you have installed it. With no Pygmy running,
you should get "connection refused" when attempting to connect to the local amazee network.

Expand All @@ -43,13 +43,13 @@ configuration to switch out the `haproxy` image for a compatible one if you'd li
**Works for**: Linux, MacOS & Windows

```shell
git clone https://github.com/pygmystack/pygmy.git && cd pygmy-go;
git clone https://github.com/pygmystack/pygmy.git && cd pygmy;
make build;
cp ./builds/pygmy-go-darwin /usr/local/bin/pygmy-go;
chmod +x /usr/local/bin/pygmy-go;
cp ./builds/pygmy-darwin /usr/local/bin/pygmy;
chmod +x /usr/local/bin/pygmy;
```

Pygmy is now an executable as `pygmy-go`, while any existing Pygmy is still executable
Pygmy is now an executable as `pygmy`, while any existing Pygmy is still executable
as `pygmy`. Now start Pygmy and use the new `status` command.

### Using Homebrew
Expand All @@ -65,16 +65,19 @@ brew install pygmy;

**Works for**: [Arch-based Linux Distributions](https://wiki.archlinux.org/title/Arch-based_distributions) (Manjaro, Elementary, ArcoLinux etc)

[pygmy-go](https://aur.archlinux.org/packages/pygmy-go/) and [pygmy-go-git](https://aur.archlinux.org/packages/pygmy-go-git/)
are available via the Arch User Repository for Arch-based Linux distributions on the community stream. Unfortunately,
Pygmy is not yet available via other distribution methods, so it is otherwise recommended to use homebrew or compile
from source.
[pygmy](https://aur.archlinux.org/packages/pygmy/), [pygmy-bin](https://aur.archlinux.org/packages/pygmy-bin/) and
[pygmy-git](https://aur.archlinux.org/packages/pygmy-git/) are available via the Arch User Repository for Arch-based
Linux distributions on the community stream. Unfortunately, Pygmy is not yet available via other distribution methods,
so it is otherwise recommended to use homebrew to install it, download a pre-compiled binary from the releases page, or
to compile from source.

```shell
# Install the latest release:
yay -S pygmy-go;
# Freshly compile the latest release:
yay -S pygmy;
# Download the latest release precompiled:
yay -S pygmy-bin;
# Download and compile the latest HEAD from GitHub on the main branch:
yay -S pygmy-go-git;
yay -S pygmy-git;
```

## Usage
Expand Down Expand Up @@ -121,7 +124,7 @@ It will use `dind` and your local daemon to walk through several tests which sho

1. First clone the project:
```
git clone https://github.com/pygmystack/pygmy.git pygmy-go && cd pygmy-go
git clone https://github.com/pygmystack/pygmy.git pygmy && cd pygmy
```
2. Perform any updates as required.
3. Clean the environment.
Expand Down
27 changes: 18 additions & 9 deletions cmd/addkey.go
Expand Up @@ -22,8 +22,9 @@ package cmd

import (
"fmt"
"os"
. "github.com/logrusorgru/aurora"

"github.com/pygmystack/pygmy/service/color"
"github.com/pygmystack/pygmy/service/interface/docker"
"github.com/pygmystack/pygmy/service/library"
"github.com/spf13/cobra"
Expand All @@ -38,23 +39,25 @@ var addkeyCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {

Key, _ := cmd.Flags().GetString("key")
Keys := []string{}
Passphrase, _ := cmd.Flags().GetString("passphrase")
var Keys []library.Key

if Key != "" {
Keys = append(Keys, Key)
} else {
if _, err := os.Stat(os.Args[len(os.Args)-1]); err == os.ErrExist {
Keys = append(c.Keys, os.Args[len(os.Args)-1])
thisKey := library.Key{
Path: Key,
Passphrase: Passphrase,
}
Keys = append(Keys, thisKey)
} else {
if len(Keys) == 0 {
library.Setup(&c)
Keys = c.Keys
}
}

for _, k := range Keys {
if e := library.SshKeyAdd(c, k); e != nil {
fmt.Println(e)
if e := library.SshKeyAdd(c, k.Path, k.Passphrase); e != nil {
color.Print(Red(fmt.Sprintf("%v\n", e)))
}
}

Expand All @@ -74,6 +77,12 @@ var addkeyCmd = &cobra.Command{
func init() {

rootCmd.AddCommand(addkeyCmd)
addkeyCmd.Flags().StringP("key", "", "", "Path of SSH key to add")
addkeyCmd.Flags().StringP("key", "k", "", "Path of SSH key to add")
addkeyCmd.Flags().StringP("passphrase", "p", "", "Passphrase of the SSH key to add")

err := addkeyCmd.Flags().MarkHidden("passphrase")
if err != nil {
fmt.Println(err)
}

}

0 comments on commit e273e01

Please sign in to comment.