diff --git a/.drone.yml b/.drone.yml index 31bc2970..0209498f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -9,7 +9,7 @@ platform: steps: - name: build - image: rancher/dapper:v0.5.0 + image: rancher/dapper:v0.6.0 commands: - dapper ci environment: @@ -68,7 +68,7 @@ steps: - refs/tags/* - name: test-image - image: rancher/dapper:v0.5.0 + image: rancher/dapper:v0.6.0 commands: - docker build -t kine:test-${DRONE_COMMIT} -f Dockerfile.test . environment: @@ -81,7 +81,7 @@ steps: - pull_request - name: test-sqlite - image: rancher/dapper:v0.5.0 + image: rancher/dapper:v0.6.0 depends_on: - build - test-image @@ -98,7 +98,7 @@ steps: - pull_request - name: test-mysql - image: rancher/dapper:v0.5.0 + image: rancher/dapper:v0.6.0 depends_on: - build - test-image @@ -115,7 +115,7 @@ steps: - pull_request - name: test-postgres - image: rancher/dapper:v0.5.0 + image: rancher/dapper:v0.6.0 depends_on: - build - test-image @@ -132,7 +132,7 @@ steps: - pull_request - name: test-cockroachdb - image: rancher/dapper:v0.5.0 + image: rancher/dapper:v0.6.0 depends_on: - build - test-image @@ -149,7 +149,7 @@ steps: - pull_request - name: test-nats - image: rancher/dapper:v0.5.0 + image: rancher/dapper:v0.6.0 depends_on: - build - test-image @@ -189,7 +189,7 @@ platform: steps: - name: build - image: rancher/dapper:v0.5.0 + image: rancher/dapper:v0.6.0 commands: - dapper ci environment: @@ -263,7 +263,7 @@ platform: steps: - name: build - image: rancher/dapper:v0.5.0 + image: rancher/dapper:v0.5.0 # Fixed to v0.5.0 as newer versions of dapper don't work on arm commands: - dapper ci environment: diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..c336f949 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,50 @@ + +FROM golang:1.21-alpine3.18 AS infra +ARG ARCH=amd64 + +RUN apk -U add bash coreutils git gcc musl-dev docker-cli vim less file curl wget ca-certificates +# go imports version gopls/v0.14.1 +# https://github.com/golang/tools/releases/latest +RUN go install golang.org/x/tools/cmd/goimports@e985f842fa05caad2f3486f0711512aedffbcda8 +RUN rm -rf /go/src /go/pkg +RUN if [ "${ARCH}" == "amd64" ]; then \ + curl -sL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s; \ + fi + +ENV SRC_DIR=/go/src/github.com/k3s-io/kine +WORKDIR ${SRC_DIR}/ + +# Validate needs everything in the project, so we separate it out for better caching +FROM infra as validate +ARG SKIP_VALIDATE +ENV SKIP_VALIDATE=${SKIP_VALIDATE} +COPY . . +RUN --mount=type=cache,id=gomod,target=/go/pkg/mod \ + --mount=type=cache,id=gobuild,target=/root/.cache/go-build \ + --mount=type=cache,id=lint,target=/root/.cache/golangci-lint \ + ./scripts/validate + +FROM infra AS build +ARG CROSS +ARG TAG +ARG DRONE_TAG +ARG ARCH=amd64 +ENV ARCH=${ARCH} + +COPY ./scripts/build ./scripts/version ./scripts/ +COPY ./go.mod ./go.sum ./main.go ./ +COPY ./pkg ./pkg +COPY ./.git ./.git +COPY ./.golangci.json ./.golangci.json + +RUN --mount=type=cache,id=gomod,target=/go/pkg/mod \ + --mount=type=cache,id=gobuild,target=/root/.cache/go-build \ + ./scripts/build + +COPY ./scripts/package ./scripts/entry ./scripts/ +COPY ./package ./package +CMD ./scripts/entry package + +FROM scratch as binary +ENV SRC_DIR=/go/src/github.com/k3s-io/kine +COPY --from=build ${SRC_DIR}/bin /bin \ No newline at end of file diff --git a/Makefile b/Makefile index 01d5c948..bc851a4e 100644 --- a/Makefile +++ b/Makefile @@ -11,3 +11,25 @@ $(TARGETS): .dapper ./.dapper $@ .DEFAULT_GOAL := ci + +ARCH ?= amd64 +REPO ?= rancher +DEFAULT_BUILD_ARGS=--build-arg="REPO=$(REPO)" --build-arg="TAG=$(TAG)" --build-arg="ARCH=$(ARCH)" --build-arg="DIRTY=$(DIRTY)" +DIRTY := $(shell git status --porcelain --untracked-files=no) +ifneq ($(DIRTY),) + DIRTY="-dirty" +endif + +.PHONY: no-dapper +no-dapper: + DOCKER_BUILDKIT=1 docker build \ + $(DEFAULT_BUILD_ARGS) --build-arg="SKIP_VALIDATE=$(SKIP_VALIDATE)" \ + --target=validate -f Dockerfile . + DOCKER_BUILDKIT=1 docker build \ + $(DEFAULT_BUILD_ARGS) --build-arg="DRONE_TAG=$(DRONE_TAG)" --build-arg="CROSS=$(CROSS)" \ + -f Dockerfile --target=build -t kine-build . + DOCKER_BUILDKIT=1 docker build \ + $(DEFAULT_BUILD_ARGS) --build-arg="DRONE_TAG=$(DRONE_TAG)" --build-arg="CROSS=$(CROSS)" \ + -f Dockerfile --target=binary --output=. . + DOCKER_BUILDKIT=1 docker run -v /var/run/docker.sock:/var/run/docker.sock -v ./dist:/go/src/github.com/k3s-io/kine/dist \ + -e DAPPER_UID=1000 -e DAPPER_GID=1000 -e IMAGE_NAME -e DRONE_TAG -e DIRTY=$(DIRTY) kine-build \ No newline at end of file diff --git a/pkg/drivers/generic/generic.go b/pkg/drivers/generic/generic.go index 43b53712..481f051e 100644 --- a/pkg/drivers/generic/generic.go +++ b/pkg/drivers/generic/generic.go @@ -425,7 +425,7 @@ func (d *Generic) Insert(ctx context.Context, key string, create, delete bool, c } // Drivers without LastInsertID support may conflict on the serial id key when inserting rows, - // as the ID is reserved at the begining of the implicit transaction, but does not become + // as the ID is reserved at the beginning of the implicit transaction, but does not become // visible until the transaction completes, at which point we may have already created a gap fill record. // Retry the insert if the driver indicates a retriable insert error, to avoid presenting a spurious // duplicate key error to the client. diff --git a/pkg/drivers/nats/config.go b/pkg/drivers/nats/config.go index 5480a6b3..56a0e65c 100644 --- a/pkg/drivers/nats/config.go +++ b/pkg/drivers/nats/config.go @@ -134,7 +134,7 @@ func parseConnection(dsn string, tlsInfo tls.Config) (*Config, error) { // command line options provided to kine will override the file // https://github.com/nats-io/jsm.go/blob/v0.0.29/natscontext/context.go#L257 - // allows for user, creds, nke, token, certifcate, ca, inboxprefix from the context.json + // allows for user, creds, nke, token, certificate, ca, inboxprefix from the context.json natsClientOpts, err := natsContext.NATSOptions(config.clientOptions...) if err != nil { return nil, err diff --git a/scripts/ci b/scripts/ci index 577239c4..74dcc397 100755 --- a/scripts/ci +++ b/scripts/ci @@ -3,10 +3,6 @@ set -e cd $(dirname $0) -if [ -z "$SKIP_VALIDATE" ]; then - ./validate - ./validate-ci -fi - +./validate ./build ./package diff --git a/scripts/validate b/scripts/validate index 781e4d1d..2cef865f 100755 --- a/scripts/validate +++ b/scripts/validate @@ -1,19 +1,32 @@ #!/bin/bash set -e +if [ -n "$SKIP_VALIDATE" ]; then + echo Skipping validation + exit 0 +fi + cd $(dirname $0)/.. echo Running validation PACKAGES="$(go list ./...)" -if ! command -v golangci-lint; then - echo Skipping validation: no golangci-lint available - exit +if command -v golangci-lint; then + echo Running: golangci-lint + golangci-lint run fi -echo Running: golangci-lint -golangci-lint run - echo Running: go fmt test -z "$(go fmt ${PACKAGES} | tee /dev/stderr)" + +go generate + +source ./scripts/version + +if [ -n "$DIRTY" ]; then + echo Git is dirty + git status + git diff + exit 1 +fi diff --git a/scripts/validate-ci b/scripts/validate-ci deleted file mode 100755 index e7981cf8..00000000 --- a/scripts/validate-ci +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -set -e - -cd $(dirname $0)/.. - -go generate - -source ./scripts/version - -if [ -n "$DIRTY" ]; then - echo Git is dirty - git status - git diff - exit 1 -fi diff --git a/scripts/version b/scripts/version index 8d196f17..78a02b08 100755 --- a/scripts/version +++ b/scripts/version @@ -1,6 +1,7 @@ #!/bin/bash -if [ -n "$(git status --porcelain --untracked-files=no)" ]; then +# Without Dapper, DIRTY is determined in the Makefile and passed in as a build arg/env var +if [ -z "$DIRTY" ] && [ -n "$(git status --porcelain --untracked-files=no)" ]; then DIRTY="-dirty" fi diff --git a/updatecli/updatecli.d/updatecli.yml b/updatecli/updatecli.d/updatecli.yml index 51c388e8..2a427f50 100644 --- a/updatecli/updatecli.d/updatecli.yml +++ b/updatecli/updatecli.d/updatecli.yml @@ -2,7 +2,7 @@ # To test this: # have "UPDATECLI_GITHUB_ACTOR" env set to your github username # have "UPDATECLI_GITHUB_TOKEN" env set to your github token -# have the latest verison of updatecli installed +# have the latest version of updatecli installed # 'updatecli diff -v updatecli/values.yaml -c updatecli/updatecli.d/updatecli.yml' # In the future, more useful files should be added to this directory. ---