Skip to content

Commit

Permalink
Merge branch 'main' into examples
Browse files Browse the repository at this point in the history
* main:
  feat: add golangci-lint (#569)
  • Loading branch information
mdelapenya committed Nov 9, 2022
2 parents df051de + 5432154 commit ea9cff0
Show file tree
Hide file tree
Showing 40 changed files with 309 additions and 196 deletions.
15 changes: 0 additions & 15 deletions .github/workflows/ci.yml
Expand Up @@ -3,18 +3,6 @@ name: Main pipeline
on: [push, pull_request]

jobs:
static-analysis:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v3
- name: Run ShellCheck
run: |
shellcheck scripts/*.sh
- name: Run gofmt
run: |
./scripts/checks.sh
test:
strategy:
matrix:
Expand All @@ -38,9 +26,6 @@ jobs:
- name: modTidy
run: make tools-tidy

- name: vet
run: go vet ./...

- name: ensure compilation
env:
GOOS: linux
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/golangci-lint.yml
@@ -0,0 +1,47 @@
name: golangci-lint / static-analysis
on:
push:
tags:
- v*
branches:
- main
pull_request:

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read

jobs:
static-analysis:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.19
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@07db5389c99593f11ad7b44463c2d4233066a9b1
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.50

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0
args: --timeout=3m

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
3 changes: 3 additions & 0 deletions .golangci.yml
@@ -0,0 +1,3 @@
linters:
enable:
- gofmt
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -68,7 +68,11 @@ func TestIntegrationNginxLatestReturn(t *testing.T) {
}

// Clean up the container after the test is complete
defer nginxC.Terminate(ctx)
defer func() {
if err := nginxC.terminate(ctx); err != nil {
t.Fatalf("failed to terminate container: %w", err)
}
}()

resp, err := http.Get(nginxC.URI)
if resp.StatusCode != http.StatusOK {
Expand Down
3 changes: 3 additions & 0 deletions compose_api.go
Expand Up @@ -25,8 +25,10 @@ func (f stackUpOptionFunc) applyToStackUp(o *stackUpOptions) {
f(o)
}

//nolint:unused
type stackDownOptionFunc func(do *api.DownOptions)

//nolint:unused
func (f stackDownOptionFunc) applyToStackDown(do *api.DownOptions) {
f(do)
}
Expand All @@ -42,6 +44,7 @@ func RunServices(serviceNames ...string) StackUpOption {
// IgnoreOrphans - Ignore legacy containers for services that are not defined in the project
type IgnoreOrphans bool

//nolint:unused
func (io IgnoreOrphans) applyToStackUp(co *api.CreateOptions, _ *api.StartOptions) {
co.IgnoreOrphans = bool(io)
}
Expand Down
3 changes: 1 addition & 2 deletions compose_local.go
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -220,7 +219,7 @@ func (dc *LocalDockerCompose) validate() error {
for _, abs := range dc.absComposeFilePaths {
c := compose{}

yamlFile, err := ioutil.ReadFile(abs)
yamlFile, err := os.ReadFile(abs)
if err != nil {
return err
}
Expand Down
17 changes: 7 additions & 10 deletions container_test.go
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -95,19 +94,19 @@ func Test_GetDockerfile(t *testing.T) {
}

testTable := []TestCase{
TestCase{
{
name: "defaults to \"Dockerfile\" 1",
ExpectedDockerfileName: "Dockerfile",
ContainerRequest: ContainerRequest{},
},
TestCase{
{
name: "defaults to \"Dockerfile\" 2",
ExpectedDockerfileName: "Dockerfile",
ContainerRequest: ContainerRequest{
FromDockerfile: FromDockerfile{},
},
},
TestCase{
{
name: "will override name",
ExpectedDockerfileName: "CustomDockerfile",
ContainerRequest: ContainerRequest{
Expand Down Expand Up @@ -325,7 +324,7 @@ func Test_BuildImageWithContexts(t *testing.T) {
} else if err != nil {
t.Fatal(err)
} else {
c.Terminate(ctx)
terminateContainerOnEnd(t, ctx, c)
}
})
}
Expand All @@ -347,7 +346,7 @@ func Test_GetLogsFromFailedContainer(t *testing.T) {
if err != nil && !errors.Is(err, context.DeadlineExceeded) {
t.Fatal(err)
} else if err == nil {
c.Terminate(ctx)
terminateContainerOnEnd(t, ctx, c)
t.Fatal("was expecting error starting container")
}

Expand All @@ -356,7 +355,7 @@ func Test_GetLogsFromFailedContainer(t *testing.T) {
t.Fatal(logErr)
}

b, err := ioutil.ReadAll(logs)
b, err := io.ReadAll(logs)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -397,9 +396,7 @@ func createTestContainer(t *testing.T, ctx context.Context) int {
t.Fatalf("could not get mapped port: %v", err)
}

t.Cleanup(func() {
container.Terminate(context.Background())
})
terminateContainerOnEnd(t, ctx, container)

return port.Int()
}
Expand Down
15 changes: 5 additions & 10 deletions docker.go
Expand Up @@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/url"
"os"
"os/exec"
Expand Down Expand Up @@ -296,13 +295,9 @@ func (c *DockerContainer) Logs(ctx context.Context) (io.ReadCloser, error) {
r := bufio.NewReader(rc)

go func() {
var (
isPrefix = true
lineStarted = true
line []byte
)
var lineStarted = true
for err == nil {
line, isPrefix, err = r.ReadLine()
line, isPrefix, err := r.ReadLine()

if lineStarted && len(line) >= streamHeaderSize {
line = line[streamHeaderSize:] // trim stream header
Expand Down Expand Up @@ -542,7 +537,7 @@ func (c *DockerContainer) CopyFileToContainer(ctx context.Context, hostFilePath
return c.CopyDirToContainer(ctx, hostFilePath, containerFilePath, fileMode)
}

fileContent, err := ioutil.ReadFile(hostFilePath)
fileContent, err := os.ReadFile(hostFilePath)
if err != nil {
return err
}
Expand Down Expand Up @@ -1036,7 +1031,7 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque
if err != nil {
return nil, err
}
for p, _ := range image.ContainerConfig.ExposedPorts {
for p := range image.ContainerConfig.ExposedPorts {
exposedPorts = append(exposedPorts, string(p))
}
}
Expand Down Expand Up @@ -1225,7 +1220,7 @@ func (p *DockerProvider) attemptToPullImage(ctx context.Context, tag string, pul
defer pull.Close()

// download of docker image finishes at EOF of the pull request
_, err = ioutil.ReadAll(pull)
_, err = io.ReadAll(pull)
return err
}

Expand Down

0 comments on commit ea9cff0

Please sign in to comment.