diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 8ceb2fac4..0b77162b6 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -12,6 +12,9 @@ jobs: - uses: actions/setup-go@v3 with: go-version: '1.17.8' + - name: check-gofmt + run: make checkfmt + shell: bash - name: Lint run: make vet shell: bash diff --git a/.tiltignore b/.tiltignore new file mode 100644 index 000000000..0efa72977 --- /dev/null +++ b/.tiltignore @@ -0,0 +1,8 @@ +capm.yaml +LICENSE +Makefile +README.md +osc-secret.yaml +CONTRIBUTING.md +example/*.yaml +docs/*.md diff --git a/Dockerfile b/Dockerfile index dd2253f5a..d71dd0cfb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,9 @@ COPY go.mod go.mod COPY go.sum go.sum # cache deps before building and copying source so that we don't need to re-download as much # and so that source changes don't invalidate our downloaded layer -RUN go mod download +RUN --mount=type=cache,target=/root/.local/share/golang \ + --mount=type=cache,target=/go/pkg/mod \ + go mod download # Copy the go source COPY main.go main.go @@ -16,7 +18,13 @@ COPY controllers/ controllers/ COPY cloud/ cloud/ COPY util/ util/ # Build -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go +ARG LDFLAGS +ARG ARCH=amd64 + +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.local/share/golang \ + CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -ldflags "${LDFLAGS} -extldflags '-static'" -o manager . # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details diff --git a/Makefile b/Makefile index e9736f364..bcd97f016 100644 --- a/Makefile +++ b/Makefile @@ -59,6 +59,14 @@ fmt: ## Run go fmt against code. vet: ## Run go vet against code. go vet ./... +.PHONY: gofmt +gofmt: ## Run gofmt + find . -name "*.go" | grep -v "\/vendor\/" | xargs gofmt -s -w + +.PHONY: checkfmt +checkfmt: ## check gofmt + ./check-gofmt + .PHONY: unit-test unit-test: go test -v -coverprofile=covers.out ./... diff --git a/Tiltfile b/Tiltfile index 3fbb9253a..202d59bdf 100644 --- a/Tiltfile +++ b/Tiltfile @@ -1,7 +1,10 @@ +trigger_mode(TRIGGER_MODE_MANUAL) + docker_build(os.getenv('CONTROLLER_IMAGE', ''), '.') allow_k8s_contexts(os.getenv('K8S_CONTEXT', 'phandalin')) + k8s_yaml('capm.yaml') diff --git a/check-gofmt b/check-gofmt new file mode 100755 index 000000000..cf3fbaf5f --- /dev/null +++ b/check-gofmt @@ -0,0 +1,13 @@ +#!/bin/bash + +set -euo pipefail +set -x +echo "Check with gofmt" + +change=$(find . -name "*.go" | grep -v "\/vendor\/" | xargs gofmt -s -d 2>&1) +if [[ -n ${change} ]]; then + echo "${change}" + echo "Please run make gofmt" + exit 1 +fi +echo "Format is good" diff --git a/cloud/scope/clients.go b/cloud/scope/clients.go index c76e462b7..bff7ac380 100644 --- a/cloud/scope/clients.go +++ b/cloud/scope/clients.go @@ -4,8 +4,8 @@ import ( "context" "os" - osc "github.com/outscale/osc-sdk-go/v2" "errors" + osc "github.com/outscale/osc-sdk-go/v2" ) // OscClient contains input client to use outscale api diff --git a/cloud/scope/cluster.go b/cloud/scope/cluster.go index ead46742b..328e7edfe 100644 --- a/cloud/scope/cluster.go +++ b/cloud/scope/cluster.go @@ -3,12 +3,12 @@ package scope import ( "context" + "errors" + "fmt" "github.com/go-logr/logr" infrastructurev1beta1 "github.com/outscale-dev/cluster-api-provider-outscale.git/api/v1beta1" "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud" osc "github.com/outscale/osc-sdk-go/v2" - "errors" - "fmt" "k8s.io/klog/v2/klogr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/util/conditions" @@ -60,7 +60,7 @@ func NewClusterScope(params ClusterScopeParams) (*ClusterScope, error) { helper, err := patch.NewHelper(params.OscCluster, params.Client) if err != nil { return nil, fmt.Errorf("%w failed to init patch helper", err) - } + } return &ClusterScope{ Logger: params.Logger, diff --git a/cloud/tag/tag.go b/cloud/tag/tag.go index 53e273586..6bd6aee42 100644 --- a/cloud/tag/tag.go +++ b/cloud/tag/tag.go @@ -2,10 +2,11 @@ package tag import ( "context" - "fmt" - osc "github.com/outscale/osc-sdk-go/v2" "errors" + "fmt" "regexp" + + osc "github.com/outscale/osc-sdk-go/v2" ) // AddTag add a tag to a resource