Skip to content

Commit

Permalink
Merge pull request #105 from DrDaveD/pre-v2
Browse files Browse the repository at this point in the history
Merge sylabs/sif up to the creation of v1 branch
  • Loading branch information
kmuriki authored Aug 10, 2021
2 parents 772602c + 0dbd405 commit acaf90f
Show file tree
Hide file tree
Showing 44 changed files with 757 additions and 849 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: '1.14.x'
go-version: '1.16.x'

- name: Check go.mod and go.sum are tidy
run: |
Expand All @@ -34,7 +34,7 @@ jobs:

- name: Check for Lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.39.0
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.41.0
$(go env GOPATH)/bin/golangci-lint run
- name: Run Tests
Expand Down
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
*~
/cmd/siftool/siftool

# couple test images to ignore
/pkg/sif/testdata/testcontainer.sif
/pkg/sif/testdata/test-obj-container.sif
6 changes: 2 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ linters:
- gocritic
- godot
- godox
- gofmt
- gofumpt
- goimports
- golint
- gomodguard
- goprintffuncname
- gosec
Expand All @@ -26,6 +25,7 @@ linters:
- misspell
- nolintlint
- prealloc
- revive
- rowserrcheck
- staticcheck
- structcheck
Expand All @@ -37,7 +37,5 @@ linters:
- whitespace

linters-settings:
gofmt:
simplify: true
misspell:
locale: US
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"go.lintTool":"golangci-lint",
"go.lintFlags": [
"--fast"
]
}
27 changes: 9 additions & 18 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,15 @@ all your interactions with the project members and users.

#### Process

1. Essential bug fix PRs should be sent to both master and release branches.
2. Small bug fix and feature enhancement PRs should be sent to master only.
3. Follow the existing code style precedent, especially for C. For Golang, you
will mostly conform to the style and form enforced by the "go fmt" and
"golint" tools for proper formatting.
4. Ensure any install or build dependencies are removed before doing a build
to test your PR locally.
5. For any new functionality, please write appropriate go tests that will run
as part of the Continuous Integration (Circle CI) system.
6. The project's default copyright and header have been included in any new
source files.
7. Make sure you have implemented a local `make test` and all tests succeed
before submitting the PR.
8. Is the code human understandable? This can be accomplished via a clear code
style as well as documentation and/or comments.
9. The pull request will be reviewed by others, and finally merged when all
requirements are met.
10. Documentation must be provided if necessary (next section)
1. Essential bug fix PRs should be sent to both `master` and release branches (if applicable).
1. Small bug fix and feature enhancement PRs should be sent to `master` only.
1. Follow the existing code style precedent. Use [golangci-lint](https://golangci-lint.run) to ensure your code is properly formatted and free of lint.
1. For any new functionality, please write appropriate tests that will run as part of the continuous integration system.
1. Ensure the project's default copyright and header have been included in any new source files.
1. Make sure you have run `go test ./...` and all tests succeed before submitting the PR.
1. Is the code human understandable? This can be accomplished via a clear code style as well as documentation and/or comments.
1. The pull request will be reviewed by others, and finally merged when all requirements are met.
1. Documentation must be provided if necessary (next section)

#### Documentation

Expand Down
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@
[![Code Coverage](https://codecov.io/gh/hpcng/sif/branch/master/graph/badge.svg)](https://codecov.io/gh/hpcng/sif)
[![Go Report Card](https://goreportcard.com/badge/github.com/hpcng/sif)](https://goreportcard.com/report/github.com/hpcng/sif)

SIF is an open source implementation of the Singularity Container Image Format
that makes it easy to create complete and encapsulated container enviroments
stored in a single file.
This module contains an open source implementation of the Singularity Image Format (SIF) that makes it easy to create complete and encapsulated container environments stored in a single file.

![SIF Image](doc/sif.png)

Unless otherwise noted, the SIF source files are distributed under the BSD-style
license found in the LICENSE.md file.
Unless otherwise noted, the SIF source files are distributed under the BSD-style license found in the [LICENSE.md](LICENSE.md) file.

## Download and Install From Source

To get the sif package to use directly from your programs:

```sh
go get -u github.com/hpcng/sif/pkg/sif
go get -u github.com/hpcng/sif
```

To get the siftool CLI program installed to `$(go env GOPATH)/bin` to manipulate SIF container files:
Expand All @@ -32,11 +29,10 @@ cd sif

## Go Version Compatibility

This module aims to maintain support for the two most recent stable versions of Go.
This module aims to maintain support for the two most recent stable versions of Go. This corresponds to the Go [Release Maintenance Policy](https://github.com/golang/go/wiki/Go-Release-Cycle#release-maintenance) and [Security Policy](https://golang.org/security), ensuring critical bug fixes and security patches are available for all supported language versions.

### Contributing
## Contributing

SIF and Singularity is the work of many contributors. We appreciate your help!
SIF and [Singularity](https://github.com/hpcng/singularity) are the work of many contributors. We appreciate your help!

To contribute, please read the contribution guidelines:
[CONTRIBUTING.md](./CONTRIBUTING.md)
To contribute, please read the contribution guidelines found in the [CONTRIBUTING.md](CONTRIBUTING.md) file.
5 changes: 3 additions & 2 deletions cmd/siftool/info.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (c) 2021, Sylabs Inc. All rights reserved.
// Copyright (c) 2018, Divya Cote <divya.cote@gmail.com> All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE file distributed with the sources of this project regarding your
Expand Down Expand Up @@ -41,7 +42,7 @@ func cmdInfo(args []string) error {
return fmt.Errorf("while converting input descriptor id: %s", err)
}

return siftool.Info(id, args[1])
return siftool.Info(args[1], uint32(id))
}

// cmdDump extracts and output a data object from a SIF file to stdout.
Expand All @@ -55,5 +56,5 @@ func cmdDump(args []string) error {
return fmt.Errorf("while converting input descriptor id: %s", err)
}

return siftool.Dump(id, args[1])
return siftool.Dump(args[1], uint32(id))
}
125 changes: 101 additions & 24 deletions cmd/siftool/modif.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
// Copyright (c) 2018, Sylabs Inc. All rights reserved.
// Copyright (c) 2018-2021, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE file distributed with the sources of this project regarding your
// rights to use or distribute this software.

package main

import (
"errors"
"flag"
"fmt"
"os"
"strconv"

"github.com/hpcng/sif/internal/app/siftool"
"github.com/hpcng/sif/pkg/sif"
)

var datatype = flag.Int64("datatype", -1, "")
var parttype = flag.Int64("parttype", -1, "")
var partfs = flag.Int64("partfs", -1, "")
var partarch = flag.Int64("partarch", -1, "")
var signhash = flag.Int64("signhash", -1, "")
var signentity = flag.String("signentity", "", "")
var groupid = flag.Int64("groupid", sif.DescrUnusedGroup, "")
var link = flag.Int64("link", sif.DescrUnusedLink, "")
var alignment = flag.Int("alignment", 0, "")
var filename = flag.String("filename", "", "")
var (
datatype = flag.Int("datatype", 0, "")
parttype = flag.Int("parttype", 0, "")
partfs = flag.Int("partfs", 0, "")
partarch = flag.Int("partarch", 0, "")
signhash = flag.Int("signhash", 0, "")
signentity = flag.String("signentity", "", "")
groupid = flag.Int("groupid", 0, "")
link = flag.Int("link", 0, "")
alignment = flag.Int("alignment", 0, "")
filename = flag.String("filename", "", "")
)

func cmdNew(args []string) error {
if len(args) != 1 {
Expand All @@ -39,19 +43,92 @@ func cmdAdd(args []string) error {
}

opts := siftool.AddOptions{
Datatype: datatype,
Parttype: parttype,
Partfs: partfs,
Partarch: partarch,
Signhash: signhash,
Signentity: signentity,
Groupid: groupid,
Link: link,
Alignment: alignment,
Filename: filename,
Groupid: uint32(*groupid),
Link: uint32(*link),
Alignment: *alignment,
Filename: *filename,
Fp: os.Stdin,
}

switch *datatype {
case 1:
opts.Datatype = sif.DataDeffile
case 2:
opts.Datatype = sif.DataEnvVar
case 3:
opts.Datatype = sif.DataLabels
case 4:
opts.Datatype = sif.DataPartition
case 5:
opts.Datatype = sif.DataSignature
case 6:
opts.Datatype = sif.DataGenericJSON
case 7:
opts.Datatype = sif.DataGeneric
case 8:
opts.Datatype = sif.DataCryptoMessage
default:
return errors.New("-datatype flag is required with a valid range")
}

if opts.Datatype == sif.DataPartition {
if *partfs == 0 || *parttype == 0 || *partarch == 0 {
return errors.New("with partition datatype, -partfs, -parttype and -partarch must be passed")
}

opts.Parttype = sif.Parttype(*parttype)
opts.Partfs = sif.Fstype(*partfs)

switch *partarch {
case 1:
opts.Partarch = sif.HdrArch386
case 2:
opts.Partarch = sif.HdrArchAMD64
case 3:
opts.Partarch = sif.HdrArchARM
case 4:
opts.Partarch = sif.HdrArchARM64
case 5:
opts.Partarch = sif.HdrArchPPC64
case 6:
opts.Partarch = sif.HdrArchPPC64le
case 7:
opts.Partarch = sif.HdrArchMIPS
case 8:
opts.Partarch = sif.HdrArchMIPSle
case 9:
opts.Partarch = sif.HdrArchMIPS64
case 10:
opts.Partarch = sif.HdrArchMIPS64le
case 11:
opts.Partarch = sif.HdrArchS390x
default:
return errors.New("-partarch flag is required with a valid range")
}
} else if opts.Datatype == sif.DataSignature {
if *signhash == 0 || *signentity == "" {
return errors.New("with signature datatype, -signhash and -signentity must be passed")
}

opts.Signhash = sif.Hashtype(*signhash)
opts.Signentity = *signentity
}

if dataFile := args[1]; dataFile != "-" {
fp, err := os.Open(dataFile)
if err != nil {
return err
}
defer fp.Close()

opts.Fp = fp

if opts.Filename == "" {
opts.Filename = dataFile
}
}

return siftool.Add(args[0], args[1], opts)
return siftool.Add(args[0], opts)
}

func cmdDel(args []string) error {
Expand All @@ -64,7 +141,7 @@ func cmdDel(args []string) error {
return fmt.Errorf("while converting input descriptor id: %s", err)
}

return siftool.Del(id, args[1])
return siftool.Del(args[1], uint32(id))
}

func cmdSetPrim(args []string) error {
Expand All @@ -77,5 +154,5 @@ func cmdSetPrim(args []string) error {
return fmt.Errorf("while converting input descriptor id: %s", err)
}

return siftool.Setprim(id, args[0])
return siftool.Setprim(args[0], uint32(id))
}
4 changes: 2 additions & 2 deletions cmd/siftool/siftool.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ func main() {
-signentity the entity that signs (with -datatype 5-Signature)
[NEEDED, no default]:
example: 433FE984155206BD962725E20E8713472A879943
-groupid set groupid [default: DescrUnusedGroup]
-link set link pointer [default: DescrUnusedLink]
-groupid set groupid [default: 0]
-link set link pointer [default: 0]
-alignment set alignment constraint [default: aligned on page size]
-filename set logical filename/handle [default: input filename]
`},
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.15

require (
github.com/satori/go.uuid v1.2.1-0.20180404165556-75cca531ea76
github.com/sebdah/goldie/v2 v2.5.3
github.com/spf13/cobra v1.2.1
golang.org/x/crypto v0.0.0-20210503195802-e9a32991a82e
)
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down Expand Up @@ -191,6 +192,7 @@ github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FI
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
Expand All @@ -201,6 +203,10 @@ github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb
github.com/satori/go.uuid v1.2.1-0.20180404165556-75cca531ea76 h1:ofyVTM1w4iyKwaQIlRR6Ip06mXXx5Cnz7a4mTGYq1hE=
github.com/satori/go.uuid v1.2.1-0.20180404165556-75cca531ea76/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/sebdah/goldie/v2 v2.5.3 h1:9ES/mNN+HNUbNWpVAlrzuZ7jE+Nrczbj8uFRjM7624Y=
github.com/sebdah/goldie/v2 v2.5.3/go.mod h1:oZ9fp0+se1eapSRjfYbsV/0Hqhbuu3bJVvKI/NNtssI=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
Expand All @@ -218,6 +224,7 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down Expand Up @@ -560,6 +567,7 @@ gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
Loading

0 comments on commit acaf90f

Please sign in to comment.