Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .bazelrc

This file was deleted.

1 change: 0 additions & 1 deletion .bazelversion

This file was deleted.

5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.md
Makefile
/img
/out
Dockerfile
18 changes: 3 additions & 15 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: bazel-contrib/setup-bazel@0.14.0
with:
bazelisk-cache: true
repository-cache: true
- run: bazel --bazelrc=tools/ci.bazelrc build //...
- run: make build
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
- run: make check
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: bazel-contrib/setup-bazel@0.14.0
with:
bazelisk-cache: true
repository-cache: true
- run: bazel --bazelrc=tools/ci.bazelrc test //...
- run: make test
16 changes: 7 additions & 9 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ jobs:
fetch-depth: 0
- run: |
git fetch --tags --force
- uses: bazel-contrib/setup-bazel@0.14.0
with:
bazelisk-cache: true
repository-cache: true
- run: bazel --bazelrc=tools/ci.bazelrc run //manifests:stable > stable.yaml
- run: bazel --bazelrc=tools/ci.bazelrc run //manifests:cluster > cluster.yaml
- name: Release
- run: make build
- run: make manifests
- name: Push image
run: make push
- name: Release manifests
uses: softprops/action-gh-release@v1
with:
files: |
stable.yaml
cluster.yaml
out/stable.yaml
out/cluster.yaml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
cmd/sciuro/sciuro
vendor
build
/bazel*
/out
70 changes: 70 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
version: "2"
run:
modules-download-mode: readonly
linters:
enable:
- bodyclose
- contextcheck
- copyloopvar
- decorder
- dogsled
- errorlint
- gochecknoinits
- goconst
- gocritic
- godox
- goprintffuncname
- gosec
- misspell
- nakedret
- prealloc
- revive
- staticcheck
- unconvert
- unparam
settings:
gocritic:
disabled-checks:
- commentFormatting
- exitAfterDefer
- hugeParam
- ifElseChain
- rangeValCopy
- unnecessaryBlock
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
godox:
keywords:
- HACK
- XXX
misspell:
locale: US
ignore-rules:
- clas
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- goimports
settings:
gofmt:
simplify: true
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
58 changes: 0 additions & 58 deletions .golangci.yml

This file was deleted.

4 changes: 0 additions & 4 deletions BUILD

This file was deleted.

66 changes: 66 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# https://hub.docker.com/layers/library/alpine/3.18.3/images/sha256-c5c5fda71656f28e49ac9c5416b3643eaa6a108a8093151d6d1afc9463be8e33
FROM docker.io/alpine@sha256:c5c5fda71656f28e49ac9c5416b3643eaa6a108a8093151d6d1afc9463be8e33 AS alpine-base

FROM docker.io/golang:1.23.0 AS base
WORKDIR /work
COPY go.mod go.sum ./
RUN go mod download
COPY . .

FROM base AS test
RUN --mount=type=cache,target=/root/.cache/go-build \
go test ./...

FROM base AS test-coverage
RUN --mount=type=cache,target=/root/.cache/go-build \
go test -coverprofile=/coverage.txt -mod=readonly -covermode=atomic ./...

FROM scratch AS export-test-coverage
COPY --from=test-coverage /coverage.txt /

FROM docker.io/golangci/golangci-lint:v2.8.0 AS golangci-lint
FROM base AS check
COPY --from=golangci-lint /usr/bin/golangci-lint /usr/bin/
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/golangci-lint \
golangci-lint run ./...

FROM base AS dep-update
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
set -x && \
go get -u ./... && \
go mod tidy

FROM scratch AS export-dep-update
COPY --from=dep-update /work/go.mod /work/go.sum /

FROM registry.k8s.io/kustomize/kustomize:v5.8.0 AS kustomize
FROM alpine-base AS build-manifests
ARG TAG
COPY --from=kustomize /app/kustomize /usr/local/bin/
WORKDIR /work
COPY manifests ./manifests
RUN set -x && \
cd manifests/namespaced && \
kustomize edit set image docker.io/cloudflare/sciuro:${TAG} && \
kustomize build >/stable.yaml
RUN set -x && \
cd manifests/non-namespaced && \
kustomize build >/cluster.yaml

FROM scratch AS export-manifests
COPY --from=build-manifests /stable.yaml /cluster.yaml /

FROM base AS build
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
CGO_ENABLED=0 go build -o /sciuro cmd/sciuro/main.go

FROM scratch AS export
COPY --from=build /sciuro /

FROM alpine-base
COPY --from=build /sciuro /
ENTRYPOINT ["/sciuro"]
46 changes: 24 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
PROJECT = sciuro
MODULE = github.com/cloudflare/$(PROJECT)
TAG := $(shell git describe --tags --always --dirty)
IMG ?= docker.io/cloudflare/sciuro:$(TAG)

DOCKER_BUILD ?= docker build --progress=plain
OUTPUT_DIR ?= out

.PHONY: default
default: build;

.PHONY: clean
clean:
@echo cleaning build targets
@rm -rf bin coverage.txt

.PHONY: clean-bazel
clean-bazel:
@echo cleaning bazel build targets
@./tools/bazel clean
@rm -rf $(OUTPUT_DIR)

.PHONY: check
check:
@echo running checks
# TODO: Not well incorporated into bazel
@golangcilint run ./...

.PHONY: dep-fix
dep-fix:
@echo fixing dependencies
@./tools/bazel run //:gazelle -- fix
@$(DOCKER_BUILD) --target check .

.PHONY: dep-update
dep-update: go.sum
dep-update:
@echo updating dependencies
@go mod tidy
@./tools/bazel run //:gazelle -- update-repos -from_file=go.mod -prune=true -to_macro=gazelle.bzl%deps
@$(DOCKER_BUILD) --target export-dep-update --output . .

.PHONY: test
test:
@echo unit testing with Bazel
@./tools/bazel test //...
@echo unit testing
$(DOCKER_BUILD) --target test .

.PHONY: test-coverage
test-coverage:
@echo unit testing with coverage
@go test -coverprofile=coverage.txt -mod=readonly -covermode=atomic $(MODULE)/...
$(DOCKER_BUILD) --target export-test-coverage --output $(OUTPUT_DIR) .

.PHONY: build
build:
@echo building cmds and images
@./tools/bazel build //cmd/...
@$(DOCKER_BUILD) --target export --output $(OUTPUT_DIR) .
@$(DOCKER_BUILD) -t $(IMG) .

.PHONY: manifests
manifests:
@echo generating manifests
@$(DOCKER_BUILD) --build-arg TAG=$(TAG) --target export-manifests --output $(OUTPUT_DIR) .

.PHONY: push
push:
@echo pushing images
@docker push $(IMG)
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,22 @@ $ kubectl get node worker01 -o json | jq '.status.conditions[] | select(.type |
```

# Building
Sciuro is built and tested with [bazel](https://bazel.build/). To run tests:
To run tests:
```
make test
```

To build and push images, define the docker repository base with the run of the
manifests targets:
To build images:
```
bazel run --define repo=quay.io/myrepo //manifests:cluster > /tmp/cluster.yaml
bazel run --define repo=quay.io/myrepo //manifests:stable > /tmp/stable.yaml
make build
```

To push images:
```
make push
```

To generate manifests:
```
make manifests
```
Loading