Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Bump function builder
Browse files Browse the repository at this point in the history
Signed-off-by: Darren Shepherd <darren@acorn.io>
  • Loading branch information
ibuildthecloud committed Jan 11, 2024
1 parent 43dbcbf commit 9aab141
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 48 deletions.
2 changes: 1 addition & 1 deletion docs/docs/100-reference/01-command-line/acorn_logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ acorn logs [flags] [ACORN_NAME|CONTAINER_REPLICA_NAME]
-f, --follow Follow log output
-h, --help help for logs
-s, --since string Show logs since timestamp (e.g. 42m for 42 minutes)
-n, --tail int Number of lines in log output
-n, --tail int Number of lines in log output (-1 for all) (default 100)
```

### Options inherited from parent commands
Expand Down
18 changes: 9 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/acorn-io/aml/cli v0.0.0-20240106192317-21afc7320c77
github.com/acorn-io/baaah v0.0.0-20240105013849-c4f82d7a5a41
github.com/acorn-io/broadcaster v0.0.0-20240105011354-bfadd4a7b45d
github.com/acorn-io/function-builder v0.0.0-20240106051830-f0d368d2382c
github.com/acorn-io/function-builder v0.0.0-20240111042311-041315dd7091
github.com/acorn-io/mink v0.0.0-20240105015834-b1f7af4fadea
github.com/acorn-io/namegenerator v0.0.0-20220915160418-9e3d5a0ffe78
github.com/acorn-io/schemer v0.0.0-20240105014212-9739d5485208
Expand Down Expand Up @@ -54,9 +54,9 @@ require (
github.com/stretchr/testify v1.8.4
github.com/tonistiigi/fsutil v0.0.0-20230629203738-36ef4d8c0dbb
github.com/wI2L/jsondiff v0.3.0
golang.org/x/crypto v0.14.0
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/sync v0.4.0
golang.org/x/crypto v0.16.0
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc
golang.org/x/sync v0.5.0
google.golang.org/grpc v1.58.3
inet.af/tcpproxy v0.0.0-20221017015627-91f861402626
k8s.io/api v0.29.0
Expand Down Expand Up @@ -285,14 +285,14 @@ require (
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.14.0 // indirect
golang.org/x/tools v0.16.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect
Expand Down
36 changes: 18 additions & 18 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ github.com/acorn-io/broadcaster v0.0.0-20240105011354-bfadd4a7b45d h1:hfpNQkJ4I2
github.com/acorn-io/broadcaster v0.0.0-20240105011354-bfadd4a7b45d/go.mod h1:WF6FYrEqW0+ZtY5OKb21JhSL0aeL5VJoVrm+u0d4gOE=
github.com/acorn-io/cmd v0.0.0-20230929053520-ebe1b9879b38 h1:oJMGvI702ZW5L0JjJfGV9ekzU2IqqTGjmAQl4gkO6Ro=
github.com/acorn-io/cmd v0.0.0-20230929053520-ebe1b9879b38/go.mod h1:bo9ONX4kagbQmXcG4bnfoK53MBFFtbUZ5fR7s9NfS+M=
github.com/acorn-io/function-builder v0.0.0-20240106051830-f0d368d2382c h1:xfOXFsu5BBsZg6B+xkD4mrP1vacp+WofRTfReSYpS1A=
github.com/acorn-io/function-builder v0.0.0-20240106051830-f0d368d2382c/go.mod h1:yf8qvacJItEV62UVTgNoTTnZHF/1/kqu+eU0CNf9hLw=
github.com/acorn-io/function-builder v0.0.0-20240111042311-041315dd7091 h1:l+cuQsOK7aoC8VIq6C+Q98Svq9OgmzNCWuCcWhRw27w=
github.com/acorn-io/function-builder v0.0.0-20240111042311-041315dd7091/go.mod h1:b60OzYlyV4fuiTw3HExgOJITsXnfm0c0uIoywz7s+Y4=
github.com/acorn-io/mink v0.0.0-20240105015834-b1f7af4fadea h1:HyH8nh7zZ7qZeWOjBGtK/iAI5gCu/c5iSnN703hlHHY=
github.com/acorn-io/mink v0.0.0-20240105015834-b1f7af4fadea/go.mod h1:EmoDPUYsPyBEhEpSC+LpRGUs2GeSI5nPOTa7WO7jwlc=
github.com/acorn-io/namegenerator v0.0.0-20220915160418-9e3d5a0ffe78 h1:5zs9L/CXNkuTdJSbhFWczAorbmx67nqlqswx5CQi7XI=
Expand Down Expand Up @@ -1107,8 +1107,8 @@ golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0
golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand All @@ -1119,8 +1119,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc h1:ao2WRsKSzW6KuUY9IWPwWahcHCgR0s52IfwutMfEbdM=
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down Expand Up @@ -1150,8 +1150,8 @@ golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -1202,8 +1202,8 @@ golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -1231,8 +1231,8 @@ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -1324,8 +1324,8 @@ golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -1341,8 +1341,8 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down Expand Up @@ -1413,8 +1413,8 @@ golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.8.0/go.mod h1:JxBZ99ISMI5ViVkT1tr6tdNmXeTrcpVSD3vZ1RsRdN4=
golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM=
golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc=
golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg=
golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM=
golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/internal.acorn.io/v1/appspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,13 @@ type Assistant struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Prompts Prompts `json:"prompts,omitempty"`
Vision bool `json:"vision,omitempty"`
Model string `json:"model,omitempty"`
Dependencies Dependencies `json:"tools,omitempty"`
InputSchema *jsonschema.Schema `json:"inputSchema,omitempty"`
MaxTokens int `json:"maxTokens,omitempty"`
JSONResponse bool `json:"jsonResponse,omitempty"`
Cache *bool `json:"cache,omitempty"`
}

type Prompts []string
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/internal.acorn.io/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pkg/appdefinition/acornfile-schema.acorn
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,10 @@ let types: {
model?: string || Model
tools: string || [string]
inputSchema?: schema
vision: false
maxTokens?: int
jsonResponse: false
cache: true
}

RouteTargetName: "^[a-z][-a-z0-9]*(:[0-9]+)?$"
Expand Down
17 changes: 15 additions & 2 deletions pkg/appdefinition/appdefinition.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ func overlayFragment(con *v1.Container, imagesData v1.ImagesData, imageID, servi

strData := fmt.Sprintf(`
let serviceName: "%s"
{ %s } + { %s }`, serviceName, containerData, fragment)
let base: { %s }
{ %s } + { %s }`, serviceName, containerData, containerData, fragment)

return aml.Unmarshal([]byte(strData), con)
}
Expand Down Expand Up @@ -359,6 +360,18 @@ func (a *AppDefinition) AppSpec() (*v1.AppSpec, error) {
return spec, v1.AddImpliedResources(spec)
}

func addFunctionFiles(fileSet map[string]bool, builds map[string]v1.ContainerImageBuilderSpec, cwd string) {
for key, build := range builds {
addContainerFiles(fileSet, build.Sidecars, cwd)
context := build.Src
if context == "" {
context = key
}
fileSet[filepath.Join(cwd, context, "build.acorn")] = true
fileSet[filepath.Join(cwd, context, ".dockerignore")] = true
}
}

func addContainerFiles(fileSet map[string]bool, builds map[string]v1.ContainerImageBuilderSpec, cwd string) {
for _, build := range builds {
addContainerFiles(fileSet, build.Sidecars, cwd)
Expand Down Expand Up @@ -416,7 +429,7 @@ func (a *AppDefinition) WatchFiles(cwd string) (result []string, _ error) {
}

addContainerFiles(fileSet, spec.Containers, cwd)
addContainerFiles(fileSet, spec.Functions, cwd)
addFunctionFiles(fileSet, spec.Functions, cwd)
addContainerFiles(fileSet, spec.Jobs, cwd)
addFiles(fileSet, spec.Images, cwd)
addAcorns(fileSet, spec.Services, cwd)
Expand Down
9 changes: 2 additions & 7 deletions pkg/cli/log.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cli

import (
"fmt"

apiv1 "github.com/acorn-io/runtime/pkg/apis/api.acorn.io/v1"
cli "github.com/acorn-io/runtime/pkg/cli/builder"
"github.com/acorn-io/runtime/pkg/client"
Expand All @@ -24,7 +22,7 @@ func NewLogs(c CommandContext) *cobra.Command {
type Logs struct {
Follow bool `short:"f" usage:"Follow log output"`
Since string `short:"s" usage:"Show logs since timestamp (e.g. 42m for 42 minutes)"`
Tail int64 `short:"n" usage:"Number of lines in log output"`
Tail int64 `short:"n" usage:"Number of lines in log output (-1 for all)" default:"100"`
Container string `short:"c" usage:"Container name or Job name within app to follow"`
client ClientFactory
}
Expand All @@ -44,10 +42,7 @@ func (s *Logs) Run(cmd *cobra.Command, args []string) error {
}

var tailLines *int64
if s.Tail < 0 {
err := fmt.Errorf("Tail: Invalid value: %d: must be greater than or equal to 0", s.Tail)
return err
} else if s.Tail == 0 {
if s.Tail <= 0 {
tailLines = nil
} else {
tailLines = &s.Tail
Expand Down
35 changes: 32 additions & 3 deletions pkg/dev/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"io"
"io/fs"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -90,6 +91,29 @@ func containerSync(ctx context.Context, client client.Client, logger Logger, app
return err
}

func findDockerIgnore(path string) (string, error) {
startPath := filepath.Join(path, ".dockerignore")
for {
testPath := filepath.Join(path, ".dockerignore")
if _, err := os.Stat(testPath); err == nil {
return testPath, nil
} else if errors.Is(err, fs.ErrNotExist) {
newPath := filepath.Dir(path)
if newPath == path {
return startPath, nil
}
if _, err := os.Stat(newPath); errors.Is(err, fs.ErrNotExist) {
return startPath, nil
} else if err != nil {
return "", err
}
path = newPath
} else {
return "", err
}
}
}

func invokeStartSyncForPath(ctx context.Context, client client.Client, logger Logger, con *apiv1.ContainerReplica, cwd, localDir, remoteDir string, bidirectional bool) (chan struct{}, chan error, error) {
source := filepath.Join(cwd, localDir)
if s, err := os.Stat(source); err == nil && !s.IsDir() {
Expand All @@ -100,7 +124,12 @@ func invokeStartSyncForPath(ctx context.Context, client client.Client, logger Lo
return nil, nil, err
}
var exclude []string
f, err := os.Open(filepath.Join(cwd, ".dockerignore"))
dockerIgnorePath, err := findDockerIgnore(filepath.Join(cwd, localDir))
if err != nil {
return nil, nil, err
}

f, err := os.Open(dockerIgnorePath)
if err == nil {
lines, err := dockerignore.ReadAll(f)
_ = f.Close()
Expand All @@ -110,7 +139,7 @@ func invokeStartSyncForPath(ctx context.Context, client client.Client, logger Lo
logrus.Warnf("failed to read %s for syncing: %v", filepath.Join(cwd, ".dockerignore"), err)
exclude = nil
}
} else if !os.IsNotExist(err) {
} else if !errors.Is(err, fs.ErrNotExist) {
logrus.Warnf("failed to open %s for syncing: %v", filepath.Join(cwd, ".dockerignore"), err)
exclude = nil
}
Expand All @@ -121,7 +150,7 @@ func invokeStartSyncForPath(ctx context.Context, client client.Client, logger Lo
UploadExcludePaths: exclude,
InitialSync: latest.InitialSyncStrategyPreferLocal,
Log: newLogger(logger, con).
WithPrefix(strings.TrimPrefix(con.Name, con.Spec.AppName+".") + ": (sync): "),
WithPrefix("(sync): "),
})
if err != nil {
return nil, nil, err
Expand Down
8 changes: 7 additions & 1 deletion pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func pipe(input io.ReadCloser, output chan<- Message, pod *corev1.Pod, name stri
var lastTS *metav1.Time

scanner := bufio.NewScanner(input)
scanner.Buffer(nil, 1_000_000)
scanner.Buffer(nil, 2_000_000)
for scanner.Scan() {
line := scanner.Text()
ts, newLine, _ := strings.Cut(line, " ")
Expand Down Expand Up @@ -417,6 +417,8 @@ func matchesContainer(pod *corev1.Pod, container corev1.Container, options *Opti
if containerName == "" {
if pod.Labels[applabels.AcornContainerName] != "" {
return pod.Name == podName && container.Name == pod.Labels[applabels.AcornContainerName]
} else if pod.Labels[applabels.AcornFunctionName] != "" {
return pod.Name == podName && container.Name == pod.Labels[applabels.AcornFunctionName]
} else {
return pod.Name == podName && container.Name == pod.Labels[applabels.AcornJobName]
}
Expand All @@ -429,6 +431,7 @@ func matchesContainer(pod *corev1.Pod, container corev1.Container, options *Opti
if options != nil && options.Container != "" {
// Must match the acorn container name or job name on the pod
if pod.Labels[applabels.AcornContainerName] != options.Container &&
pod.Labels[applabels.AcornFunctionName] != options.Container &&
pod.Labels[applabels.AcornJobName] != options.Container {
return false
}
Expand All @@ -438,6 +441,9 @@ func matchesContainer(pod *corev1.Pod, container corev1.Container, options *Opti
if pod.Labels[applabels.AcornContainerName] != "" {
validContainerNames = append(validContainerNames, pod.Labels[applabels.AcornContainerName])
}
if pod.Labels[applabels.AcornFunctionName] != "" {
validContainerNames = append(validContainerNames, pod.Labels[applabels.AcornFunctionName])
}
if pod.Labels[applabels.AcornJobName] != "" {
validContainerNames = append(validContainerNames, pod.Labels[applabels.AcornJobName])
}
Expand Down
Loading

0 comments on commit 9aab141

Please sign in to comment.