Skip to content

Commit d6c1b0f

Browse files
authored
feat: add mise and node engines support (#25)
1 parent 6f8e449 commit d6c1b0f

39 files changed

+337
-7
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,12 @@ Read on to see runtime-specific examples and how to configure the generated Dock
134134

135135
#### Detected Files
136136
- `bun.lockb`
137+
- `bun.lock`
137138
- `bunfig.toml`
138139

139140
#### Version Detection
140141
- `.tool-versions` - `bun {VERSION}`
142+
- `.mise.toml` - `bun = "{VERSION}"`
141143

142144
#### Runtime Image
143145
`oven/bun:${VERSION}-slim`
@@ -174,6 +176,7 @@ Detected in order of precedence:
174176

175177
#### Version Detection
176178
- `.tool-versions` - `deno {VERSION}`
179+
- `.mise.toml` - `deno = "{VERSION}"`
177180

178181
#### Runtime Image
179182
`debian:stable-slim`
@@ -209,6 +212,7 @@ Detected in order of precedence:
209212
- `.tool-versions` - `erlang {VERSION}`
210213
- `.elixir-version` - `{VERSION}`
211214
- `.erlang-version` - `{VERSION}`
215+
- `.mise.toml` - `erlang = "{VERSION}"`
212216

213217
#### Runtime Image
214218
`debian:stable-slim`
@@ -233,6 +237,7 @@ Detected in order of precedence:
233237

234238
#### Version Detection
235239
- `.tool-versions` - `golang {VERSION}`
240+
- `.mise.toml` - `go = "{VERSION}"`
236241
- `go.mod` - `go {VERSION}`
237242

238243
#### Runtime Image
@@ -309,6 +314,8 @@ Maven version:
309314
- `.tool-versions` - `nodejs {VERSION}`
310315
- `.nvmrc` - `v{VERSION}`
311316
- `.node-version` - `v{VERSION}`
317+
- `.mise.toml` - `node = "{VERSION}"`
318+
- `package.json` - `"engines": {"node": "{VERSION}"}`
312319

313320
#### Runtime Image
314321
`node:${VERSION}-slim`
@@ -437,6 +444,7 @@ In order of precedence:
437444
#### Version Detection
438445
- `.tool-versions` - `python {VERSION}`
439446
- `.python-version` - `{VERSION}`
447+
- `.mise.toml` - `python = "{VERSION}"`
440448
- `runtime.txt` - `python-{VERSION}`
441449

442450
#### Runtime Image
@@ -477,6 +485,7 @@ In order of precedence:
477485
#### Version Detection
478486
- `.tool-versions` - `ruby {VERSION}`
479487
- `.ruby-version` - `{VERSION}`
488+
- `.mise.toml` - `ruby = "{VERSION}"`
480489
- `Gemfile` - `ruby '{VERSION}'`
481490

482491
#### Runtime Image

go.mod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module github.com/flexstack/new-dockerfile
22

3-
go 1.21
3+
go 1.21.0
4+
5+
toolchain go1.21.5
46

57
require (
68
github.com/lmittmann/tint v1.0.4
@@ -10,11 +12,12 @@ require (
1012
)
1113

1214
require (
15+
github.com/Masterminds/semver/v3 v3.3.0
1316
github.com/fsnotify/fsnotify v1.7.0 // indirect
1417
github.com/hashicorp/hcl v1.0.0 // indirect
1518
github.com/magiconair/properties v1.8.7 // indirect
1619
github.com/mitchellh/mapstructure v1.5.0 // indirect
17-
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
20+
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
1821
github.com/sagikazarmark/locafero v0.4.0 // indirect
1922
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
2023
github.com/sourcegraph/conc v0.3.0 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0=
2+
github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
13
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
24
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
35
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
@@ -24,6 +26,8 @@ github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3v
2426
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
2527
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
2628
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
29+
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
30+
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
2731
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
2832
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
2933
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=

runtime/bun.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"path/filepath"
1212
"strings"
1313
"text/template"
14+
15+
"github.com/pelletier/go-toml/v2"
1416
)
1517

1618
type Bun struct {
@@ -24,6 +26,7 @@ func (d *Bun) Name() RuntimeName {
2426
func (d *Bun) Match(path string) bool {
2527
checkPaths := []string{
2628
filepath.Join(path, "bun.lockb"),
29+
filepath.Join(path, "bun.lock"),
2730
filepath.Join(path, "bunfig.toml"),
2831
}
2932

@@ -185,6 +188,7 @@ func findBunVersion(path string, log *slog.Logger) (*string, error) {
185188
version := ""
186189
versionFiles := []string{
187190
".tool-versions",
191+
".mise.toml",
188192
}
189193

190194
for _, file := range versionFiles {
@@ -214,6 +218,23 @@ func findBunVersion(path string, log *slog.Logger) (*string, error) {
214218
return nil, fmt.Errorf("Failed to read .tool-versions file")
215219
}
216220

221+
case ".mise.toml":
222+
var mise MiseToml
223+
if err := toml.NewDecoder(f).Decode(&mise); err != nil {
224+
return nil, fmt.Errorf("Failed to decode .mise.toml file")
225+
}
226+
bunVersion, ok := mise.Tools["bun"].(string)
227+
if !ok {
228+
versions, ok := mise.Tools["bun"].([]string)
229+
if ok {
230+
bunVersion = versions[0]
231+
}
232+
}
233+
if bunVersion != "" {
234+
version = bunVersion
235+
log.Info("Detected Bun version in .mise.toml: " + version)
236+
break
237+
}
217238
}
218239

219240
f.Close()

runtime/bun_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ func TestBunGenerateDockerfile(t *testing.T) {
5353
path: "../testdata/bun",
5454
expected: []any{`ARG VERSION=1`, `ARG INSTALL_CMD="bun install"`, regexp.MustCompile(`^ARG BUILD_CMD=$`), `ARG START_CMD="bun index.ts"`},
5555
},
56+
{
57+
name: "Bun project w/ mise",
58+
path: "../testdata/bun-mise",
59+
expected: []any{`ARG VERSION=1.1.3`, `ARG INSTALL_CMD="bun install"`, regexp.MustCompile(`^ARG BUILD_CMD=$`), `ARG START_CMD="bun index.ts"`},
60+
},
5661
{
5762
name: "Bun project with .ts file",
5863
path: "../testdata/bun-bunfig",

runtime/deno.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"path/filepath"
1313
"strings"
1414
"text/template"
15+
16+
"github.com/pelletier/go-toml/v2"
1517
)
1618

1719
type Deno struct {
@@ -209,6 +211,7 @@ func findDenoVersion(path string, log *slog.Logger) (*string, error) {
209211
version := ""
210212
versionFiles := []string{
211213
".tool-versions",
214+
".mise.toml",
212215
}
213216

214217
for _, file := range versionFiles {
@@ -237,12 +240,31 @@ func findDenoVersion(path string, log *slog.Logger) (*string, error) {
237240
if err := scanner.Err(); err != nil {
238241
return nil, fmt.Errorf("Failed to read .tool-versions file")
239242
}
243+
244+
case ".mise.toml":
245+
var mise MiseToml
246+
if err := toml.NewDecoder(f).Decode(&mise); err != nil {
247+
return nil, fmt.Errorf("Failed to decode .mise.toml file")
248+
}
249+
denoVersion, ok := mise.Tools["deno"].(string)
250+
if !ok {
251+
versions, ok := mise.Tools["deno"].([]string)
252+
if ok {
253+
denoVersion = versions[0]
254+
}
255+
}
256+
if denoVersion != "" {
257+
version = denoVersion
258+
log.Info("Detected Deno version in .mise.toml: " + version)
259+
break
260+
}
240261
}
241262

242263
f.Close()
243264
if version != "" {
244265
break
245266
}
267+
246268
}
247269
}
248270

runtime/deno_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ func TestDenoGenerateDockerfile(t *testing.T) {
5353
path: "../testdata/deno",
5454
expected: []any{`ARG VERSION=latest`, `ARG INSTALL_CMD="deno cache main.ts"`, `ARG START_CMD="deno run --allow-all main.ts"`},
5555
},
56+
{
57+
name: "Deno project w/ mise",
58+
path: "../testdata/deno-mise",
59+
expected: []any{`ARG VERSION=1.43.2`, `ARG INSTALL_CMD="deno cache main.ts"`, `ARG START_CMD="deno run --allow-all main.ts"`},
60+
},
5661
{
5762
name: "Deno project with .ts file",
5863
path: "../testdata/deno-jsonc",

runtime/elixir.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"path/filepath"
1111
"strings"
1212
"text/template"
13+
14+
"github.com/pelletier/go-toml/v2"
1315
)
1416

1517
type Elixir struct {
@@ -120,9 +122,9 @@ RUN addgroup --system nonroot && adduser --system --ingroup nonroot nonroot
120122
121123
RUN chown -R nonroot:nonroot /app
122124
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
123-
ENV LANG en_US.UTF-8
124-
ENV LANGUAGE en_US:en
125-
ENV LC_ALL en_US.UTF-8
125+
ENV LANG=en_US.UTF-8
126+
ENV LANGUAGE=en_US:en
127+
ENV LC_ALL=en_US.UTF-8
126128
127129
ENV MIX_ENV="prod"
128130
@@ -210,6 +212,7 @@ func findOTPVersion(path string, log *slog.Logger) (*string, error) {
210212
versionFiles := []string{
211213
".tool-versions",
212214
".erlang-version",
215+
".mise.toml",
213216
}
214217

215218
for _, file := range versionFiles {
@@ -254,6 +257,23 @@ func findOTPVersion(path string, log *slog.Logger) (*string, error) {
254257
return nil, fmt.Errorf("Failed to read .erlang-version file")
255258
}
256259

260+
case ".mise.toml":
261+
var mise MiseToml
262+
if err := toml.NewDecoder(f).Decode(&mise); err != nil {
263+
return nil, fmt.Errorf("Failed to decode .mise.toml file")
264+
}
265+
erlangVersion, ok := mise.Tools["erlang"].(string)
266+
if !ok {
267+
versions, ok := mise.Tools["erlang"].([]string)
268+
if ok {
269+
erlangVersion = versions[0]
270+
}
271+
}
272+
if erlangVersion != "" {
273+
version = erlangVersion
274+
log.Info("Detected Erlang version in .mise.toml: " + version)
275+
break
276+
}
257277
}
258278

259279
f.Close()

runtime/elixir_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ func TestElixirGenerateDockerfile(t *testing.T) {
5252
path: "../testdata/elixir",
5353
expected: []any{`ARG VERSION=1.10`, `ARG OTP_VERSION=22`, `ARG BIN_NAME=hello`},
5454
},
55+
{
56+
name: "Elixir project w/ mise",
57+
path: "../testdata/elixir-mise",
58+
expected: []any{`ARG VERSION=1.10`, `ARG OTP_VERSION=23`, `ARG BIN_NAME=hello`},
59+
},
5560
{
5661
name: "Elixir project with .tool-versions",
5762
path: "../testdata/elixir-tool-versions",

runtime/golang.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"path/filepath"
1111
"strings"
1212
"text/template"
13+
14+
"github.com/pelletier/go-toml/v2"
1315
)
1416

1517
type Golang struct {
@@ -145,6 +147,7 @@ func findGoVersion(path string, log *slog.Logger) (*string, error) {
145147
version := ""
146148
versionFiles := []string{
147149
".tool-versions",
150+
".mise.toml",
148151
"go.mod",
149152
}
150153

@@ -190,6 +193,23 @@ func findGoVersion(path string, log *slog.Logger) (*string, error) {
190193
return nil, fmt.Errorf("Failed to read go.mod file")
191194
}
192195

196+
case ".mise.toml":
197+
var mise MiseToml
198+
if err := toml.NewDecoder(f).Decode(&mise); err != nil {
199+
return nil, fmt.Errorf("Failed to decode .mise.toml file")
200+
}
201+
goVersion, ok := mise.Tools["go"].(string)
202+
if !ok {
203+
versions, ok := mise.Tools["go"].([]string)
204+
if ok {
205+
goVersion = versions[0]
206+
}
207+
}
208+
if goVersion != "" {
209+
version = goVersion
210+
log.Info("Detected Python version in .mise.toml: " + version)
211+
break
212+
}
193213
}
194214

195215
f.Close()

runtime/golang_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ func TestGolangGenerateDockerfile(t *testing.T) {
5252
path: "../testdata/go",
5353
expected: []any{`ARG VERSION=1.16.3`, `ARG PACKAGE=./main.go`},
5454
},
55+
{
56+
name: "Golang project w/ mise",
57+
path: "../testdata/go-mise",
58+
expected: []any{`ARG VERSION=1.16`, `ARG PACKAGE=./main.go`},
59+
},
5560
{
5661
name: "Golang project with go.mod file",
5762
path: "../testdata/go-mod",

runtime/nextjs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ COPY . .
133133
# Next.js collects completely anonymous telemetry data about general usage.
134134
# Learn more here: https://nextjs.org/telemetry
135135
# Uncomment the following line in case you want to disable telemetry during the build.
136-
ENV NEXT_TELEMETRY_DISABLED 1
136+
ENV NEXT_TELEMETRY_DISABLED=1
137137
138138
RUN {{.BuildMounts}}if [ -f yarn.lock ]; then yarn run build; \
139139
elif [ -f package-lock.json ]; then npm run build; \
@@ -222,7 +222,7 @@ COPY --from=builder --chown=nonroot:nonroot /app/node_modules ./node_modules
222222
USER nonroot
223223
224224
ENV NODE_ENV=production
225-
ENV NEXT_TELEMETRY_DISABLED 1
225+
ENV NEXT_TELEMETRY_DISABLED=1
226226
ENV PORT=8080
227227
EXPOSE ${PORT}
228228
CMD ["node_modules/.bin/next", "start", "-H", "0.0.0.0"]

0 commit comments

Comments
 (0)