Skip to content

Commit

Permalink
enforce deno version
Browse files Browse the repository at this point in the history
  • Loading branch information
pomdtr committed Mar 3, 2025
1 parent 290e39f commit 894db34
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ COPY . .
ARG SMALLWEB_VERSION=dev
RUN go build -ldflags="-s -w -X github.com/pomdtr/smallweb/build.Version=${SMALLWEB_VERSION}" -o smallweb

FROM denoland/deno:2.2.2
FROM debian:bookworm-slim
COPY --from=builder /build/smallweb /usr/local/bin/smallweb

RUN apt update && apt install -y git && rm -rf /var/lib/apt/lists/*
RUN apt update && apt install -y git unzip curl && rm -rf /var/lib/apt/lists/*

ARG DENO_VERSION=v2.2.2
RUN curl -fsSL https://deno.land/install.sh | DENO_INSTALL=/usr/local/deno sh -s "$DENO_VERSION"
ENV PATH="/usr/local/deno/bin:$PATH"

ENV SMALLWEB_DIR=/smallweb
VOLUME ["$SMALLWEB_DIR"]

EXPOSE 7777 2222
ENTRYPOINT ["/usr/local/bin/smallweb"]
CMD [ "up", "--cron", "--addr", ":7777", "--ssh-addr", ":2222" ]
CMD [ "up", "--enable-crons", "--addr", ":7777", "--ssh-addr", ":2222"]
6 changes: 4 additions & 2 deletions cmd/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/spf13/cobra"
)

var minimumDenoVersion = semver.MustParse("2.2.0")

func NewCmdDoctor() *cobra.Command {
cmd := &cobra.Command{
Use: "doctor",
Expand Down Expand Up @@ -69,8 +71,8 @@ func checkDenoVersion() (string, error) {
return "", err
}

if v.Major() < 2 {
return "", fmt.Errorf("deno version 2 or higher required")
if v.LessThan(minimumDenoVersion) {
return denoVersion, fmt.Errorf("deno version %s is too old, please upgrade to %s or newer", denoVersion, minimumDenoVersion)
}

return v.String(), nil
Expand Down
7 changes: 7 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ func NewCmdRun() *cobra.Command {
Use: "run <app> [args...]",
Short: "Run an app cli",
ValidArgsFunction: completeApp,
PreRunE: func(cmd *cobra.Command, args []string) error {
if _, err := checkDenoVersion(); err != nil {
return err
}

return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return cmd.Help()
Expand Down
8 changes: 8 additions & 0 deletions cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ func NewCmdUp() *cobra.Command {
return fmt.Errorf("domain cannot be empty")
}

if k.String("dir") == "" {
return fmt.Errorf("dir cannot be empty")
}

if _, err := checkDenoVersion(); err != nil {
return err
}

oldCronFlag, _ := cmd.Flags().GetBool("cron")
if oldCronFlag {
flags.enableCrons = true
Expand Down

0 comments on commit 894db34

Please sign in to comment.