Zuul: Switch from travis to zuul
This PS adds the skeleton for a set of zuul checks and gates for airshipctl and removes the travis config. This PS also removes some dead code from the util package. This change is required to get unit tests passing. Change-Id: Ifb1be49cb1bb82c62a0085b6da9b8ff1b261a95b
This commit is contained in:
parent
dfe8fd0bf1
commit
d6b06a8787
15
.travis.yml
15
.travis.yml
@ -1,15 +0,0 @@
|
||||
language: go
|
||||
|
||||
go:
|
||||
- "1.12"
|
||||
|
||||
env:
|
||||
- GO111MODULE=on
|
||||
|
||||
script: make test
|
||||
|
||||
git:
|
||||
depth: 1
|
||||
|
||||
notifications:
|
||||
email: false
|
21
Dockerfile
21
Dockerfile
@ -1,5 +1,20 @@
|
||||
FROM alpine
|
||||
ARG GO_IMAGE=docker.io/golang:1.12.6-stretch
|
||||
ARG RELEASE_IMAGE=scratch
|
||||
FROM ${GO_IMAGE} as builder
|
||||
|
||||
COPY /bin/airshipctl /bin/airshipctl
|
||||
SHELL [ "/bin/bash", "-cex" ]
|
||||
ADD . /usr/src/airshipctl
|
||||
WORKDIR /usr/src/airshipctl
|
||||
ENV GO111MODULE=on
|
||||
|
||||
CMD airshipctl help
|
||||
RUN make get-modules
|
||||
|
||||
ARG MAKE_TARGET=build
|
||||
RUN make ${MAKE_TARGET} && \
|
||||
if [[ "${MAKE_TARGET}" == 'lint' ]]; then \
|
||||
mkdir -p /usr/src/airshipctl/bin; \
|
||||
touch /usr/src/airshipctl/bin/airshipctl; \
|
||||
fi
|
||||
|
||||
FROM ${RELEASE_IMAGE} as release
|
||||
COPY --from=builder /usr/src/airshipctl/bin/airshipctl /usr/local/bin/airshipctl
|
||||
|
31
Makefile
31
Makefile
@ -1,6 +1,6 @@
|
||||
SHELL := /bin/bash
|
||||
|
||||
GO_FLAGS := -ldflags '-extldflags "-static"'
|
||||
GO_FLAGS := -ldflags '-extldflags "-static"' -tags=netgo
|
||||
|
||||
BINDIR := bin
|
||||
EXECUTABLE_CLI := airshipctl
|
||||
@ -11,13 +11,20 @@ SCRIPTS_DIR := scripts
|
||||
LINTER_CMD := "github.com/golangci/golangci-lint/cmd/golangci-lint" run
|
||||
ADDTL_LINTERS := goconst,gofmt,unparam
|
||||
|
||||
# docker
|
||||
DOCKER_MAKE_TARGET := build
|
||||
|
||||
# go options
|
||||
PKG := ./...
|
||||
TESTS := .
|
||||
|
||||
.PHONY: get-modules
|
||||
get-modules:
|
||||
@go mod download
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
@CGO_ENABLED=0 go build -o $(BINDIR)/$(EXECUTABLE_CLI) $(GO_FLAGS)
|
||||
build: get-modules
|
||||
@GO111MODULE=on CGO_ENABLED=0 go build -o $(BINDIR)/$(EXECUTABLE_CLI) $(GO_FLAGS)
|
||||
|
||||
.PHONY: test
|
||||
test: build
|
||||
@ -28,15 +35,27 @@ test: unit-tests
|
||||
.PHONY: unit-tests
|
||||
unit-tests: build
|
||||
@echo "Performing unit test step..."
|
||||
@go test -run $(TESTS) $(PKG) $(TESTFLAGS)
|
||||
@GO111MODULE=on go test -run $(TESTS) $(PKG) $(TESTFLAGS)
|
||||
@echo "All unit tests passed"
|
||||
|
||||
.PHONY: lint
|
||||
lint:
|
||||
@echo "Performing linting step..."
|
||||
@go run ${LINTER_CMD} --enable ${ADDTL_LINTERS}
|
||||
@GO111MODULE=on go run ${LINTER_CMD} --enable ${ADDTL_LINTERS}
|
||||
@echo "Linting completed successfully"
|
||||
|
||||
.PHONY: docker-image
|
||||
docker-image:
|
||||
@docker build . --build-arg MAKE_TARGET=$(DOCKER_MAKE_TARGET)
|
||||
|
||||
.PHONY: docker-image-unit-tests
|
||||
docker-image-unit-tests: DOCKER_MAKE_TARGET = unit-tests
|
||||
docker-image-unit-tests: docker-image
|
||||
|
||||
.PHONY: docker-image-lint
|
||||
docker-image-lint: DOCKER_MAKE_TARGET = lint
|
||||
docker-image-lint: docker-image
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
@rm -fr $(BINDIR)
|
||||
@ -49,4 +68,4 @@ docs:
|
||||
update-golden: TESTFLAGS += -update -v
|
||||
update-golden: PKG = github.com/ian-howell/airshipctl/cmd/...
|
||||
update-golden:
|
||||
@go test $(PKG) $(TESTFLAGS)
|
||||
@GO111MODULE=on go test $(PKG) $(TESTFLAGS)
|
||||
|
@ -1,5 +1,3 @@
|
||||
[![Build Status](https://travis-ci.com/ian-howell/airshipctl.svg?branch=master)](https://travis-ci.com/ian-howell/airshipctl)
|
||||
|
||||
# airshipctl
|
||||
|
||||
### Custom Plugins Tutorial
|
||||
|
@ -1,41 +0,0 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
// IsReadable returns nil if the file at path is readable. An error is returned otherwise.
|
||||
func IsReadable(path string) error {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return err.(*os.PathError).Err
|
||||
}
|
||||
return f.Close()
|
||||
}
|
||||
|
||||
// Clock is mostly useful for unit testing, allowing for mocking out of time
|
||||
var clock *time.Time
|
||||
|
||||
// Now returns time.Now() if the Clock is nil. If the Clock is not nil, it is
|
||||
// returned instead. This is useful for testing
|
||||
func Now() time.Time {
|
||||
if clock == nil {
|
||||
return time.Now()
|
||||
}
|
||||
return *clock
|
||||
}
|
||||
|
||||
// InitClock creates a clock for unit testing
|
||||
func InitClock() {
|
||||
mockClock := time.Date(2000, time.January, 0, 0, 0, 0, 0, time.UTC)
|
||||
clock = &mockClock
|
||||
}
|
||||
|
||||
// Clock gives access to the mocked clock
|
||||
func Clock() time.Time {
|
||||
if clock == nil {
|
||||
InitClock()
|
||||
}
|
||||
return *clock
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package util_test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/ian-howell/airshipctl/pkg/util"
|
||||
)
|
||||
|
||||
func TestIsReadable(t *testing.T) {
|
||||
file, err := ioutil.TempFile(os.TempDir(), "airshipctl")
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %s", err.Error())
|
||||
}
|
||||
defer os.Remove(file.Name())
|
||||
|
||||
if err := util.IsReadable(file.Name()); err != nil {
|
||||
t.Errorf("Unexpected error: %s", err.Error())
|
||||
}
|
||||
|
||||
expected := "permission denied"
|
||||
err = file.Chmod(0000)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %s", err.Error())
|
||||
}
|
||||
if err := util.IsReadable(file.Name()); err == nil {
|
||||
t.Errorf("Expected '%s' error", expected)
|
||||
} else if err.Error() != "permission denied" {
|
||||
t.Errorf("Expected '%s' error, got '%s'", expected, err.Error())
|
||||
}
|
||||
|
||||
expected = "no such file or directory"
|
||||
os.Remove(file.Name())
|
||||
if err := util.IsReadable(file.Name()); err == nil {
|
||||
t.Errorf("Expected '%s' error", expected)
|
||||
} else if err.Error() != expected {
|
||||
t.Errorf("Expected '%s' error, got '%s'", expected, err.Error())
|
||||
}
|
||||
}
|
14
playbooks/airship-airshipctl-common.yaml
Normal file
14
playbooks/airship-airshipctl-common.yaml
Normal file
@ -0,0 +1,14 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
- hosts: all
|
||||
roles:
|
||||
- install-docker
|
27
playbooks/airship-airshipctl-lint-test.yaml
Normal file
27
playbooks/airship-airshipctl-lint-test.yaml
Normal file
@ -0,0 +1,27 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
- hosts: primary
|
||||
tasks:
|
||||
|
||||
- name: Run Linter
|
||||
block:
|
||||
- name: "make docker-image-lint"
|
||||
make:
|
||||
chdir: "{{ zuul.project.src_dir }}"
|
||||
target: docker-image-lint
|
||||
|
||||
- name: Run Unit Tests
|
||||
block:
|
||||
- name: "make docker-image-unit-tests"
|
||||
make:
|
||||
chdir: "{{ zuul.project.src_dir }}"
|
||||
target: docker-image-unit-tests
|
@ -11,8 +11,6 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
||||
"github.com/ian-howell/airshipctl/pkg/util"
|
||||
)
|
||||
|
||||
// UpdateGolden writes out the golden files with the latest values, rather than failing the test.
|
||||
@ -35,7 +33,6 @@ type CmdTest struct {
|
||||
// output from its golden file, or generates golden files if the -update flag
|
||||
// is passed
|
||||
func RunTest(t *testing.T, test *CmdTest, cmd *cobra.Command) {
|
||||
util.InitClock()
|
||||
actual := &bytes.Buffer{}
|
||||
cmd.SetOutput(actual)
|
||||
args := strings.Fields(test.CmdLine)
|
||||
|
17
zuul.d/jobs.yaml
Normal file
17
zuul.d/jobs.yaml
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
- job:
|
||||
name: airship-airshipctl-lint-test
|
||||
pre-run: playbooks/airship-airshipctl-common.yaml
|
||||
run: playbooks/airship-airshipctl-lint-test.yaml
|
||||
nodeset: airship-airshipctl-single-node
|
17
zuul.d/nodesets.yaml
Normal file
17
zuul.d/nodesets.yaml
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
- nodeset:
|
||||
name: airship-airshipctl-single-node
|
||||
nodes:
|
||||
- name: primary
|
||||
label: ubuntu-bionic
|
19
zuul.d/projects.yaml
Normal file
19
zuul.d/projects.yaml
Normal file
@ -0,0 +1,19 @@
|
||||
---
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
- project:
|
||||
check:
|
||||
jobs:
|
||||
- airship-airshipctl-lint-test
|
||||
gate:
|
||||
jobs:
|
||||
- airship-airshipctl-lint-test
|
Loading…
x
Reference in New Issue
Block a user