Skip to content

Commit

Permalink
Merge pull request #36 from interlynk-io/fix/dockerize
Browse files Browse the repository at this point in the history
[ISSUE-35] Dockerize sbomex release
  • Loading branch information
surendrapathak authored Jul 5, 2023
2 parents a633be1 + 39688ad commit ece969e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM golang:1.20-alpine AS builder
LABEL org.opencontainers.image.source="https://github.com/interlynk-io/sbomex"

RUN apk add --no-cache make
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN make ; make build

FROM scratch
LABEL org.opencontainers.image.source="https://github.com/interlynk-io/sbomex"
LABEL org.opencontainers.image.description="SBOM Explorer - Find and pull public SBOMs"
LABEL org.opencontainers.image.licenses=Apache-2.0

COPY --from=builder /app/build/sbomex /app/sbomex
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

ENTRYPOINT [ "/app/sbomex"]
23 changes: 20 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ package cmd

import (
"context"
"database/sql"
"fmt"
"io"
"net/http"
"os"
"path/filepath"

_ "github.com/glebarez/go-sqlite"
"github.com/google/go-github/v52/github"
"github.com/interlynk-io/sbomex/pkg/model"
"github.com/schollz/progressbar/v3"
Expand Down Expand Up @@ -59,11 +61,26 @@ func init() {
downloadDB(model.SbomlcDataSource, model.DbLocation)
}

func CheckSQLiteDB(filePath string) bool {
db, err := sql.Open("sqlite", filePath)
if err != nil {
return false
}
defer db.Close()

err = db.Ping()
if err != nil {
return false
}

return true
}

func downloadDB(path string, url string) {
var out *os.File
_, err := os.ReadFile(path)
if err != nil {
err = os.MkdirAll(filepath.Dir(path), os.ModePerm)
isValidDB := CheckSQLiteDB(path)
if !isValidDB {
var err = os.MkdirAll(filepath.Dir(path), os.ModePerm)
if err != nil {
fmt.Printf("failed to create directory %s", err.Error())
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import "time"

const (
SbomlcDataSource string = ".interlynk-io/sbomex/sqlite3.db"
DbLocation string = "https://github.com/interlynk-io/sbomdb/raw/v0.0.5/sbomlc.db"
DbLocation string = "https://github.com/interlynk-io/sbomdb/raw/v0.0.4/sbomlc.db"
)

type SBOMS struct {
Expand Down

0 comments on commit ece969e

Please sign in to comment.