13
0
Fork 0
mirror of https://github.com/yannh/kubeconform.git synced 2026-06-28 16:00:44 +00:00

Add go version of openapi2jsonschema to container

This commit is contained in:
Yann Hamon 2026-06-04 21:03:01 +02:00
parent 4f7cf0fc3e
commit 0f144bb9e6
16 changed files with 98 additions and 7138 deletions

View file

@ -16,21 +16,29 @@ jobs:
- name: acceptance-test
run: make docker-acceptance
openapi2jsonschema-test:
openapi2jsonschema-go-test:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: test
working-directory: ./scripts
run: make docker-test docker-acceptance
working-directory: ./openapi2jsonschema-go
run: make docker-test
- name: build
working-directory: ./openapi2jsonschema-go
run: make docker-build-static
- name: acceptance-test
working-directory: ./openapi2jsonschema-go
run: make docker-acceptance
goreleaser:
runs-on: ubuntu-latest
needs:
- kubeconform-test
- openapi2jsonschema-test
- openapi2jsonschema-go-test
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: checkout

View file

@ -1,6 +1,8 @@
project_name: kubeconform
builds:
- main: ./cmd/kubeconform
- id: kubeconform
binary: kubeconform
main: ./cmd/kubeconform
env:
- CGO_ENABLED=0
- GOFLAGS = -mod=vendor
@ -11,7 +13,6 @@ builds:
- linux
- darwin
goarch:
- 386
- amd64
- arm
- arm64
@ -22,9 +23,33 @@ builds:
ldflags:
- -extldflags "-static"
- -X main.version={{.Tag}}
- id: openapi2jsonschema
binary: openapi2jsonschema
dir: ./openapi2jsonschema-go
main: .
env:
- CGO_ENABLED=0
- GO111MODULE = on
- GIT_OWNER = yannh
goos:
- windows
- linux
- darwin
goarch:
- amd64
- arm
- arm64
flags:
- -trimpath
- -tags=netgo
- -a
ldflags:
- -extldflags "-static"
archives:
- format: tar.gz
builds:
- kubeconform
format_overrides:
- goos: windows
format: zip

View file

@ -11,4 +11,5 @@ LABEL org.opencontainers.image.authors="Yann Hamon <yann@mandragor.org>" \
org.opencontainers.image.url="https://github.com/yannh/kubeconform/"
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY kubeconform /
COPY openapi2jsonschema /
ENTRYPOINT ["/kubeconform"]

View file

@ -9,4 +9,5 @@ LABEL org.opencontainers.image.authors="Yann Hamon <yann@mandragor.org>" \
org.opencontainers.image.url="https://github.com/yannh/kubeconform/"
RUN apk add ca-certificates
COPY kubeconform /
COPY openapi2jsonschema /
ENTRYPOINT ["/kubeconform"]

View file

@ -12,7 +12,7 @@ local-build:
go build -o bin/ ./...
local-build-static:
CGO_ENABLED=0 GOFLAGS=-mod=vendor GOOS=linux GOARCH=amd64 GO111MODULE=on go build -trimpath -tags=netgo -ldflags "-extldflags=\"-static\"" -a -o bin/ ./...
CGO_ENABLED=0 GOFLAGS=-mod=vendor GOOS=$(shell go env GOOS) GOARCH=$(shell go env GOARCH) GO111MODULE=on go build -trimpath -tags=netgo -ldflags "-extldflags=\"-static\"" -a -o bin/ ./...
# These only used for development. Release artifacts and docker images are produced by goreleaser.
docker-test:

View file

@ -0,0 +1,15 @@
# Build context must be the repo root so that scripts/fixtures/ is reachable.
# See the Makefile in this folder.
FROM golang:1.24-alpine AS build
WORKDIR /src
COPY openapi2jsonschema-go/go.mod openapi2jsonschema-go/go.sum ./
RUN go mod download
COPY openapi2jsonschema-go/openapi2jsonschema.go openapi2jsonschema-go/openapi2jsonschema_test.go ./
RUN go build -o /openapi2jsonschema .
FROM alpine:3.20
RUN apk --no-cache add bats diffutils
COPY --from=build /openapi2jsonschema /code/openapi2jsonschema-go/openapi2jsonschema
COPY scripts/fixtures /code/fixtures
COPY openapi2jsonschema-go/acceptance.bats /code/openapi2jsonschema-go/
WORKDIR /code/openapi2jsonschema-go

View file

@ -0,0 +1,41 @@
#!/usr/bin/make -f
GO_VERSION ?= 1.24.3
.PHONY: test local-test local-build local-build-static docker-test docker-build docker-build-static build-bats docker-acceptance update-deps clean
test: local-test docker-acceptance
local-test:
go test -race ./... -count=1
local-build:
go build -o bin/openapi2jsonschema .
local-build-static:
CGO_ENABLED=0 GOOS=$(shell go env GOOS) GOARCH=$(shell go env GOARCH) GO111MODULE=on go build -trimpath -tags=netgo -ldflags "-extldflags=\"-static\"" -a -o bin/openapi2jsonschema .
# Mount the repo root so scripts/fixtures/ is reachable from the container.
docker-test:
docker run -t -v $$PWD/..:/src -w /src/openapi2jsonschema-go golang:$(GO_VERSION) make local-test
docker-build:
docker run -t -v $$PWD/..:/src -w /src/openapi2jsonschema-go golang:$(GO_VERSION) make local-build
docker-build-static:
docker run -t -v $$PWD/..:/src -w /src/openapi2jsonschema-go golang:$(GO_VERSION) make local-build-static
# Build context is the repo root so the image can pull in scripts/fixtures/.
build-bats:
docker build -t openapi2jsonschema-go-bats -f Dockerfile.bats ..
docker-acceptance: build-bats
docker run --entrypoint "/usr/bin/bats" -t openapi2jsonschema-go-bats /code/openapi2jsonschema-go/acceptance.bats
update-deps:
go get -u ./...
go mod tidy
clean:
rm -rf bin
rm -f openapi2jsonschema prometheus_v1.json prometheus-monitoring-v1.json

Binary file not shown.

View file

@ -1,15 +0,0 @@
# Build context must be the parent `scripts/` directory so that
# `fixtures/` is reachable. See the Makefile in this folder.
FROM golang:1.24-alpine AS build
WORKDIR /src
COPY go/go.mod go/go.sum ./
RUN go mod download
COPY go/openapi2jsonschema.go go/openapi2jsonschema_test.go ./
RUN go build -o /openapi2jsonschema .
FROM alpine:3.20
RUN apk --no-cache add bats diffutils
COPY --from=build /openapi2jsonschema /code/go/openapi2jsonschema
COPY fixtures /code/fixtures
COPY go/acceptance.bats /code/go/
WORKDIR /code/go

View file

@ -1,18 +0,0 @@
#!/usr/bin/make -f
test: unit-test docker-acceptance
build:
go build -o openapi2jsonschema .
unit-test:
go test ./...
build-go-bats:
docker build -t go-bats -f Dockerfile.bats ..
docker-acceptance: build-go-bats
docker run --entrypoint "/usr/bin/bats" -t go-bats /code/go/acceptance.bats
clean:
rm -f openapi2jsonschema prometheus_v1.json prometheus-monitoring-v1.json