Skip to content

Commit da38821

Browse files
feat(tokenizer): support multiple files
based on HashFiles .soos.json with package.json as default if not specified Closes #11
1 parent cffc363 commit da38821

3 files changed

Lines changed: 30 additions & 6 deletions

File tree

.soos.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"ImageName": "elmariofredo/soos-npm",
3+
"HashFiles": [
4+
"package.json",
5+
"composer.json"
6+
],
37
"ExposePorts": [
48
"3000:3000"
59
]

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require": {
3+
"monolog/monolog": "1.0.*"
4+
}
5+
}

soos.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@ import (
1111
"os/exec"
1212
"os/user"
1313
"path/filepath"
14+
15+
concatenate "github.com/paulvollmer/go-concatenate"
1416
)
1517

1618
// Configuration : represent .soos.json structure
1719
type Configuration struct {
1820
ImageName string
1921
ExposePorts []string
22+
HashFiles []string
23+
}
24+
25+
// DefaultConfig : base for .soos.json
26+
var DefaultConfig = Configuration{
27+
HashFiles: []string{"package.json"},
2028
}
2129

2230
func getConfig() Configuration {
@@ -27,18 +35,24 @@ func getConfig() Configuration {
2735
if err != nil {
2836
fmt.Println("error:", err)
2937
}
38+
39+
if len(configuration.HashFiles) == 0 {
40+
configuration.HashFiles = DefaultConfig.HashFiles
41+
}
42+
3043
return configuration
3144
}
3245

33-
func tokenizer() string {
34-
f, err := os.Open("package.json")
46+
func tokenizer(hashFiles []string) string {
47+
48+
data, err := concatenate.FilesToBytes("\n", hashFiles...)
49+
3550
if err != nil {
3651
log.Fatal(err)
3752
}
38-
defer f.Close()
3953

4054
h := sha1.New()
41-
if _, err := io.Copy(h, f); err != nil {
55+
if _, err := io.Copy(h, bytes.NewReader(data)); err != nil {
4256
log.Fatal(err)
4357
}
4458

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

205-
imageReference := tokenizer()
206-
fmt.Printf("<-> Generated image name is %s\n", imageReference)
219+
hashFiles := getConfig().HashFiles
220+
imageReference := tokenizer(hashFiles)
221+
fmt.Printf("<-> Generated image name is %s based on %s\n", imageReference, hashFiles)
207222

208223
fmt.Printf("<-> Verifying/Generating Dockerfile presence...")
209224
genDockerfile()

0 commit comments

Comments
 (0)