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

ci: github actions pipeline #628

Merged
merged 23 commits into from
Oct 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
97 changes: 97 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Pipeline

on: [ push ]

env:
CI: true

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-go@v1
with: { go-version: '1.13' }
- name: Install web dependencies
run: make web-deps
- name: Run linters
run: make lint

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-go@v1
with: { go-version: '1.13' }
- name: Build daemon
run: make daemon TAG=test
- name: Cache daemon image
uses: actions/upload-artifact@v1
with:
name: inertia-daemon-image
path: images/inertia-daemon-image

test-core:
runs-on: ubuntu-latest
needs: [ build, lint ]
steps:
- uses: actions/checkout@v1
- uses: actions/setup-go@v1
with: { go-version: '1.13' }
- name: Install Docker dependencies
run: bash test/docker_deps.sh
- name: Start test container
run: docker run --name testcontainer -d nginx
- name: Execute tests
run: go test -race -tags no_bootstrap -coverprofile=coverage.txt ./...
- name: Upload code coverage
run: bash <(curl -s https://codecov.io/bash)
env:
CODECOV_TOKEN: ${{ secrets.codecov_token }}

test-bootstrap:
runs-on: ubuntu-latest
needs: [ test-core ]
strategy:
matrix:
case: [ debian-9.3, centos-7, amazon-1, ubuntu-16.04, ubuntu-18.04 ]
include:
- case: debian-9.3
os_name: debian
os_version: 9.3
- case: centos-7
os_name: centos
os_version: 7
- case: amazon-1
os_name: amazon
os_version: 1
- case: ubuntu-16.04
os_name: ubuntu
os_version: 16.04
- case: ubuntu-18.04
os_name: ubuntu
os_version: 18.04
fail-fast: false
steps:
- uses: actions/checkout@v1
- uses: actions/setup-go@v1
with: { go-version: '1.13' }
- name: Start mock VPS (${{ matrix.case }})
run: |
make testenv \
VPS_OS=${{ matrix.os_name }} \
VPS_VERSION=${{ matrix.os_version }} \
SSH_PORT=69
- name: Pull daemon image
uses: actions/download-artifact@v1
with:
name: inertia-daemon-image
path: images/
- name: Set up daemon image
run: make testdaemon-scp
- name: Run bootstrap test
run: go test ./... -v -run 'TestBootstrap_Integration' -coverprofile=coverage.txt -ldflags "-X github.com/ubclaunchpad/inertia/cmd.Version=test"
- name: Upload code coverage
run: bash <(curl -s https://codecov.io/bash)
env:
CODECOV_TOKEN: ${{ secrets.codecov_token }}
15 changes: 15 additions & 0 deletions .github/workflows/publish-latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Pipeline

on:
push:
branches: [ master ]

jobs:
daemon:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Build and publish daemon:latest
run: |
- docker login -u ${{ secrets.docker_user }} -p ${{ secrets.docker_key }}
- make daemon-release RELEASE=latest
23 changes: 23 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Pipeline

on:
release:
types: [ published, prereleased ]

jobs:
daemon:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-go@v1
with: { go-version: '1.13' }
- name: Build release and publish daemon
run: |
docker login -u ${{ secrets.docker_user }} -p ${{ secrets.docker_key }}
bash .scripts/release.sh
- name: Publish CLI
uses: softprops/action-gh-release@v1
with:
files: inertia.v*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
109 changes: 0 additions & 109 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion client/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func Bootstrap(c *client.Client, opts Options) error {
}
sshc, err := c.GetSSHClient()
if err != nil {
return err
return fmt.Errorf("failed to initialize SSH client: %w", err)
}

fprintf(out, "Setting up remote '%s' at %s\n", c.Remote.Name, c.Remote.IP)
Expand Down
9 changes: 6 additions & 3 deletions client/bootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ubclaunchpad/inertia/cfg"
"github.com/ubclaunchpad/inertia/client"
Expand Down Expand Up @@ -41,13 +42,15 @@ func TestBootstrap_Integration(t *testing.T) {
}

var c = newIntegrationClient()
assert.NoError(t, Bootstrap(c, Options{Out: os.Stdout}))
c.WithDebug(true) // makes troubleshooting tests easier
require.NoError(t, Bootstrap(c, Options{Out: os.Stdout}), "bootstrap failed")

// Daemon setup takes a bit of time - do a crude wait
time.Sleep(3 * time.Second)
time.Sleep(5 * time.Second)

// Check if daemon is online following bootstrap
status, err := c.Status(context.Background())
assert.NoError(t, err)
require.NoError(t, err, "status check of bootstrapped daemon failed")
t.Logf("daemon status: %+v", status)
assert.Equal(t, "test", status.InertiaVersion)
}
6 changes: 3 additions & 3 deletions client/internal/compiled.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/scripts/daemon-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ sudo docker run -d \
-e HOME="$HOME" \
-e SSH_KNOWN_HOSTS='/app/host/.ssh/known_hosts' \
--name "$DAEMON_NAME" \
"$IMAGE" "$HOST_ADDRESS" > /dev/null 2>&1
"$IMAGE" "$HOST_ADDRESS" > /dev/null # 2>&1
20 changes: 10 additions & 10 deletions client/sshc.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (s *SSHClient) GetRunner() runner.SSHSession { return s.ssh }
func (s *SSHClient) DaemonUp() error {
scriptBytes, err := internal.ReadFile("client/scripts/daemon-up.sh")
if err != nil {
return err
return fmt.Errorf("could not initialize script: %w", err)
}
var daemonCmdStr = fmt.Sprintf(string(scriptBytes),
s.remote.Version, s.remote.Daemon.Port, s.remote.IP)
Expand All @@ -41,7 +41,7 @@ func (s *SSHClient) DaemonUp() error {
func (s *SSHClient) DaemonDown() error {
scriptBytes, err := internal.ReadFile("client/scripts/daemon-down.sh")
if err != nil {
return err
return fmt.Errorf("could not initialize script: %w", err)
}

stdout, stderr, err := s.ssh.Run(string(scriptBytes))
Expand All @@ -58,13 +58,13 @@ func (s *SSHClient) DaemonDown() error {
func (s *SSHClient) InstallDocker() error {
installDockerSh, err := internal.ReadFile("client/scripts/docker.sh")
if err != nil {
return err
return fmt.Errorf("could not initialize script: %w", err)
}

// Install docker.
cmdStr := string(installDockerSh)
if err = s.ssh.RunStream(cmdStr, false); err != nil {
return fmt.Errorf("docker installation: %s", err.Error())
return fmt.Errorf("docker installation failed: %w", err.Error())
}

return nil
Expand All @@ -79,15 +79,15 @@ func (s *SSHClient) GenerateKeys() (string, error) {

scriptBytes, err := internal.ReadFile("client/scripts/keygen.sh")
if err != nil {
return "", err
return "", fmt.Errorf("could not initialize script: %w", err)
}

// Create deploy key.
stdout, stderr, err := s.ssh.Run(string(scriptBytes))
s.debugStdout("keygen.sh", stdout)
s.debugStderr("keygen.sh", stderr)
if err != nil {
return "", fmt.Errorf("key generation failed: %s", err.Error())
return "", fmt.Errorf("key generation failed: %w", err.Error())
}

return stdout.String(), nil
Expand All @@ -97,14 +97,14 @@ func (s *SSHClient) GenerateKeys() (string, error) {
func (s *SSHClient) AssignAPIToken() error {
scriptBytes, err := internal.ReadFile("client/scripts/token.sh")
if err != nil {
return err
return fmt.Errorf("could not initialize script: %w", err)
}
daemonCmdStr := fmt.Sprintf(string(scriptBytes), s.remote.Version)
stdout, stderr, err := s.ssh.Run(daemonCmdStr)
s.debugStdout("token.sh", stdout)
s.debugStderr("token.sh", stderr)
if err != nil {
return fmt.Errorf("api token generation failed: %s", err.Error())
return fmt.Errorf("api token generation failed: %w", err.Error())
}

// There may be a newline, remove it.
Expand All @@ -116,14 +116,14 @@ func (s *SSHClient) AssignAPIToken() error {
func (s *SSHClient) UninstallInertia() error {
scriptBytes, err := internal.ReadFile("client/scripts/inertia-down.sh")
if err != nil {
return err
return fmt.Errorf("could not initialize script: %w", err)
}

stdout, stderr, err := s.ssh.Run(string(scriptBytes))
s.debugStdout("inertia-down.sh", stdout)
s.debugStderr("inertia-down.sh", stderr)
if err != nil {
return fmt.Errorf("inertia shutdown failed: %s", err.Error())
return fmt.Errorf("inertia shutdown failed: %w", err.Error())
}

return nil
Expand Down
Loading