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

build: upgrade circleci configuration #11889

Merged
merged 1 commit into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .changelog/11889.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
build: upgrade and speedup circleci configuration
```
20 changes: 4 additions & 16 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ version: 2.1
references:
# environment specific references - aim to avoid conflicts
go-machine-image: &go_machine_image
circleci/classic:201808-01
go-machine-recent-image: &go_machine_recent_image
ubuntu-1604:201903-01
ubuntu-2004:202111-02
go-windows-image: &go_windows_image
windows-server-2019-vs2019:stable

Expand Down Expand Up @@ -289,7 +287,7 @@ jobs:
default: ""
executor:
type: string
default: "go-machine-recent"
default: "go-machine"
goarch:
type: string
default: "amd64"
Expand Down Expand Up @@ -513,6 +511,7 @@ executors:
working_directory: /go/src/github.com/hashicorp/nomad
docker:
- image: docker.mirror.hashicorp.services/golang:1.17.5
resource_class: medium
environment:
<<: *common_envs
GOPATH: /go
Expand All @@ -521,19 +520,11 @@ executors:
working_directory: ~/go/src/github.com/hashicorp/nomad
machine:
image: *go_machine_image
resource_class: medium
environment: &machine_env
<<: *common_envs
GOPATH: /home/circleci/go
GOLANG_VERSION: 1.17.5

# uses a more recent image with unattended upgrades disabled properly
# but seems to break docker builds
go-machine-recent:
working_directory: ~/go/src/github.com/hashicorp/nomad
machine:
image: *go_machine_recent_image
environment: *machine_env

go-macos:
working_directory: ~/go/src/github.com/hashicorp/nomad
macos:
Expand Down Expand Up @@ -636,9 +627,6 @@ workflows:
- test-machine:
name: "test-docker"
test_packages: "./drivers/docker"
# docker is misbehaving in docker-machine-recent image
# and we get unexpected failures
# e.g. https://circleci.com/gh/hashicorp/nomad/3854
executor: go-machine
filters: *backend_test_branches_filter
- test-machine:
Expand Down
10 changes: 8 additions & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ GIT_DIRTY := $(if $(shell git status --porcelain),+CHANGES)

GO_LDFLAGS := "-X github.com/hashicorp/nomad/version.GitCommit=$(GIT_COMMIT)$(GIT_DIRTY)"

ifneq (MSYS_NT,$(THIS_OS))
# GOPATH supports PATH style multi-paths; assume the first entry is favorable.
# Necessary because new Circle images override GOPATH with multiple values.
# See: https://discuss.circleci.com/t/gopath-is-set-to-multiple-directories/7174
GOPATH=$(shell go env GOPATH | cut -d: -f1)
endif

GO_TAGS ?=

ifeq ($(CI),true)
Expand Down Expand Up @@ -241,7 +248,6 @@ tidy:
.PHONY: dev
dev: GOOS=$(shell go env GOOS)
dev: GOARCH=$(shell go env GOARCH)
dev: GOPATH=$(shell go env GOPATH)
dev: DEV_TARGET=pkg/$(GOOS)_$(GOARCH)/nomad
dev: hclfmt ## Build for the current development platform
@echo "==> Removing old development build..."
Expand Down Expand Up @@ -297,7 +303,7 @@ test-nomad: dev ## Run Nomad test suites

.PHONY: test-nomad-module
test-nomad-module: dev ## Run Nomad test suites on a sub-module
@echo "==> Running Nomad test suites on sub-module:"
@echo "==> Running Nomad test suites on sub-module $(GOTEST_MOD)"
@cd $(GOTEST_MOD) && $(if $(ENABLE_RACE),GORACE="strip_path_prefix=$(GOPATH)/src") $(GO_TEST_CMD) \
$(if $(ENABLE_RACE),-race) $(if $(VERBOSE),-v) \
-cover \
Expand Down
2 changes: 1 addition & 1 deletion command/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestCommand_Metrics_Cases(t *testing.T) {
[]string{"-address=http://foo"},
1,
"",
"no such host",
"dial tcp: lookup foo: Temporary failure in name resolution",
},
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/exec/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func TestExecDriver_Stats(t *testing.T) {
require.NoError(err)
select {
case stats := <-statsCh:
require.NotZero(stats.ResourceUsage.MemoryStats.RSS)
require.NotEmpty(stats.ResourceUsage.MemoryStats.Measured)
require.NotZero(stats.Timestamp)
require.WithinDuration(time.Now(), time.Unix(0, stats.Timestamp), time.Second)
case <-time.After(time.Second):
Expand Down
1 change: 1 addition & 0 deletions drivers/shared/executor/executor_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type LibcontainerExecutor struct {
}

func NewExecutorWithIsolation(logger hclog.Logger) Executor {

logger = logger.Named("isolated_executor")
if err := shelpers.Init(); err != nil {
logger.Error("unable to initialize stats", "error", err)
Expand Down
19 changes: 11 additions & 8 deletions drivers/shared/executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ func TestExecutor_WaitExitSignal(pt *testing.T) {
pt.Parallel()
for name, factory := range executorFactories {
pt.Run(name, func(t *testing.T) {
require := require.New(t)
testExecCmd := testExecutorCommand(t)
execCmd, allocDir := testExecCmd.command, testExecCmd.allocDir
execCmd.Cmd = "/bin/sleep"
Expand All @@ -266,8 +265,8 @@ func TestExecutor_WaitExitSignal(pt *testing.T) {
executor := factory.new(testlog.HCLogger(t))
defer executor.Shutdown("", 0)

ps, err := executor.Launch(execCmd)
require.NoError(err)
pState, err := executor.Launch(execCmd)
require.NoError(t, err)

go func() {
tu.WaitForResult(func() (bool, error) {
Expand All @@ -280,10 +279,14 @@ func TestExecutor_WaitExitSignal(pt *testing.T) {
return false, fmt.Errorf("stats failed to send on interval")
case ru := <-ch:
assert.NotEmpty(t, ru.Pids, "no pids recorded in stats")
assert.NotZero(t, ru.ResourceUsage.MemoryStats.RSS)

// just checking we measured something; each executor type has its own abilities,
// and e.g. cgroup v2 provides different information than cgroup v1
assert.NotEmpty(t, ru.ResourceUsage.MemoryStats.Measured)

assert.WithinDuration(t, time.Now(), time.Unix(0, ru.Timestamp), time.Second)
}
proc, err := os.FindProcess(ps.Pid)
proc, err := os.FindProcess(pState.Pid)
if err != nil {
return false, err
}
Expand All @@ -298,9 +301,9 @@ func TestExecutor_WaitExitSignal(pt *testing.T) {
})
}()

ps, err = executor.Wait(context.Background())
require.NoError(err)
require.Equal(ps.Signal, int(syscall.SIGKILL))
pState, err = executor.Wait(context.Background())
require.NoError(t, err)
require.Equal(t, pState.Signal, int(syscall.SIGKILL))
})
}
}
Expand Down
37 changes: 21 additions & 16 deletions testutil/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,37 @@ import (

func TestWait_WaitForFilesUntil(t *testing.T) {

var files []string
for i := 1; i < 10; i++ {
filename := fmt.Sprintf("test%d.txt", i)
filepath := filepath.Join(os.TempDir(), filename)
Copy link
Member Author

@shoenig shoenig Jan 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conflicts with some other test writing/rm-ing directly in /tmp; at the very least we can make this test use a custom dir

files = append(files, filepath)
N := 10

tmpDir, err := os.MkdirTemp("", "waiter")
require.NoError(t, err)

defer func() {
require.NoError(t, os.RemoveAll(tmpDir))
}()

defer os.Remove(filepath)
var files []string
for i := 1; i < N; i++ {
files = append(files, filepath.Join(
tmpDir, fmt.Sprintf("test%d.txt", i),
))
}

go func() {
for _, filepath := range files {
t.Logf("Creating file %s...", filepath)
fh, err := os.Create(filepath)
fh.Close()
for _, file := range files {
t.Logf("Creating file %s ...", file)
fh, createErr := os.Create(file)
require.NoError(t, createErr)

require.NoError(t, err, "error creating test file")
require.FileExists(t, filepath)
closeErr := fh.Close()
require.NoError(t, closeErr)
require.FileExists(t, file)

time.Sleep(250 * time.Millisecond)
}
}()

duration := 5 * time.Second
t.Log("Waiting 5 seconds for files...")
t.Log("Waiting 5 seconds for files ...")
WaitForFilesUntil(t, files, duration)

t.Log("done")

}