Skip to content

Commit

Permalink
Make build faster:
Browse files Browse the repository at this point in the history
* manual tilt launch
* tiltignore
* use buildkit with cache
* Add makefile check gofmt
* add github action to check gofmt
  • Loading branch information
vincentBaer authored and Vincent Baer committed May 25, 2022
1 parent 8c6030e commit 91d9f0d
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions .tiltignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
capm.yaml
LICENSE
Makefile
README.md
osc-secret.yaml
CONTRIBUTING.md
example/*.yaml
docs/*.md
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
Expand Down
3 changes: 3 additions & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
@@ -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')
13 changes: 13 additions & 0 deletions check-gofmt
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion cloud/scope/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions cloud/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions cloud/tag/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 91d9f0d

Please sign in to comment.