Skip to content

Commit

Permalink
feat: add initial sources
Browse files Browse the repository at this point in the history
The initial implementation.

Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com>
  • Loading branch information
utkuozdemir committed Jul 13, 2024
1 parent 2a1d83d commit 9ea9d16
Show file tree
Hide file tree
Showing 33 changed files with 2,506 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-07-13T08:21:34Z by kres 8c8b007.
# Generated on 2024-06-21T07:15:12Z by kres 4c9f215.

codecov:
require_ci_to_pass: false
Expand Down
2 changes: 1 addition & 1 deletion .conform.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-07-13T08:21:34Z by kres 8c8b007.
# Generated on 2024-06-25T08:36:21Z by kres 4c9f215.

policies:
- type: commit
Expand Down
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-07-13T08:21:34Z by kres 8c8b007.
# Generated on 2024-07-11T21:13:16Z by kres 8c8b007.

*
!api
!cmd
!internal
!go.mod
!go.sum
!.golangci.yml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-07-13T08:21:34Z by kres 8c8b007.
# Generated on 2024-06-25T08:36:21Z by kres 4c9f215.

name: default
concurrency:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/slack-notify.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-07-13T08:21:34Z by kres 8c8b007.
# Generated on 2024-06-21T07:15:12Z by kres 4c9f215.

name: slack-notify
"on":
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-07-13T08:21:34Z by kres 8c8b007.
# Generated on 2024-06-21T07:15:12Z by kres 4c9f215.

_out
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-07-13T08:21:34Z by kres 8c8b007.
# Generated on 2024-06-21T07:15:12Z by kres 4c9f215.

# options for analysis running
run:
Expand Down
11 changes: 11 additions & 0 deletions .kres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
kind: common.Image
name: image-omni-cloud-provider-qemu
spec:
baseImage: ghcr.io/siderolabs/talosctl:v1.7.5
pushLatest: false
droneExtraEnvironment:
PLATFORM: linux/amd64,linux/arm64
Expand All @@ -16,6 +17,16 @@ spec:
GOOS: linux
GOARCH: arm64
---
kind: golang.Generate
spec:
versionPackagePath: internal/version
baseSpecPath: /api
vtProtobufEnabled: true
specs:
- source: api/specs/specs.proto
subdirectory: specs
genGateway: false
---
kind: common.Release
name: release
spec:
Expand Down
2 changes: 1 addition & 1 deletion .markdownlint.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-07-13T08:21:34Z by kres 8c8b007.
# Generated on 2024-07-11T21:13:16Z by kres 8c8b007.

{
"MD013": false,
Expand Down
97 changes: 76 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-07-13T08:21:34Z by kres 8c8b007.
# Generated on 2024-07-11T21:20:23Z by kres 8c8b007.

ARG TOOLCHAIN

# cleaned up specs and compiled versions
FROM scratch AS generate
FROM ghcr.io/siderolabs/talosctl:v1.7.5 AS base-image-omni-cloud-provider-qemu

FROM ghcr.io/siderolabs/ca-certificates:v1.7.0 AS image-ca-certificates

Expand All @@ -21,6 +20,10 @@ COPY .markdownlint.json .
COPY ./README.md ./README.md
RUN bunx markdownlint --ignore "CHANGELOG.md" --ignore "**/node_modules/**" --ignore '**/hack/chglog/**' --rules node_modules/sentences-per-line/index.js .

# collects proto specs
FROM scratch AS proto-specs
ADD api/specs/specs.proto /api/specs/

# base toolchain image
FROM --platform=${BUILDPLATFORM} ${TOOLCHAIN} AS toolchain
RUN apk --update --no-cache add bash curl build-base protoc protobuf-dev
Expand All @@ -35,6 +38,21 @@ ENV GOTOOLCHAIN=${GOTOOLCHAIN}
ARG GOEXPERIMENT
ENV GOEXPERIMENT=${GOEXPERIMENT}
ENV GOPATH=/go
ARG GOIMPORTS_VERSION
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go install golang.org/x/tools/cmd/goimports@v${GOIMPORTS_VERSION}
RUN mv /go/bin/goimports /bin
ARG PROTOBUF_GO_VERSION
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go install google.golang.org/protobuf/cmd/protoc-gen-go@v${PROTOBUF_GO_VERSION}
RUN mv /go/bin/protoc-gen-go /bin
ARG GRPC_GO_VERSION
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v${GRPC_GO_VERSION}
RUN mv /go/bin/protoc-gen-go-grpc /bin
ARG GRPC_GATEWAY_VERSION
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@v${GRPC_GATEWAY_VERSION}
RUN mv /go/bin/protoc-gen-grpc-gateway /bin
ARG VTPROTOBUF_VERSION
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go install github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto@v${VTPROTOBUF_VERSION}
RUN mv /go/bin/protoc-gen-go-vtproto /bin
ARG DEEPCOPY_VERSION
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go install github.com/siderolabs/deep-copy@${DEEPCOPY_VERSION} \
&& mv /go/bin/deep-copy /bin/deep-copy
Expand All @@ -55,9 +73,27 @@ COPY go.sum go.sum
RUN cd .
RUN --mount=type=cache,target=/go/pkg go mod download
RUN --mount=type=cache,target=/go/pkg go mod verify
COPY ./api ./api
COPY ./cmd ./cmd
COPY ./internal ./internal
RUN --mount=type=cache,target=/go/pkg go list -mod=readonly all >/dev/null

FROM tools AS embed-generate
ARG SHA
ARG TAG
WORKDIR /src
RUN mkdir -p internal/version/data && \
echo -n ${SHA} > internal/version/data/sha && \
echo -n ${TAG} > internal/version/data/tag

# runs protobuf compiler
FROM tools AS proto-compile
COPY --from=proto-specs / /
RUN protoc -I/api --go_out=paths=source_relative:/api --go-grpc_out=paths=source_relative:/api --go-vtproto_out=paths=source_relative:/api --go-vtproto_opt=features=marshal+unmarshal+size+equal+clone /api/specs/specs.proto
RUN rm /api/specs/specs.proto
RUN goimports -w -local github.com/siderolabs/omni-cloud-provider-qemu /api
RUN gofumpt -w /api

# runs gofumpt
FROM base AS lint-gofumpt
RUN FILES="$(gofumpt -l .)" && test -z "${FILES}" || (echo -e "Source code is not formatted with 'gofumpt -w .':\n${FILES}"; exit 1)
Expand All @@ -75,50 +111,69 @@ FROM base AS lint-govulncheck
WORKDIR /src
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg govulncheck ./...

# runs unit-tests with race detector
FROM base AS unit-tests-race
WORKDIR /src
ARG TESTPKGS
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg --mount=type=cache,target=/tmp CGO_ENABLED=1 go test -v -race -count 1 ${TESTPKGS}

# runs unit-tests
FROM base AS unit-tests-run
WORKDIR /src
ARG TESTPKGS
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg --mount=type=cache,target=/tmp go test -v -covermode=atomic -coverprofile=coverage.txt -coverpkg=${TESTPKGS} -count 1 ${TESTPKGS}

FROM embed-generate AS embed-abbrev-generate
WORKDIR /src
ARG ABBREV_TAG
RUN echo -n 'undefined' > internal/version/data/sha && \
echo -n ${ABBREV_TAG} > internal/version/data/tag

FROM scratch AS unit-tests
COPY --from=unit-tests-run /src/coverage.txt /coverage-unit-tests.txt

# cleaned up specs and compiled versions
FROM scratch AS generate
COPY --from=proto-compile /api/ /api/
COPY --from=embed-abbrev-generate /src/internal/version internal/version

# builds omni-cloud-provider-qemu-linux-amd64
FROM base AS omni-cloud-provider-qemu-linux-amd64-build
COPY --from=generate / /
COPY --from=embed-generate / /
WORKDIR /src/cmd/omni-cloud-provider-qemu
ARG GO_BUILDFLAGS
ARG GO_LDFLAGS
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg GOARCH=amd64 GOOS=linux go build ${GO_BUILDFLAGS} -ldflags "${GO_LDFLAGS}" -o /omni-cloud-provider-qemu-linux-amd64
ARG VERSION_PKG="internal/version"
ARG SHA
ARG TAG
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg GOARCH=amd64 GOOS=linux go build ${GO_BUILDFLAGS} -ldflags "${GO_LDFLAGS} -X ${VERSION_PKG}.Name=omni-cloud-provider-qemu -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /omni-cloud-provider-qemu-linux-amd64

# builds omni-cloud-provider-qemu-linux-arm64
FROM base AS omni-cloud-provider-qemu-linux-arm64-build
COPY --from=generate / /
COPY --from=embed-generate / /
WORKDIR /src/cmd/omni-cloud-provider-qemu
ARG GO_BUILDFLAGS
ARG GO_LDFLAGS
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg GOARCH=arm64 GOOS=linux go build ${GO_BUILDFLAGS} -ldflags "${GO_LDFLAGS}" -o /omni-cloud-provider-qemu-linux-arm64

# runs unit-tests with race detector
FROM base AS unit-tests-race
WORKDIR /src
ARG TESTPKGS
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg --mount=type=cache,target=/tmp CGO_ENABLED=1 go test -v -race -count 1 ${TESTPKGS}

# runs unit-tests
FROM base AS unit-tests-run
WORKDIR /src
ARG TESTPKGS
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg --mount=type=cache,target=/tmp go test -v -covermode=atomic -coverprofile=coverage.txt -coverpkg=${TESTPKGS} -count 1 ${TESTPKGS}
ARG VERSION_PKG="internal/version"
ARG SHA
ARG TAG
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg GOARCH=arm64 GOOS=linux go build ${GO_BUILDFLAGS} -ldflags "${GO_LDFLAGS} -X ${VERSION_PKG}.Name=omni-cloud-provider-qemu -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /omni-cloud-provider-qemu-linux-arm64

FROM scratch AS omni-cloud-provider-qemu-linux-amd64
COPY --from=omni-cloud-provider-qemu-linux-amd64-build /omni-cloud-provider-qemu-linux-amd64 /omni-cloud-provider-qemu-linux-amd64

FROM scratch AS omni-cloud-provider-qemu-linux-arm64
COPY --from=omni-cloud-provider-qemu-linux-arm64-build /omni-cloud-provider-qemu-linux-arm64 /omni-cloud-provider-qemu-linux-arm64

FROM scratch AS unit-tests
COPY --from=unit-tests-run /src/coverage.txt /coverage-unit-tests.txt

FROM omni-cloud-provider-qemu-linux-${TARGETARCH} AS omni-cloud-provider-qemu

FROM scratch AS omni-cloud-provider-qemu-all
COPY --from=omni-cloud-provider-qemu-linux-amd64 / /
COPY --from=omni-cloud-provider-qemu-linux-arm64 / /

FROM scratch AS image-omni-cloud-provider-qemu
FROM base-image-omni-cloud-provider-qemu AS image-omni-cloud-provider-qemu
ARG TARGETARCH
COPY --from=omni-cloud-provider-qemu omni-cloud-provider-qemu-linux-${TARGETARCH} /omni-cloud-provider-qemu
COPY --from=image-fhs / /
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-07-13T08:21:34Z by kres 8c8b007.
# Generated on 2024-07-11T21:13:16Z by kres 8c8b007.

# common variables

Expand Down Expand Up @@ -146,6 +146,9 @@ target-%: ## Builds the specified target defined in the Dockerfile. The build r
local-%: ## Builds the specified target defined in the Dockerfile using the local output type. The build result will be output to the specified local destination.
@$(MAKE) target-$* TARGET_ARGS="--output=type=local,dest=$(DEST) $(TARGET_ARGS)"

generate: ## Generate .proto definitions.
@$(MAKE) local-$@ DEST=./

lint-golangci-lint: ## Runs golangci-lint linter.
@$(MAKE) target-$@

Expand Down
Loading

0 comments on commit 9ea9d16

Please sign in to comment.