Skip to content

Commit

Permalink
feat(tokenizer): support multiple files
Browse files Browse the repository at this point in the history
based on HashFiles .soos.json with package.json as default if not specified

Closes #11
  • Loading branch information
elmariofredo committed Jan 4, 2018
1 parent cffc363 commit da38821
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .soos.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"ImageName": "elmariofredo/soos-npm",
"HashFiles": [
"package.json",
"composer.json"
],
"ExposePorts": [
"3000:3000"
]
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"monolog/monolog": "1.0.*"
}
}
27 changes: 21 additions & 6 deletions soos.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ import (
"os/exec"
"os/user"
"path/filepath"

concatenate "github.com/paulvollmer/go-concatenate"
)

// Configuration : represent .soos.json structure
type Configuration struct {
ImageName string
ExposePorts []string
HashFiles []string
}

// DefaultConfig : base for .soos.json
var DefaultConfig = Configuration{
HashFiles: []string{"package.json"},
}

func getConfig() Configuration {
Expand All @@ -27,18 +35,24 @@ func getConfig() Configuration {
if err != nil {
fmt.Println("error:", err)
}

if len(configuration.HashFiles) == 0 {
configuration.HashFiles = DefaultConfig.HashFiles
}

return configuration
}

func tokenizer() string {
f, err := os.Open("package.json")
func tokenizer(hashFiles []string) string {

data, err := concatenate.FilesToBytes("\n", hashFiles...)

if err != nil {
log.Fatal(err)
}
defer f.Close()

h := sha1.New()
if _, err := io.Copy(h, f); err != nil {
if _, err := io.Copy(h, bytes.NewReader(data)); err != nil {
log.Fatal(err)
}

Expand Down Expand Up @@ -202,8 +216,9 @@ func pushImage(imageNameWithTag string) {
func main() {
fmt.Printf("<*> Soos start\n")

imageReference := tokenizer()
fmt.Printf("<-> Generated image name is %s\n", imageReference)
hashFiles := getConfig().HashFiles
imageReference := tokenizer(hashFiles)
fmt.Printf("<-> Generated image name is %s based on %s\n", imageReference, hashFiles)

fmt.Printf("<-> Verifying/Generating Dockerfile presence...")
genDockerfile()
Expand Down

0 comments on commit da38821

Please sign in to comment.