Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial devops skeleton #2

Merged
merged 2 commits into from
Nov 6, 2022
Merged
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
11 changes: 11 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# CODEOWNERS reference: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners

# These owners will be the default owners for everything in
# the repo. Unless a later match takes precedence,
# the following users/teams will be requested for
# review when someone opens a pull request.
* @openclarity/vmclarity-maintainers

# Enforces admin protections for repo configuration via probot settings app.
# ref: https://github.com/probot/settings#security-implications
.github/settings.yml @openclarity/vmclarity-admins
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
17 changes: 17 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: 2
updates:
- package-ecosystem: gomod
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
- package-ecosystem: docker
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
72 changes: 72 additions & 0 deletions .github/settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
repository:
# See https://developer.github.com/v3/repos/#edit for all available settings.

# The name of the repository. Changing this will rename the repository
name: vmclarity

# A short description of the repository that will show up on GitHub
description: VMClarity is a tool for agentless detection and management of Virtual Machine Software Bill Of Materials (SBOM) and vulnerabilities

# A URL with more information about the repository
# homepage:

# Updates the default branch for this repository.
default_branch: main

# Either `true` to enable automated security fixes, or `false` to disable
# automated security fixes.
enable_automated_security_fixes: true

# Either `true` to enable vulnerability alerts, or `false` to disable
# vulnerability alerts.
enable_vulnerability_alerts: true

# See https://docs.github.com/en/rest/reference/teams#add-or-update-team-repository-permissions for available options
teams:
- name: vmclarity-admins
# The permission to grant the team. Can be one of:
# * `pull` - can pull, but not push to or administer this repository.
# * `push` - can pull and push, but not administer this repository.
# * `admin` - can pull, push and administer this repository.
# * `maintain` - Recommended for project managers who need to manage the repository without access to sensitive or destructive actions.
permission: admin

- name: vmclarity-maintainers
permission: maintain

# Collaborators: give specific users access to this repository.
# See https://docs.github.com/en/rest/reference/collaborators for available options
collaborators: []

branches:
- name: main
# https://docs.github.com/en/rest/reference/repos#update-branch-protection
# Branch Protection settings. Set to null to disable
protection:
# Required. Require at least one approving review on a pull request, before merging. Set to null to disable.
required_pull_request_reviews:
# The number of approvals required. (1-6)
required_approving_review_count: 1
# Dismiss approved reviews automatically when a new commit is pushed.
dismiss_stale_reviews: true
# Blocks merge until code owners have reviewed.
require_code_owner_reviews: true
# Specify which users and teams can dismiss pull request reviews. Pass an empty dismissal_restrictions object to disable. User and team dismissal_restrictions are only available for organization-owned repositories. Omit this parameter for personal repositories.
dismissal_restrictions:
users: []
teams: []
# Required. Require status checks to pass before merging. Set to null to disable
required_status_checks:
# Required. Require branches to be up to date before merging.
strict: true
# Required. The list of status checks to require in order to merge into this branch
contexts: []
# Required. Enforce all configured restrictions for administrators. Set to true to enforce required status checks for repository administrators. Set to null to disable.
enforce_admins: true
# Prevent merge commits from being pushed to matching branches
required_linear_history: true
# Required. Restrict who can push to this branch. Team and user restrictions are only available for organization-owned repositories. Set to null to disable.
restrictions:
apps: []
users: []
teams: []
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI
on:
pull_request:

env:
GO_VERSION: 1.19

jobs:
verification:
name: Verification
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}

- name: Check licenses
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: make license-check

- name: Run verification
run: make check

build:
needs: verification
name: Build
uses: ./.github/workflows/reusable-build-and-push.yml
with:
image_tag: ${{ github.sha }}
push: false
upload: false
81 changes: 81 additions & 0 deletions .github/workflows/reusable-build-and-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Build & Push

on:
workflow_call:
inputs:
image_tag:
required: true
type: string
description: 'Image tag to build and push.'
push:
required: false
type: string
description: 'If set to true, push the image.'
default: false
upload:
required: false
type: string
description: 'If set to true, upload the image.'
default: false

jobs:
timestamp:
runs-on: ubuntu-latest
outputs:
timestamp: ${{ steps.timestamp.outputs.timestamp }}
steps:
- name: Get current timestamp
id: timestamp
run: echo "::set-output name=timestamp::$(date -u +'%Y-%m-%dT%H:%M:%SZ')"

vmclarity:
needs: timestamp
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.ref }}
restore-keys: |
${{ runner.os }}-buildx-

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set build output env var
if: ${{ inputs.upload == 'true' }}
run: |
echo "OUTPUTS=type=docker,dest=/tmp/vmclarity.tar" >> $GITHUB_ENV

- name: Build
uses: docker/build-push-action@v3
with:
context: .
tags: ghcr.io/openclarity/vmclarity:${{ inputs.image_tag }}
file: Dockerfile
push: ${{ inputs.push }}
outputs: "${{ env.OUTPUTS }}"
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
build-args: |
VERSION=${{ inputs.image_tag }}
BUILD_TIMESTAMP=${{ needs.timestamp.outputs.timestamp }}
COMMIT_HASH=${{ github.sha }}

- name: Upload artifact
if: ${{ inputs.upload == 'true' }}
uses: actions/upload-artifact@v3
with:
name: vmclarity
path: /tmp/vmclarity.tar
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
.idea/
bin/
62 changes: 62 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
run:
timeout: 15m

linters-settings:
golint:
min-confidence: 0.1
goimports:
local-prefixes: github.com/openclarity/vmclarity
errorlint:
# Check whether fmt.Errorf uses the %w verb for formatting errors. See the readme for caveats
errorf: false

gosec:
# To specify a set of rules to explicitly exclude.
# Available rules: https://github.com/securego/gosec#available-rules
# excludes:
# - G404 # Insecure random number source (rand)
forbidigo:
# Forbid the following identifiers (identifiers are written using regexp):
forbid:
- ^print.*$

linters:
enable-all: true
disable:
- maligned
- funlen
- dupl
- nestif
- wsl
- lll
- interfacer
- exhaustivestruct
- nlreturn
- gocritic
- gochecknoglobals
- testpackage
- goerr113
- paralleltest
- godox # Allow TODOs
- tagliatelle # Allow json(camel)
- scopelint # deprecated
- golint # deprecated
- ifshort # deprecated
- deadcode # deprecated
- varcheck # deprecated
- structcheck # deprecated
- nosnakecase # deprecated
- gochecknoinits # Allow init function
- nolintlint # Allow nolint
- varnamelen # Allow short var names
- ireturn # Allow returning with interfaces
- exhaustruct # Allow structures with uninitialized fields
- gci # imports still has gci lint errors after run `gci write --skip-generated -s standard -s default -s "prefix(github.com/openclarity/vmclarity)"`

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- govet
30 changes: 30 additions & 0 deletions .licensei.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
approved = [
"mit",
"apache-2.0",
"bsd-3-clause",
"bsd-2-clause",
"mpl-2.0",
"isc"
]

ignored = [

]

[header]
ignorePaths = []
ignoreFiles = []
template = """// Copyright © :YEAR: Cisco Systems, Inc. and its affiliates.
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License."""
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM golang:1.19.3-alpine AS builder

WORKDIR /build
COPY go.* ./
RUN go mod download

ARG VERSION
ARG BUILD_TIMESTAMP
ARG COMMIT_HASH

# Copy and build backend code
COPY . .
RUN go build -ldflags="-s -w \
-X 'github.com/openclarity/vmclarity/pkg/version.Version=${VERSION}' \
-X 'github.com/openclarity/vmclarity/pkg/version.CommitHash=${COMMIT_HASH}' \
-X 'github.com/openclarity/vmclarity/pkg/version.BuildTimestamp=${BUILD_TIMESTAMP}'" -o vmclarity ./main.go

FROM alpine:3.16

WORKDIR /app

COPY --from=builder ["/build/vmclarity", "./vmclarity"]

ENTRYPOINT ["/app/vmclarity"]
Loading