Skip to content

Commit

Permalink
Package restructuring (#784)
Browse files Browse the repository at this point in the history
## Description

Restructure the ocm core library according to the intended new package
structure and module name (`ocm.software/ocm`).
In a first step we keep the lib and the CLI inthe same repository as
before.

The actual first migration step has been be done based on the original
main branch just
by calling `migrate.sh --paths --module` from the repository root
folder. It can be repeated for new main versions.

Afterwards it is possible to call
- `make build`
- `make generate`
- `make test`
- `make generate-deepcopy`
- `go fmt ./{api,cmds}/...` 
- `make check` 


These commands should succeed.

This is the current state. Everything else is not yet done.
So far, packages are moved and renamed to their intended location in the
package structure.
The used relative paths should be adapted and tests and component builds
are running.

To adapt projects using this library a migration script is provided.
It can be run in in the root folder of using repositories by calling
`migrate.sh --script migrate.mig`.
Optionally, particular package folders can be given as additional
arguments.

(see also mig.md)

## What type of PR is this? (check all applicable)

- [ ] 🍕 Feature
- [x] 🎇 Restructuring
- [ ] 🐛 Bug Fix
- [ ] 📝 Documentation Update
- [ ] 🎨 Style
- [ ] 🧑‍💻 Code Refactor
- [ ] 🔥 Performance Improvements
- [ ] ✅ Test
- [ ] 🤖 Build
- [ ] 🔁 CI
- [ ] 📦 Chore (Release)
- [ ] ⏩ Revert

## Related Tickets & Documents
  • Loading branch information
mandelsoft authored Aug 5, 2024
1 parent 8472909 commit 4a1aa4f
Show file tree
Hide file tree
Showing 2,865 changed files with 88,281 additions and 90,869 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push_ocm.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: publish as latest
on:
# publish on pushes to the main branch (image tagged as "latest")
# https://github.com/open-component-model/ocm/pkgs/container/ocm
# https://ocm.software/ocm/pkgs/container/ocm
push:
branches:
- main
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

- name: Set Version
run: |
RELEASE_VERSION=v$(go run $GITHUB_WORKSPACE/pkg/version/generate print-version)
RELEASE_VERSION=v$(go run $GITHUB_WORKSPACE/api/version/generate print-version)
echo "release version is $RELEASE_VERSION"
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ jobs:
run: |
echo "Release Job Arguments"
if ${{ github.event.inputs.release_candidate }}; then
v="v$(go run $GITHUB_WORKSPACE/pkg/version/generate --no-dev print-rc-version ${{ github.event.inputs.prerelease }})"
v="v$(go run $GITHUB_WORKSPACE/api/version/generate --no-dev print-rc-version ${{ github.event.inputs.prerelease }})"
if [ -n "${{ github.event.inputs.prerelease }}" ]; then
echo "Candidate: $v"
else
echo "Candidate: $v (taken from source)"
fi
else
v="v$(go run $GITHUB_WORKSPACE/pkg/version/generate print-version)"
v="v$(go run $GITHUB_WORKSPACE/api/version/generate print-version)"
echo "Final Release: $v"
if ${{ github.event.inputs.create_branch }}; then
echo "with release branch creation"
Expand All @@ -55,13 +55,13 @@ jobs:
- name: Set Base Version
run: |
BASE_VERSION=v$(go run $GITHUB_WORKSPACE/pkg/version/generate print-version)
BASE_VERSION=v$(go run $GITHUB_WORKSPACE/api/version/generate print-version)
echo "BASE_VERSION=$BASE_VERSION" >> $GITHUB_ENV
- name: Set Pre-Release Version
if: inputs.release_candidate == true
run: |
RELEASE_VERSION=v$(go run $GITHUB_WORKSPACE/pkg/version/generate --no-dev print-rc-version ${{ github.event.inputs.prerelease }})
RELEASE_VERSION=v$(go run $GITHUB_WORKSPACE/api/version/generate --no-dev print-rc-version ${{ github.event.inputs.prerelease }})
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
- name: Set Version
Expand Down Expand Up @@ -164,13 +164,13 @@ jobs:
- name: Set Base Version
run: |
BASE_VERSION=v$(go run $GITHUB_WORKSPACE/pkg/version/generate print-version)
BASE_VERSION=v$(go run $GITHUB_WORKSPACE/api/version/generate print-version)
echo "BASE_VERSION=$BASE_VERSION" >> $GITHUB_ENV
- name: Set Pre-Release Version
if: inputs.release_candidate == true
run: |
RELEASE_VERSION=v$(go run $GITHUB_WORKSPACE/pkg/version/generate --no-dev print-rc-version ${{ github.event.inputs.prerelease }})
RELEASE_VERSION=v$(go run $GITHUB_WORKSPACE/api/version/generate --no-dev print-rc-version ${{ github.event.inputs.prerelease }})
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
echo "release name is $RELEASE_VERSION"
Expand Down Expand Up @@ -247,7 +247,7 @@ jobs:
run: |
n="releases/${{env.RELEASE_VERSION}}"
git checkout -b "$n"
v="$(go run ./pkg/version/generate bump-patch)"
v="$(go run ./api/version/generate bump-patch)"
echo "$v" > VERSION
git add VERSION
git commit -m "Prepare Development of v$v"
Expand All @@ -258,7 +258,7 @@ jobs:
run: |
set -e
git checkout ${GITHUB_REF#refs/heads/}
v="$(go run ./pkg/version/generate bump-version)"
v="$(go run ./api/version/generate bump-version)"
echo "$v" > VERSION
git add VERSION
git commit -m "Update version file to $v"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/releasenotes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Set Version
run: |
RELEASE_VERSION=v$(go run $GITHUB_WORKSPACE/pkg/version/generate print-version)
RELEASE_VERSION=v$(go run $GITHUB_WORKSPACE/api/version/generate print-version)
echo "release version is $RELEASE_VERSION"
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
Expand All @@ -48,7 +48,7 @@ jobs:
run: |
set -e
echo "Release Notes:\n $RELEASE_NOTES'"
v="v$(go run $GITHUB_WORKSPACE/pkg/version/generate print-version)"
v="v$(go run $GITHUB_WORKSPACE/api/version/generate print-version)"
f="docs/releasenotes/$v.md"
echo "$RELEASE_NOTES" > "$f"
git add "$f"
Expand Down
4 changes: 2 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ linters-settings:
- blank
- dot
- default
- prefix(github.com/open-component-model/ocm)
- prefix(ocm.software/ocm)
custom-order: true
funlen:
lines: 110
Expand Down Expand Up @@ -129,7 +129,7 @@ issues:
exclude-dirs:
- "hack"
# External code from containerd/containerd
- "pkg/docker"
- "api/tech/docker"
exclude:
- composites
exclude-rules:
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ builds:
binary: ocm
main: ./cmds/ocm/main.go
ldflags:
- -s -w -X github.com/open-component-model/ocm/pkg/version.gitVersion={{.Version}} -X github.com/open-component-model/ocm/pkg/version.gitCommit={{.Commit}} -X github.com/open-component-model/ocm/pkg/version.buildDate={{.CommitDate}}
- -s -w -X ocm.software/ocm/api/version.gitVersion={{.Version}} -X ocm.software/ocm/api/version.gitCommit={{.Commit}} -X ocm.software/ocm/api/version.buildDate={{.CommitDate}}
env:
- CGO_ENABLED=0
id: linux
Expand Down
4 changes: 2 additions & 2 deletions .reuse/dep5
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: ocm
Upstream-Contact: [email protected]
Source: https://github.com/open-component-model/ocm
Source: https://ocm.software/ocm
Disclaimer: The code in this project may include calls to APIs ("API Calls") of
SAP or third-party products or services developed outside of this project
("External Products").
Expand All @@ -28,6 +28,6 @@ Files: **
Copyright: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors
License: Apache-2.0

Files: pkg/contexts/ocm/blobhandler/handlers/generic/npm/publish.go
Files: api/ocm/extensions/blobhandler/handlers/generic/npm/publish.go
Copyright: Copyright 2021 - cloverstd
License: MIT
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ RUN --mount=type=cache,target=/root/.cache/go-build go mod download

COPY . .
RUN --mount=type=cache,target=/root/.cache/go-build \
export VERSION=$(go run pkg/version/generate/release_generate.go print-rc-version) && \
export VERSION=$(go run api/version/generate/release_generate.go print-rc-version) && \
export NOW=$(date -u +%FT%T%z) && \
go build -trimpath -ldflags \
"-s -w -X github.com/open-component-model/ocm/pkg/version.gitVersion=$VERSION -X github.com/open-component-model/ocm/pkg/version.buildDate=$NOW" \
"-s -w -X ocm.software/ocm/api/version.gitVersion=$VERSION -X ocm.software/ocm/api/version.buildDate=$NOW" \
-o /bin/ocm ./cmds/ocm/main.go

FROM alpine:${ALPINE_VERSION}
Expand Down
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ NAME := ocm
REPO_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
GITHUBORG ?= open-component-model
OCMREPO ?= ghcr.io/$(GITHUBORG)/ocm
VERSION := $(shell go run pkg/version/generate/release_generate.go print-rc-version $(CANDIDATE))
VERSION := $(shell go run api/version/generate/release_generate.go print-rc-version $(CANDIDATE))
EFFECTIVE_VERSION := $(VERSION)+$(shell git rev-parse HEAD)
GIT_TREE_STATE := $(shell [ -z "$$(git status --porcelain 2>/dev/null)" ] && echo clean || echo dirty)
COMMIT := $(shell git rev-parse --verify HEAD)
Expand All @@ -23,17 +23,17 @@ GOPATH := $(shell go env GOPATH)

NOW := $(shell date -u +%FT%T%z)
BUILD_FLAGS := "-s -w \
-X github.com/open-component-model/ocm/pkg/version.gitVersion=$(EFFECTIVE_VERSION) \
-X github.com/open-component-model/ocm/pkg/version.gitTreeState=$(GIT_TREE_STATE) \
-X github.com/open-component-model/ocm/pkg/version.gitCommit=$(COMMIT) \
-X github.com/open-component-model/ocm/pkg/version.buildDate=$(NOW)"
-X ocm.software/ocm/api/version.gitVersion=$(EFFECTIVE_VERSION) \
-X ocm.software/ocm/api/version.gitTreeState=$(GIT_TREE_STATE) \
-X ocm.software/ocm/api/version.gitCommit=$(COMMIT) \
-X ocm.software/ocm/api/version.buildDate=$(NOW)"

COMPONENTS ?= ocmcli helminstaller demoplugin ecrplugin helmdemo subchartsdemo

.PHONY: build
build: ${SOURCES}
mkdir -p bin
go build ./pkg/...
go build ./api/...
go build ./examples/...
CGO_ENABLED=0 go build -ldflags $(BUILD_FLAGS) -o bin/ocm ./cmds/ocm
CGO_ENABLED=0 go build -ldflags $(BUILD_FLAGS) -o bin/helminstaller ./cmds/helminstaller
Expand All @@ -55,7 +55,7 @@ install-requirements:
.PHONY: prepare
prepare: generate format generate-deepcopy build test check

EFFECTIVE_DIRECTORIES := $(REPO_ROOT)/cmds/ocm/... $(REPO_ROOT)/cmds/helminstaller/... $(REPO_ROOT)/cmds/ecrplugin/... $(REPO_ROOT)/cmds/demoplugin/... $(REPO_ROOT)/cmds/cliplugin/... $(REPO_ROOT)/examples/... $(REPO_ROOT)/cmds/subcmdplugin/... $(REPO_ROOT)/pkg/...
EFFECTIVE_DIRECTORIES := $(REPO_ROOT)/cmds/ocm/... $(REPO_ROOT)/cmds/helminstaller/... $(REPO_ROOT)/cmds/ecrplugin/... $(REPO_ROOT)/cmds/demoplugin/... $(REPO_ROOT)/cmds/cliplugin/... $(REPO_ROOT)/examples/... $(REPO_ROOT)/cmds/subcmdplugin/... $(REPO_ROOT)/api/...

.PHONY: format
format:
Expand Down Expand Up @@ -89,7 +89,7 @@ generate:

.PHONY: generate-deepcopy
generate-deepcopy: controller-gen
$(CONTROLLER_GEN) object paths=./pkg/contexts/ocm/compdesc/versions/... paths=./pkg/contexts/ocm/compdesc/meta/...
$(CONTROLLER_GEN) object paths=./api/ocm/compdesc/versions/... paths=./api/ocm/compdesc/meta/...

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# Open Component Model

[![OpenSSF Best Practices](https://bestpractices.coreinfrastructure.org/projects/7156/badge)](https://bestpractices.coreinfrastructure.org/projects/7156)
[![REUSE status](https://api.reuse.software/badge/github.com/open-component-model/ocm)](https://api.reuse.software/info/github.com/open-component-model/ocm)
[![OCM Integration Tests](https://github.com/open-component-model/ocm-integrationtest/actions/workflows/integrationtest.yaml/badge.svg?branch=main)](https://open-component-model.github.io/ocm-integrationtest/report.html)
[![Go Report Card](https://goreportcard.com/badge/github.com/open-component-model/ocm)](https://goreportcard.com/report/github.com/open-component-model/ocm)
[![REUSE status](https://api.reuse.software/badge/ocm.software/ocm)](https://api.reuse.software/info/ocm.software/ocm)
[![OCM Integration Tests](https://ocm.software/ocm-integrationtest/actions/workflows/integrationtest.yaml/badge.svg?branch=main)](https://open-component-model.github.io/ocm-integrationtest/report.html)
[![Go Report Card](https://goreportcard.com/badge/ocm.software/ocm)](https://goreportcard.com/report/ocm.software/ocm)

The Open Component Model (OCM) is an open standard to describe software bills of delivery (SBOD). OCM is a technology-agnostic and machine-readable format focused on the software artifacts that must be delivered for software products.

Check out the [the main OCM project web page](https://ocm.software) to find out what OCM offers you for implementing a secure software supply chain. It is your central entry point to all kind of OCM related [docs and guides](https://ocm.software/docs/overview/about), the [OCM specification](https://ocm.software/docs/overview/specification/) and all project [github repositories](https://github.com/open-component-model). It also offers a [Getting Started](https://ocm.software/docs/getting-started/) to quickly make your hands dirty with OCM, its toolset and concepts :smiley:

## OCM Specifications

OCM describes delivery [artifacts](https://github.com/open-component-model/ocm-spec/tree/main/doc/01-model/02-elements-toplevel.md#artifacts-resources-and-sources) that can be accessed from many types of [component repositories](https://github.com/open-component-model/ocm-spec/tree/main/doc/01-model/01-model.md#component-repositories). It defines a set of semantic, formatting, and other types of specifications that can be found in the [`ocm-spec` repository](https://github.com/open-component-model/ocm-spec). Start learning about the core concepts of OCM elements [here](https://github.com/open-component-model/ocm-spec/tree/main/doc/01-model/02-elements-toplevel.md#model-elements).
OCM describes delivery [artifacts](https://ocm.software/ocm-spec/tree/main/doc/01-model/02-elements-toplevel.md#artifacts-resources-and-sources) that can be accessed from many types of [component repositories](https://ocm.software/ocm-spec/tree/main/doc/01-model/01-model.md#component-repositories). It defines a set of semantic, formatting, and other types of specifications that can be found in the [`ocm-spec` repository](https://ocm.software/ocm-spec). Start learning about the core concepts of OCM elements [here](https://ocm.software/ocm-spec/tree/main/doc/01-model/02-elements-toplevel.md#model-elements).

## OCM Library

This project provides a Go library containing an API for interacting with the
[Open Component Model (OCM)](https://github.com/open-component-model/ocm-spec) elements and mechanisms.
[Open Component Model (OCM)](https://ocm.software/ocm-spec) elements and mechanisms.

The library currently supports the following [repository mappings](https://github.com/open-component-model/ocm-spec/tree/main/doc/03-persistence/02-mappings.md#mappings-for-ocm-persistence):
The library currently supports the following [repository mappings](https://ocm.software/ocm-spec/tree/main/doc/03-persistence/02-mappings.md#mappings-for-ocm-persistence):

- **OCI**: Use the repository prefix path of an OCI repository to implement an OCM
repository.
Expand All @@ -40,12 +40,12 @@ Additionally, OCM provides a generic solution for how to:

The [`ocm` CLI](docs/reference/ocm.md) may also be used to interact with OCM mechanisms. It makes it easy to create component versions and embed them in build processes.

The `ocm` CLI documentation can be found [here](<(https://github.com/open-component-model/ocm/blob/main/docs/reference/ocm.md)>).
The `ocm` CLI documentation can be found [here](<(https://ocm.software/ocm/blob/main/docs/reference/ocm.md)>).

The code for the CLI can be found in [package `cmds/ocm`](https://github.com/open-component-model/ocm/blob/main/cmds/ocm).
The code for the CLI can be found in [package `cmds/ocm`](https://ocm.software/ocm/blob/main/cmds/ocm).

The OCI and OCM support can be found in packages
[`pkg/contexts/oci`](pkg/contexts/oci) and [`pkg/contexts/ocm`](pkg/contexts/ocm).
[`pkg/contexts/oci`](pkg/contexts/oci) and [`api/ocm`](api/ocm).

## Installation

Expand All @@ -56,7 +56,7 @@ Install the latest release from any of
- [AUR](https://aur.archlinux.org/packages/ocm-cli)
- [Docker](https://www.docker.com/)
- [Podman](https://podman.io/)
- [GitHub Releases](https://github.com/open-component-model/ocm/releases)
- [GitHub Releases](https://ocm.software/ocm/releases)

### Bash

Expand Down Expand Up @@ -140,9 +140,9 @@ podman build -t ocm --build-arg GO_VERSION=1.22 --build-arg ALPINE_VERSION=3.19

## Examples

An example of how to use the `ocm` CLI in a Makefile can be found in [`examples/make`](https://github.com/open-component-model/ocm/blob/main/examples/make/Makefile).
An example of how to use the `ocm` CLI in a Makefile can be found in [`examples/make`](https://ocm.software/ocm/blob/main/examples/make/Makefile).

More comprehensive examples can be taken from the [`components`](https://github.com/open-component-model/ocm/tree/main/components) contained in this repository. [Here](components/helmdemo/README.md) a complete component build including a multi-arch image is done and finally packaged into a CTF archive which can be tranported into an OCI repository. See the readme files for details.
More comprehensive examples can be taken from the [`components`](https://ocm.software/ocm/tree/main/components) contained in this repository. [Here](components/helmdemo/README.md) a complete component build including a multi-arch image is done and finally packaged into a CTF archive which can be tranported into an OCI repository. See the readme files for details.

## Contributing

Expand All @@ -154,4 +154,4 @@ OCM follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/m

Copyright 2024 SAP SE or an SAP affiliate company and Open Component Model contributors.
Please see our [LICENSE](LICENSE) for copyright and license information.
Detailed information including third-party components and their licensing/copyright information is available [via the REUSE tool](https://api.reuse.software/info/github.com/open-component-model/ocm).
Detailed information including third-party components and their licensing/copyright information is available [via the REUSE tool](https://api.reuse.software/info/ocm.software/ocm).
44 changes: 44 additions & 0 deletions api/cli/builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package clictx

import (
"context"
"io"

"github.com/mandelsoft/vfs/pkg/vfs"

"ocm.software/ocm/api/cli/internal"
"ocm.software/ocm/api/datacontext"
"ocm.software/ocm/api/ocm"
)

func WithContext(ctx context.Context) internal.Builder {
return internal.Builder{}.WithContext(ctx)
}

func WithSharedAttributes(ctx datacontext.AttributesContext) internal.Builder {
return internal.Builder{}.WithSharedAttributes(ctx)
}

func WithOCM(ctx ocm.Context) internal.Builder {
return internal.Builder{}.WithOCM(ctx)
}

func WithFileSystem(fs vfs.FileSystem) internal.Builder {
return internal.Builder{}.WithFileSystem(fs)
}

func WithOutput(w io.Writer) internal.Builder {
return internal.Builder{}.WithOutput(w)
}

func WithErrorOutput(w io.Writer) internal.Builder {
return internal.Builder{}.WithErrorOutput(w)
}

func WithInput(r io.Reader) internal.Builder {
return internal.Builder{}.WithInput(r)
}

func New(mode ...datacontext.BuilderMode) internal.Context {
return internal.Builder{}.New(mode...)
}
61 changes: 61 additions & 0 deletions api/cli/config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package config_test

import (
"encoding/json"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

clictx "ocm.software/ocm/api/cli"
"ocm.software/ocm/api/cli/config"
"ocm.software/ocm/api/oci/extensions/repositories/ocireg"
ocmocireg "ocm.software/ocm/api/ocm/extensions/repositories/ocireg"
)

var DefaultContext = clictx.New()

func normalize(i interface{}) ([]byte, error) {
data, err := json.Marshal(i)
if err != nil {
return nil, err
}
var generic map[string]interface{}
err = json.Unmarshal(data, &generic)
if err != nil {
return nil, err
}
return json.Marshal(generic)
}

var _ = Describe("command config", func() {
ocispec := ocireg.NewRepositorySpec("ghcr.io")

ocidata, err := normalize(ocispec)
Expect(err).To(Succeed())

ocmspec := ocmocireg.NewRepositorySpec("gcr.io", nil)
ocmdata, err := normalize(ocmspec)
Expect(err).To(Succeed())

specdata := "{\"ociRepositories\":{\"oci\":" + string(ocidata) + "},\"ocmRepositories\":{\"ocm\":" + string(ocmdata) + "},\"type\":\"" + config.OCMCmdConfigType + "\"}"

Context("serialize", func() {
It("serializes config", func() {
cfg := config.New()
err := cfg.AddOCIRepository("oci", ocispec)
Expect(err).To(Succeed())
err = cfg.AddOCMRepository("ocm", ocmspec)
Expect(err).To(Succeed())

data, err := normalize(cfg)

Expect(err).To(Succeed())
Expect(data).To(Equal([]byte(specdata)))

cfg2 := config.New()
err = json.Unmarshal(data, cfg2)
Expect(err).To(Succeed())
Expect(cfg2).To(Equal(cfg))
})
})
})
File renamed without changes.
Loading

0 comments on commit 4a1aa4f

Please sign in to comment.