Skip to content

Commit

Permalink
CI Fix: use docker for linux and local for mac and windows (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
MeNsaaH authored Mar 20, 2022
1 parent bacd714 commit 8caa04f
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 38 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/test-macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
name: Test-MacOs
jobs:
test:
runs-on: macos-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Checkout code
uses: actions/checkout@v2
- name: Setup config script
# using locals for mac-OS because github CI mac platforms don't have docker
run: make prep-ci-local
- name: Test
run: go test -v ./...
21 changes: 21 additions & 0 deletions .github/workflows/test-ssh.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
name: Test-Linux
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Checkout code
uses: actions/checkout@v2
- name: Setup SSH server and config
# run docker ssh container for ssh tests
run: make prep-ci-ssh
- name: Test
run: go test -v ./...
25 changes: 25 additions & 0 deletions .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
name: Test-Windows
jobs:
test:
runs-on: windows-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Checkout code
uses: actions/checkout@v2
- name: Choco Install make
uses: crazy-max/ghaction-chocolatey@v1
with:
args: install make
- name: Setup config script
# using locals for Windows because github CI Windows platforms don't have docker
run: make prep-ci-local-windows
- name: Test
run: go test -v ./...
37 changes: 0 additions & 37 deletions .github/workflows/test.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ vendor/
*.swp

docker-compose.yaml
ssh-key/ci/
config-ci.yaml
config-test.yaml
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Example:
# make
# make prep-ci-ssh
.PHONY: prep-ci-ssh
# Creates the ssh keys and docker container for running test
prep-ci-ssh:
./scripts/prep-test-ssh.sh
cat config-test.yaml

.PHONY: prep-ci-locals
prep-ci-local:
cp ./scripts/config.local.yaml config-test.yaml
cat config-test.yaml

.PHONY: prep-ci-local-windows
# Because we are using make, we can use linux cp and cat commands
prep-ci-local-windows:
cp ".\scripts\config.local.yaml" ".\config-test.yaml"
cat config-test.yaml

2 changes: 1 addition & 1 deletion config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ hosts:
type: ssh
username: root
password: somethingSecret
port: 33
port: 2222
"192.0.1.4":
connection:
type: local
Expand Down
2 changes: 2 additions & 0 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"
"testing"

"github.com/bisohns/saido/config"
"github.com/bisohns/saido/driver"
"github.com/bisohns/saido/inspector"
)
Expand All @@ -17,6 +18,7 @@ func NewWebForTest() driver.Driver {
}

func NewSSHForTest() driver.Driver {
_ = config.GetConfig()
return &driver.SSH{
User: "dev",
Host: "127.0.0.1",
Expand Down
11 changes: 11 additions & 0 deletions scripts/config.local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Config file for local connection
hosts:
children:
"127.0.0.1":
connection:
type: local

metrics:
- memory
- cpu

27 changes: 27 additions & 0 deletions scripts/prep-test-ssh.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
set -e
# Creates a docker container with ssh and a config file for connecting to it
SSH_KEY_NAME=${SSH_KEY_NAME:-ci-test-key}
SSH_KEY_PATH=$(pwd)/ssh-key/ci
SSH_USER=ci-dev
rm -rf $SSH_KEY_PATH
mkdir -p $SSH_KEY_PATH
ssh-keygen -f "$SSH_KEY_PATH/${SSH_KEY_NAME}" -N ""
docker kill saido-linux-sshserver | true
docker run -d -p 2222:2222 -e USER_NAME=$SSH_USER --name saido-linux-sshserver -v ${SSH_KEY_PATH}/${SSH_KEY_NAME}.pub:/config/.ssh/authorized_keys linuxserver/openssh-server
cat <<EOF > config-test.yaml
hosts:
children:
"$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" saido-linux-sshserver)":
connection:
type: ssh
port: 2222
username: ${SSH_USER}
private_key_path: $(pwd)/${SSH_KEY_NAME}
"127.0.0.1":
connection:
type: local
metrics:
- memory
- cpu
EOF

0 comments on commit 8caa04f

Please sign in to comment.