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 <[email protected]>
  • Loading branch information
utkuozdemir committed Jul 28, 2024
1 parent 2a1d83d commit 335731d
Show file tree
Hide file tree
Showing 33 changed files with 2,565 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .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-07-17T08:19:30Z by kres ac94478.

codecov:
require_ci_to_pass: false
Expand All @@ -9,7 +9,7 @@ coverage:
status:
project:
default:
target: 50%
target: 0%
threshold: 0.5%
base: auto
if_ci_failed: success
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
15 changes: 15 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.8.0-alpha.1
pushLatest: false
droneExtraEnvironment:
PLATFORM: linux/amd64,linux/arm64
Expand All @@ -16,8 +17,22 @@ 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:
artifacts:
- omni-cloud-provider-qemu-*
---
kind: service.CodeCov
spec:
targetThreshold: 0
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
101 changes: 78 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
# syntax = docker/dockerfile-upstream:1.8.1-labs
# syntax = docker/dockerfile-upstream:1.9.0-labs

# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-07-13T08:21:34Z by kres 8c8b007.
# Generated on 2024-07-16T09:58:51Z by kres ac94478.

ARG TOOLCHAIN

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

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

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

# runs markdownlint
FROM docker.io/oven/bun:1.1.17-alpine AS lint-markdown
FROM docker.io/oven/bun:1.1.20-alpine AS lint-markdown
WORKDIR /src
RUN bun i [email protected] [email protected]
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
7 changes: 5 additions & 2 deletions 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-15T10:06:51Z by kres ac94478.

# common variables

Expand All @@ -21,7 +21,7 @@ PROTOBUF_GO_VERSION ?= 1.34.2
GRPC_GO_VERSION ?= 1.4.0
GRPC_GATEWAY_VERSION ?= 2.20.0
VTPROTOBUF_VERSION ?= 0.6.0
GOIMPORTS_VERSION ?= 0.22.0
GOIMPORTS_VERSION ?= 0.23.0
DEEPCOPY_VERSION ?= v0.5.6
GOLANGCILINT_VERSION ?= v1.59.1
GOFUMPT_VERSION ?= v0.6.0
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ It also serves as a reference implementation for other cloud providers.
## Prerequisites

To be able to run and test the provider locally, you need to meet the following requirements:

- Running on a Linux machine
- [Omni](https://github.com/siderolabs/omni) running
- Qemu installed (`qemu-user-static`)
Expand All @@ -18,22 +19,26 @@ To be able to run and test the provider locally, you need to meet the following
## Usage

Create a cloud provider service account named `qemu` on Omni:

```shell
omnictl serviceaccount create --use-user-role=false --role=CloudProvider cloud-provider:qemu
```

Export the printed environment variables:

```shell
export OMNI_ENDPOINT=...
export OMNI_SERVICE_ACCOUNT_KEY=...
```

Build the project:

```shell
make omni-cloud-provider-qemu-linux-amd64
```

Run the cloud provider:

```shell
./_out/omni-cloud-provider-qemu-linux-amd64
```
Expand Down
Loading

0 comments on commit 335731d

Please sign in to comment.