Skip to content

Commit

Permalink
upgrade default deno to 2.0.4, try to detect more deno apps, add test…
Browse files Browse the repository at this point in the history
… for extremely minimal deno app
  • Loading branch information
jeromegn committed Nov 1, 2024
1 parent 64878e3 commit ec683eb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
20 changes: 17 additions & 3 deletions scanner/deno.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
package scanner

import "github.com/superfly/flyctl/internal/command/launch/plan"
import (
"fmt"
"path/filepath"

"github.com/superfly/flyctl/internal/command/launch/plan"
)

func configureDeno(sourceDir string, config *ScannerConfig) (*SourceInfo, error) {
if !checksPass(
sourceDir,
// default config files: https://deno.land/[email protected]/getting_started/configuration_file
fileExists("deno.json", "deno.jsonc"),
// deno.land and denopkg.com imports
dirContains("*.ts", "\"https?://deno\\.land/.*\"", "\"https?://denopkg\\.com/.*\""),
dirContains("*.ts", `"https?://deno\.land/.*"`, `"https?://denopkg\.com/.*"`, `import "(.*)\.tsx{0,}"`, `from "npm:.*"`, `from "jsr:.*"`, `Deno\.serve\(.*`, `Deno\.listen\(.*`),
) {
return nil, nil
}

var entrypoint string

for _, path := range []string{"index.ts", "app.ts", "server.ts"} {
if absFileExists(filepath.Join(sourceDir, path)) {
entrypoint = path
break
}
}

s := &SourceInfo{
Files: templates("templates/deno"),
Family: "Deno",
Port: 8080,
Processes: map[string]string{
"app": "run --allow-net ./example.ts",
"app": fmt.Sprintf("run -A ./%s", entrypoint),
},
Env: map[string]string{
"PORT": "8080",
Expand Down
4 changes: 2 additions & 2 deletions scanner/templates/deno/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Based on https://github.com/denoland/deno_docker/blob/main/alpine.dockerfile

ARG DENO_VERSION=1.14.0
ARG DENO_VERSION=2.0.4
ARG BIN_IMAGE=denoland/deno:bin-${DENO_VERSION}
FROM ${BIN_IMAGE} AS bin

Expand All @@ -24,4 +24,4 @@ WORKDIR /deno-dir
COPY . .

ENTRYPOINT ["/bin/deno"]
CMD ["run", "--allow-net", "https://deno.land/std/examples/echo_server.ts"]
CMD ["run", "https://deno.land/std/examples/echo_server.ts"]
24 changes: 24 additions & 0 deletions test/deployer/deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,30 @@ func TestLaunchGoNoGoSum(t *testing.T) {
require.Contains(t, string(body), "Hello from Go!")
}

func TestLaunchDenoNoConfig(t *testing.T) {
deploy := testDeployer(t,
withFixtureApp("deno-no-config"),
createRandomApp,
testlib.WithoutCustomize,
testlib.WithouExtensions,
testlib.DeployNow,
withWorkDirAppSource,
testlib.CleanupBeforeExit,
)

manifest, err := deploy.Output().ArtifactManifest()
require.NoError(t, err)
require.NotNil(t, manifest)

require.Equal(t, "deno", manifest.Plan.Runtime.Language)

appName := deploy.Extra["appName"].(string)

body, err := testlib.RunHealthCheck(fmt.Sprintf("https://%s.fly.dev/", appName))
require.NoError(t, err)
require.Contains(t, string(body), "Hello, World!")
}

func createRandomApp(d *testlib.DeployTestRun) {
appName := d.CreateRandomAppName()
require.NotEmpty(d, appName)
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/deno-no-config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Deno.serve({ port: 8080, hostname: "0.0.0.0" }, (_req) => {
return new Response("Hello, World!");
});

0 comments on commit ec683eb

Please sign in to comment.