Skip to content

Commit

Permalink
Merge pull request #1 from Vicky-Goldin/create_docker_image
Browse files Browse the repository at this point in the history
Extract taxonomy and create a docker image
  • Loading branch information
roytman authored Jan 23, 2023
2 parents c481750 + 94d2318 commit b018266
Show file tree
Hide file tree
Showing 29 changed files with 2,237 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/dco.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This enables DCO bot for you, please take a look https://github.com/probot/dco
# for more details.
require:
members: false
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
43 changes: 43 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Push

on:
push:
branches:
- 'main'
tags:
- '*'

env:
DOCKER_HOSTNAME: ghcr.io
DOCKER_USERNAME: ${{ github.actor }}

jobs:
build:
name: Build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
# Versions are created as follows (In helm 3.7 and above OCI reference tags
# must be valid SemVer):
# - Tags starting with v will be released as what comes after `v`. (e.g. refs/tags/v1.0 -> 1.0).
# - Main branch will be released with `main` as version tag for the docker images
- id: version
name: Infer version
run: |
if [[ ${GITHUB_REF} == refs/tags/* ]] ;
then
version="${GITHUB_REF#refs/tags/v}"
elif [[ ${GITHUB_REF} == refs/heads/main ]] ;
then
version=main
fi
echo ::set-output name=version::$version
echo "DOCKER_TAG=${version}" >> $GITHUB_ENV
- name: Build docker image
run: make build-docker
- name: Docker push
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login -u "${{ env.DOCKER_USERNAME }}" --password-stdin "${{ env.DOCKER_HOSTNAME }}"
make push-docker
- run: docker images
138 changes: 138 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
linters-settings:
dupl:
threshold: 100
funlen:
lines: 100
statements: 50
gci:
local-prefixes: fybrik.io/fybrik
goconst:
min-len: 6
min-occurrences: 2
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
- unnamedResult
gocyclo:
min-complexity: 15
goimports:
local-prefixes: fybrik.io/fybrik
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: argument,case,condition,return
ignored-numbers: 0,1,2,3
ignored-functions: strings.SplitN

govet:
check-shadowing: true
lll:
line-length: 140
misspell:
locale: US
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
gosec:
# Exclude generated files
exclude-generated: true
revive:
# see https://github.com/mgechev/revive#available-rules for details.
ignore-generated-header: true
severity: warning
rules:
- name: indent-error-flow
severity: warning
- name: add-constant
severity: warning
arguments:
- maxLitCount: "1"
allowStrs: '"",".","-","/","\n","\n\n","\t","error","true","false"'
allowInts: "0,1,2,404"
allowFloats: "0.0,0.,1.0,1.,2.0,2."

linters:
disable-all: true
enable:
- bodyclose
- deadcode
- dogsled
- dupl
- errcheck
- exportloopref
- funlen
# - gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- nakedret
- noctx
- nolintlint
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
- revive

# don't enable:
# - asciicheck
# - depguard
# - scopelint
# - gochecknoglobals
# - gocognit
# - godot
# - godox
# - misspell
# - goerr113
# - interfacer
# - maligned
# - nestif
# - prealloc
# - testpackage
# - wsl
issues:
exclude-rules:
- path: _test\.go
linters:
- dupl
- revive
- goconst
- funlen
- path: _test\.go
linters:
- staticcheck
text: "SA1019"
- linters:
- lll
source: "^// .kubebuilder:"


run:
timeout: 5m
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
repos:
- repo: https://github.com/golangci/golangci-lint
rev: v1.43.0
hooks:
- id: golangci-lint
name: golangci-lint
description: Fast linters runner for Go.
entry: golangci-lint run --new-from-rev=origin/main --fast
types: [ go ]
language: golang
pass_filenames: false
verbose: true
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2022 IBM Corp.
# SPDX-License-Identifier: Apache-2.0
FROM docker.io/golang:1.19.4-alpine3.17
COPY . /src/
WORKDIR /src
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -o ../taxonomy-cli main.go
WORKDIR /
RUN rm -r /src
ENTRYPOINT ["/taxonomy-cli"]
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
include Makefile.env

EXEC_NAME = taxonomy-cli

.PHONY: build-local
build-local:
CGO_ENABLED=0 GO111MODULE=on go build -o ${EXEC_NAME} main.go

.PHONY: clean-local
clean-local:
rm -f ${EXEC_NAME}

DOCKER_HOSTNAME ?= ghcr.io
DOCKER_NAMESPACE ?= fybrik
DOCKER_NAME ?= taxonomy-cli
DOCKER_TAG ?= main
DOCKER_IMG := ${DOCKER_HOSTNAME}/${DOCKER_NAMESPACE}/${DOCKER_NAME}:${DOCKER_TAG}

.PHONY: build-docker
build-docker:
docker build . -t $(DOCKER_IMG)

.PHONY: push-docker
push-docker:
docker push $(DOCKER_IMG)
7 changes: 7 additions & 0 deletions Makefile.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

GOPATH=$(shell go env GOPATH)
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# taxonomy-cli

A taxonomy defines the terms and related values that need to be commonly understood and supported across the components in the system.

`taxonomy-cli` can compile taxonomy files into a json schema, and validate an existant json schema.

For more information, please visit [the Fybrik website](https://fybrik.io/v1.2/concepts/taxonomy/).


## Usage

Simply run the `taxonomy-cli` command on the provided docker image.

For example, running `help` command:

```bash
docker run --rm -u "$(id -u):$(id -g)" ghcr.io/fybrik/taxonomy-cli:main help
```

Or compiling a `./base.json` file with a `./layer.yaml` into a `./taxonomy.json` output:

```bash
docker run --rm -u "$(id -u):$(id -g)" --volume ${PWD}:/local --workdir /local/ \
ghcr.io/fybrik/taxonomy-cli:main compile \
-o ./taxonomy.json \
-b ./base.json \
./layer.yaml
```
10 changes: 10 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Release Process

The process of creating a release is described in this document. Replace `X.Y.Z` with the version to be released.

## 1. Create a [new release](https://github.com/fybrik/taxonomy-cli/releases/new)

- Use `vX.Y.Z` tag and set `main` as the target.
- Update `Version compatibility matrix` section in README.md if needed.

Ensure that the release notes explicitly mention upgrade instructions and any breaking change.
56 changes: 56 additions & 0 deletions cmd/compile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2020 IBM Corp.
// SPDX-License-Identifier: Apache-2.0
package cmd

import (
"github.com/spf13/cobra"

"taxonomy-cli/pkg/compile"
"taxonomy-cli/pkg/taxonomyio"
)

const (
baseLiteral = "base"
outLiteral = "out"
yamlExtension = "yaml"
ymlExtension = "yml"
jsonExtension = "json"
)

var (
taxonomyCompileBasePath string
taxonomyCompileOutPath string
taxonomyCompileCodegen bool
)

// compileCmd represents the compile command
var compileCmd = &cobra.Command{
Use: "compile --out <outputFile> --base <baseFile> [<layerFile> ...] [--codegen]",
Short: "Generate a taxonomy.json file from base taxonomy and taxonomy layers",
Args: cobra.ArbitraryArgs,
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{yamlExtension, ymlExtension, jsonExtension}, cobra.ShellCompDirectiveDefault
},
RunE: func(cmd *cobra.Command, args []string) error {
result, err := compile.Files(taxonomyCompileBasePath, args, compile.WithCodeGenerationTarget(taxonomyCompileCodegen))
if err != nil {
return err
}
return taxonomyio.WriteDocumentToFile(result, taxonomyCompileOutPath)
},
DisableFlagsInUseLine: true,
}

func init() {
rootCmd.AddCommand(compileCmd)

compileCmd.Flags().StringVarP(&taxonomyCompileBasePath, baseLiteral, "b", "", "File with base taxonomy definitions (required)")
_ = compileCmd.MarkFlagFilename(baseLiteral, yamlExtension, ymlExtension, jsonExtension)
_ = compileCmd.MarkFlagRequired(baseLiteral)

compileCmd.Flags().StringVarP(&taxonomyCompileOutPath, outLiteral, "o", "taxonomy.json", "Path for output file")
_ = compileCmd.MarkFlagFilename(outLiteral, yamlExtension, ymlExtension, jsonExtension)

compileCmd.Flags().BoolVar(&taxonomyCompileCodegen, "codegen", false,
"Best effort to make output suitable for code generation tools")
}
Loading

0 comments on commit b018266

Please sign in to comment.