From e64e10f79b40db17a1cb24d9dd7ce7154f159f16 Mon Sep 17 00:00:00 2001 From: toshinari123 Date: Tue, 5 Mar 2024 12:14:11 +0800 Subject: [PATCH 01/10] Create cobra command --- cmd/pageship/app/generate.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 cmd/pageship/app/generate.go diff --git a/cmd/pageship/app/generate.go b/cmd/pageship/app/generate.go new file mode 100644 index 0000000..3067433 --- /dev/null +++ b/cmd/pageship/app/generate.go @@ -0,0 +1,31 @@ +package app + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +func init() { + rootCmd.AddCommand(generateCmd) + generateCmd.AddCommand(generateDockerfileCmd) +} + +var generateCmd = &cobra.Command{ + Use: "generate [command]", + Short: "Generate files", + Args: cobra.NoArgs, //if unknown command, will return error just like main pageship command + RunE: func(cmd *cobra.Command, args []string) error { + cmd.Help() //show help if no subcommand supplied + return nil + }, +} + +var generateDockerfileCmd = &cobra.Command{ + Use: "dockerfile", + Short: "Generate dockerfile", + RunE: func(cmd *cobra.Command, args []string) error { + fmt.Println("buh") + return nil + }, +} From f00e4e345e672784a045bbd4d595c34d9a60a6a3 Mon Sep 17 00:00:00 2001 From: toshinari123 Date: Tue, 5 Mar 2024 15:22:17 +0800 Subject: [PATCH 02/10] Implement generateDockerfileCmd --- cmd/pageship/app/generate.go | 43 ++++++++++++++++++++++++++++++++++-- cmd/pageship/main.go | 3 +++ go.mod | 4 ++-- go.sum | 1 - 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/cmd/pageship/app/generate.go b/cmd/pageship/app/generate.go index 3067433..151c8e4 100644 --- a/cmd/pageship/app/generate.go +++ b/cmd/pageship/app/generate.go @@ -1,7 +1,7 @@ package app import ( - "fmt" + "os" "github.com/spf13/cobra" ) @@ -21,11 +21,50 @@ var generateCmd = &cobra.Command{ }, } +var Version = "dev" +var dockerfileFrom = "FROM ghcr.io/oursky/pageship:v" +var dockerfileExpose = "EXPOSE 8000" +var dockerfileCopy = "COPY . /var/pageship" +var dockerfileInstructions = ` +# INSTRUCTIONS: +# 1. install docker (if it is not installed yet) +# 2. open a terminal and navigate to your static page folder +# 3. run in terminal: +# pageship generate dockerfile +# 4. build the image: +# docker build -t IMAGETAG . +# 5. run the container: +# docker run -d --name CONTAINERNAME -p PORT:8000 IMAGETAG +# 6. visit in browser: +# localhost:PORT` + var generateDockerfileCmd = &cobra.Command{ Use: "dockerfile", Short: "Generate dockerfile", RunE: func(cmd *cobra.Command, args []string) error { - fmt.Println("buh") + f, err := os.Create("dockerfile") + if err != nil { + return err + } + defer f.Close() + + Info("generating dockerfile...") + _, err = f.Write([]byte(dockerfileFrom + Version + "\n")) + if err != nil { + return err + } + _, err = f.Write([]byte(dockerfileExpose + "\n")) + if err != nil { + return err + } + _, err = f.Write([]byte(dockerfileCopy + "\n")) + if err != nil { + return err + } + _, err = f.Write([]byte(dockerfileInstructions + "\n")) + if err != nil { + return err + } return nil }, } diff --git a/cmd/pageship/main.go b/cmd/pageship/main.go index 62ee8a0..360a603 100644 --- a/cmd/pageship/main.go +++ b/cmd/pageship/main.go @@ -6,7 +6,10 @@ import ( "github.com/oursky/pageship/cmd/pageship/app" ) +var version = "dev" //https://goreleaser.com/cookbooks/using-main.version/ + func main() { + app.Version = version if err := app.Execute(); err != nil { app.Error("%s", err) os.Exit(1) diff --git a/go.mod b/go.mod index e3a4e30..45da941 100644 --- a/go.mod +++ b/go.mod @@ -4,10 +4,12 @@ go 1.20 require ( github.com/MicahParks/keyfunc/v2 v2.1.0 + github.com/andybalholm/brotli v1.1.0 github.com/caddyserver/certmagic v0.17.2 github.com/carlmjohnson/versioninfo v0.22.4 github.com/dustin/go-humanize v1.0.1 github.com/fatih/color v1.15.0 + github.com/foxcpp/go-mockdns v1.0.0 github.com/fsnotify/fsnotify v1.6.0 github.com/go-chi/chi/v5 v5.0.8 github.com/go-playground/validator/v10 v10.14.0 @@ -50,7 +52,6 @@ require ( github.com/Azure/go-autorest v14.2.0+incompatible // indirect github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 // indirect - github.com/andybalholm/brotli v1.1.0 // indirect github.com/aws/aws-sdk-go v1.44.314 // indirect github.com/aws/aws-sdk-go-v2 v1.20.0 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.11 // indirect @@ -73,7 +74,6 @@ require ( github.com/aws/smithy-go v1.14.0 // indirect github.com/chzyer/readline v1.5.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/foxcpp/go-mockdns v1.0.0 // indirect github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect diff --git a/go.sum b/go.sum index ad3070b..d1ba5d6 100644 --- a/go.sum +++ b/go.sum @@ -227,7 +227,6 @@ github.com/aws/smithy-go v1.14.0 h1:+X90sB94fizKjDmwb4vyl2cTTPXTE5E2G/1mjByb0io= github.com/aws/smithy-go v1.14.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= -github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= From 5183582bbe5bc9b993ef77afb0df33a88e20456b Mon Sep 17 00:00:00 2001 From: toshinari123 Date: Tue, 5 Mar 2024 16:43:01 +0800 Subject: [PATCH 03/10] Improve generate implementation --- cmd/pageship/app/generate.go | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/cmd/pageship/app/generate.go b/cmd/pageship/app/generate.go index 151c8e4..c45d0e5 100644 --- a/cmd/pageship/app/generate.go +++ b/cmd/pageship/app/generate.go @@ -2,6 +2,7 @@ package app import ( "os" + "strings" "github.com/spf13/cobra" ) @@ -35,9 +36,14 @@ var dockerfileInstructions = ` # docker build -t IMAGETAG . # 5. run the container: # docker run -d --name CONTAINERNAME -p PORT:8000 IMAGETAG -# 6. visit in browser: +# 6. visit in browser (URL): # localhost:PORT` +func generateContent() string { + dockerfileFromVersion := dockerfileFrom + Version + return strings.Join([]string{dockerfileFromVersion, dockerfileExpose, dockerfileCopy, dockerfileInstructions}, "\n") +} + var generateDockerfileCmd = &cobra.Command{ Use: "dockerfile", Short: "Generate dockerfile", @@ -49,19 +55,7 @@ var generateDockerfileCmd = &cobra.Command{ defer f.Close() Info("generating dockerfile...") - _, err = f.Write([]byte(dockerfileFrom + Version + "\n")) - if err != nil { - return err - } - _, err = f.Write([]byte(dockerfileExpose + "\n")) - if err != nil { - return err - } - _, err = f.Write([]byte(dockerfileCopy + "\n")) - if err != nil { - return err - } - _, err = f.Write([]byte(dockerfileInstructions + "\n")) + _, err = f.Write([]byte(generateContent())) if err != nil { return err } From de0416f1cf010611636bd4f7c7770905040850a9 Mon Sep 17 00:00:00 2001 From: toshinari123 Date: Tue, 5 Mar 2024 16:43:15 +0800 Subject: [PATCH 04/10] Test generate dockerfile --- cmd/pageship/app/generate_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 cmd/pageship/app/generate_test.go diff --git a/cmd/pageship/app/generate_test.go b/cmd/pageship/app/generate_test.go new file mode 100644 index 0000000..aa1974a --- /dev/null +++ b/cmd/pageship/app/generate_test.go @@ -0,0 +1,26 @@ +package app + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGenerate(t *testing.T) { + Version = "1.2.3" + assert.Equal(t, `FROM ghcr.io/oursky/pageship:v1.2.3 +EXPOSE 8000 +COPY . /var/pageship + +# INSTRUCTIONS: +# 1. install docker (if it is not installed yet) +# 2. open a terminal and navigate to your static page folder +# 3. run in terminal: +# pageship generate dockerfile +# 4. build the image: +# docker build -t IMAGETAG . +# 5. run the container: +# docker run -d --name CONTAINERNAME -p PORT:8000 IMAGETAG +# 6. visit in browser (URL): +# localhost:PORT`, generateContent()) +} From ee05177045df94dcf58b83163390ba41adf13b76 Mon Sep 17 00:00:00 2001 From: toshinari123 Date: Mon, 11 Mar 2024 12:20:17 +0800 Subject: [PATCH 05/10] Add read pageship.toml --- cmd/pageship/app/generate.go | 36 ++++++++++++++++++++++--------- cmd/pageship/app/generate_test.go | 4 +++- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/cmd/pageship/app/generate.go b/cmd/pageship/app/generate.go index c45d0e5..0f5f2fb 100644 --- a/cmd/pageship/app/generate.go +++ b/cmd/pageship/app/generate.go @@ -1,9 +1,11 @@ package app import ( + "fmt" "os" - "strings" + "github.com/oursky/pageship/internal/config" + "github.com/pelletier/go-toml/v2" "github.com/spf13/cobra" ) @@ -23,13 +25,13 @@ var generateCmd = &cobra.Command{ } var Version = "dev" -var dockerfileFrom = "FROM ghcr.io/oursky/pageship:v" -var dockerfileExpose = "EXPOSE 8000" -var dockerfileCopy = "COPY . /var/pageship" -var dockerfileInstructions = ` +var dockerfileTemplate = `FROM ghcr.io/oursky/pageship:v%s +EXPOSE 8000 +COPY %s /var/pageship + # INSTRUCTIONS: # 1. install docker (if it is not installed yet) -# 2. open a terminal and navigate to your static page folder +# 2. open a terminal and navigate to folder containing pageship.toml # 3. run in terminal: # pageship generate dockerfile # 4. build the image: @@ -39,9 +41,19 @@ var dockerfileInstructions = ` # 6. visit in browser (URL): # localhost:PORT` -func generateContent() string { - dockerfileFromVersion := dockerfileFrom + Version - return strings.Join([]string{dockerfileFromVersion, dockerfileExpose, dockerfileCopy, dockerfileInstructions}, "\n") +func generateContent() (string, error) { + pageshiptoml, err := os.ReadFile("./pageship.toml") + if err != nil { + return "", err + } + + var cfg config.Config + err = toml.Unmarshal([]byte(pageshiptoml), &cfg) + if err != nil { + return "", err + } + + return fmt.Sprintf(dockerfileTemplate, Version, cfg.Site.Public), nil } var generateDockerfileCmd = &cobra.Command{ @@ -55,7 +67,11 @@ var generateDockerfileCmd = &cobra.Command{ defer f.Close() Info("generating dockerfile...") - _, err = f.Write([]byte(generateContent())) + s, err := generateContent() + if err != nil { + return err + } + _, err = f.Write([]byte(s)) if err != nil { return err } diff --git a/cmd/pageship/app/generate_test.go b/cmd/pageship/app/generate_test.go index aa1974a..c7ddfa6 100644 --- a/cmd/pageship/app/generate_test.go +++ b/cmd/pageship/app/generate_test.go @@ -8,6 +8,8 @@ import ( func TestGenerate(t *testing.T) { Version = "1.2.3" + s, err := generateContent() + assert.Empty(t, err) assert.Equal(t, `FROM ghcr.io/oursky/pageship:v1.2.3 EXPOSE 8000 COPY . /var/pageship @@ -22,5 +24,5 @@ COPY . /var/pageship # 5. run the container: # docker run -d --name CONTAINERNAME -p PORT:8000 IMAGETAG # 6. visit in browser (URL): -# localhost:PORT`, generateContent()) +# localhost:PORT`, s) } From 956498ac3a4b1d03176a0d491c233e815921e822 Mon Sep 17 00:00:00 2001 From: toshinari123 Date: Mon, 11 Mar 2024 12:45:18 +0800 Subject: [PATCH 06/10] Test updated implementation --- cmd/pageship/app/generate.go | 7 +++--- cmd/pageship/app/generate_test.go | 33 ++++++++++++++++++++++--- cmd/pageship/app/testdata/pageship.toml | 22 +++++++++++++++++ 3 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 cmd/pageship/app/testdata/pageship.toml diff --git a/cmd/pageship/app/generate.go b/cmd/pageship/app/generate.go index 0f5f2fb..53fdc20 100644 --- a/cmd/pageship/app/generate.go +++ b/cmd/pageship/app/generate.go @@ -2,6 +2,7 @@ package app import ( "fmt" + "io/fs" "os" "github.com/oursky/pageship/internal/config" @@ -41,8 +42,8 @@ COPY %s /var/pageship # 6. visit in browser (URL): # localhost:PORT` -func generateContent() (string, error) { - pageshiptoml, err := os.ReadFile("./pageship.toml") +func generateContent(myfs fs.FS) (string, error) { + pageshiptoml, err := fs.ReadFile(myfs, "./pageship.toml") if err != nil { return "", err } @@ -67,7 +68,7 @@ var generateDockerfileCmd = &cobra.Command{ defer f.Close() Info("generating dockerfile...") - s, err := generateContent() + s, err := generateContent(os.DirFS(".")) if err != nil { return err } diff --git a/cmd/pageship/app/generate_test.go b/cmd/pageship/app/generate_test.go index c7ddfa6..e97e9ca 100644 --- a/cmd/pageship/app/generate_test.go +++ b/cmd/pageship/app/generate_test.go @@ -1,22 +1,49 @@ package app import ( + "embed" + "fmt" + "io/fs" + "path" "testing" "github.com/stretchr/testify/assert" ) +//go:embed testdata +var testfs embed.FS + +type FSAdapter struct { + embed.FS + subdir string +} + +func (fa FSAdapter) Open(s string) (fs.File, error) { + return fa.FS.Open(path.Join(fa.subdir, s)) +} + +func (fa FSAdapter) ReadFile(s string) ([]byte, error) { + return fa.FS.ReadFile(path.Join(fa.subdir, s)) +} + func TestGenerate(t *testing.T) { Version = "1.2.3" - s, err := generateContent() + fsa := FSAdapter{testfs, "testdata"} + + fs.WalkDir(fsa, ".", func(path string, d fs.DirEntry, err error) error { + fmt.Println(path) + return nil + }) + + s, err := generateContent(fsa) assert.Empty(t, err) assert.Equal(t, `FROM ghcr.io/oursky/pageship:v1.2.3 EXPOSE 8000 -COPY . /var/pageship +COPY dist /var/pageship # INSTRUCTIONS: # 1. install docker (if it is not installed yet) -# 2. open a terminal and navigate to your static page folder +# 2. open a terminal and navigate to folder containing pageship.toml # 3. run in terminal: # pageship generate dockerfile # 4. build the image: diff --git a/cmd/pageship/app/testdata/pageship.toml b/cmd/pageship/app/testdata/pageship.toml new file mode 100644 index 0000000..a424e2b --- /dev/null +++ b/cmd/pageship/app/testdata/pageship.toml @@ -0,0 +1,22 @@ +[app] +id = "pageship-test" + +team = [] + +[app.deployments] +# ttl = "24h" +# access = [] + +[[app.sites]] +name = "main" + +# [[app.sites]] +# name = "dev" + +# [[app.sites]] +# name = "staging" + +[site] +public = "dist" + +# access = [] From 1f465e7670b85e98e17d6d38db95e45e26987bf8 Mon Sep 17 00:00:00 2001 From: toshinari123 Date: Mon, 11 Mar 2024 13:37:22 +0800 Subject: [PATCH 07/10] Fix path --- cmd/pageship/app/generate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/pageship/app/generate.go b/cmd/pageship/app/generate.go index 53fdc20..fcb44b4 100644 --- a/cmd/pageship/app/generate.go +++ b/cmd/pageship/app/generate.go @@ -43,7 +43,7 @@ COPY %s /var/pageship # localhost:PORT` func generateContent(myfs fs.FS) (string, error) { - pageshiptoml, err := fs.ReadFile(myfs, "./pageship.toml") + pageshiptoml, err := fs.ReadFile(myfs, "pageship.toml") if err != nil { return "", err } From f596cfdd07c4ec37038fb2609fb5f49e1796a8f1 Mon Sep 17 00:00:00 2001 From: toshinari123 Date: Mon, 11 Mar 2024 14:14:21 +0800 Subject: [PATCH 08/10] Use template and loadConfig --- cmd/pageship/app/generate.go | 47 ++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/cmd/pageship/app/generate.go b/cmd/pageship/app/generate.go index fcb44b4..fe3920b 100644 --- a/cmd/pageship/app/generate.go +++ b/cmd/pageship/app/generate.go @@ -1,12 +1,10 @@ package app import ( - "fmt" - "io/fs" + "bytes" "os" + "text/template" - "github.com/oursky/pageship/internal/config" - "github.com/pelletier/go-toml/v2" "github.com/spf13/cobra" ) @@ -25,10 +23,17 @@ var generateCmd = &cobra.Command{ }, } -var Version = "dev" -var dockerfileTemplate = `FROM ghcr.io/oursky/pageship:v%s +var Version = "" + +type dockerfileTemplate struct { + Version string + PublicPath string +} + +var dockerfileTemplateString = `FROM ghcr.io/oursky/pageship:{{if .Version}}v{{.Version}}{{else}}dev{{end}} EXPOSE 8000 -COPY %s /var/pageship +COPY ./pageship.toml /var/pageship +COPY ./{{.PublicPath}} /var/pageship/{{.PublicPath}} # INSTRUCTIONS: # 1. install docker (if it is not installed yet) @@ -42,33 +47,43 @@ COPY %s /var/pageship # 6. visit in browser (URL): # localhost:PORT` -func generateContent(myfs fs.FS) (string, error) { - pageshiptoml, err := fs.ReadFile(myfs, "pageship.toml") +func generateContent() (string, error) { + cfg, err := loadConfig(".") if err != nil { return "", err } - var cfg config.Config - err = toml.Unmarshal([]byte(pageshiptoml), &cfg) + df := dockerfileTemplate{Version, cfg.Site.Public} + + tmpl, err := template.New("Dockerfile").Parse(dockerfileTemplateString) if err != nil { return "", err } - return fmt.Sprintf(dockerfileTemplate, Version, cfg.Site.Public), nil + var b bytes.Buffer + err = tmpl.Execute(&b, df) + if err != nil { + return "", err + } + return b.String(), nil } var generateDockerfileCmd = &cobra.Command{ Use: "dockerfile", - Short: "Generate dockerfile", + Short: "Generate Dockerfile", RunE: func(cmd *cobra.Command, args []string) error { - f, err := os.Create("dockerfile") + if Version == "dev" { + Version = "" + } + + f, err := os.Create("Dockerfile") if err != nil { return err } defer f.Close() - Info("generating dockerfile...") - s, err := generateContent(os.DirFS(".")) + Info("generating Dockerfile...") + s, err := generateContent() if err != nil { return err } From 3aa8a4d3a781883c967b790c73cfa0d27ec4e0b0 Mon Sep 17 00:00:00 2001 From: toshinari123 Date: Mon, 11 Mar 2024 14:54:51 +0800 Subject: [PATCH 09/10] Test using mapfs --- cmd/pageship/app/generate.go | 27 ++++++++++--- cmd/pageship/app/generate_test.go | 51 +++++++++++++------------ cmd/pageship/app/testdata/pageship.toml | 22 ----------- 3 files changed, 47 insertions(+), 53 deletions(-) delete mode 100644 cmd/pageship/app/testdata/pageship.toml diff --git a/cmd/pageship/app/generate.go b/cmd/pageship/app/generate.go index fe3920b..fa4b49d 100644 --- a/cmd/pageship/app/generate.go +++ b/cmd/pageship/app/generate.go @@ -2,9 +2,11 @@ package app import ( "bytes" + "io/fs" "os" "text/template" + "github.com/oursky/pageship/internal/config" "github.com/spf13/cobra" ) @@ -25,7 +27,7 @@ var generateCmd = &cobra.Command{ var Version = "" -type dockerfileTemplate struct { +type DockerfileTemplate struct { Version string PublicPath string } @@ -47,13 +49,26 @@ COPY ./{{.PublicPath}} /var/pageship/{{.PublicPath}} # 6. visit in browser (URL): # localhost:PORT` -func generateContent() (string, error) { - cfg, err := loadConfig(".") - if err != nil { - return "", err +func generateContent(testfs ...fs.FS) (string, error) { + var cfg config.Config + if len(testfs) > 0 { //for testing, copied from utils.go + loader := config.NewLoader(config.SiteConfigName) + + cfg = config.DefaultConfig() + if err := loader.Load(testfs[0], &cfg); err != nil { + return "", err + } + + cfg.SetDefaults() + } else { + config, err := loadConfig(".") + cfg = *config + if err != nil { + return "", err + } } - df := dockerfileTemplate{Version, cfg.Site.Public} + df := DockerfileTemplate{Version: Version, PublicPath: cfg.Site.Public} tmpl, err := template.New("Dockerfile").Parse(dockerfileTemplateString) if err != nil { diff --git a/cmd/pageship/app/generate_test.go b/cmd/pageship/app/generate_test.go index e97e9ca..83544d8 100644 --- a/cmd/pageship/app/generate_test.go +++ b/cmd/pageship/app/generate_test.go @@ -1,45 +1,46 @@ package app import ( - "embed" - "fmt" - "io/fs" - "path" "testing" + "testing/fstest" "github.com/stretchr/testify/assert" ) -//go:embed testdata -var testfs embed.FS +func TestGenerate(t *testing.T) { + Version = "1.2.3" -type FSAdapter struct { - embed.FS - subdir string -} + var testFiles fstest.MapFS = make(map[string]*fstest.MapFile) + testFiles["pageship.toml"] = &fstest.MapFile{Data: []byte(`[app] +id = "pageship-test" -func (fa FSAdapter) Open(s string) (fs.File, error) { - return fa.FS.Open(path.Join(fa.subdir, s)) -} +team = [] -func (fa FSAdapter) ReadFile(s string) ([]byte, error) { - return fa.FS.ReadFile(path.Join(fa.subdir, s)) -} +[app.deployments] +# ttl = "24h" +# access = [] -func TestGenerate(t *testing.T) { - Version = "1.2.3" - fsa := FSAdapter{testfs, "testdata"} +[[app.sites]] +name = "main" + +# [[app.sites]] +# name = "dev" + +# [[app.sites]] +# name = "staging" + +[site] +public = "dist" - fs.WalkDir(fsa, ".", func(path string, d fs.DirEntry, err error) error { - fmt.Println(path) - return nil - }) +# access = [] +`)} - s, err := generateContent(fsa) + s, err := generateContent(testFiles) assert.Empty(t, err) assert.Equal(t, `FROM ghcr.io/oursky/pageship:v1.2.3 EXPOSE 8000 -COPY dist /var/pageship +COPY ./pageship.toml /var/pageship +COPY ./dist /var/pageship/dist # INSTRUCTIONS: # 1. install docker (if it is not installed yet) diff --git a/cmd/pageship/app/testdata/pageship.toml b/cmd/pageship/app/testdata/pageship.toml deleted file mode 100644 index a424e2b..0000000 --- a/cmd/pageship/app/testdata/pageship.toml +++ /dev/null @@ -1,22 +0,0 @@ -[app] -id = "pageship-test" - -team = [] - -[app.deployments] -# ttl = "24h" -# access = [] - -[[app.sites]] -name = "main" - -# [[app.sites]] -# name = "dev" - -# [[app.sites]] -# name = "staging" - -[site] -public = "dist" - -# access = [] From f97cf81c8514042394b910f42cd093681c5ffeaa Mon Sep 17 00:00:00 2001 From: toshinari123 Date: Tue, 12 Mar 2024 11:37:28 +0800 Subject: [PATCH 10/10] Use maybenil FS input --- cmd/pageship/app/generate.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/pageship/app/generate.go b/cmd/pageship/app/generate.go index fa4b49d..770d1c2 100644 --- a/cmd/pageship/app/generate.go +++ b/cmd/pageship/app/generate.go @@ -49,13 +49,13 @@ COPY ./{{.PublicPath}} /var/pageship/{{.PublicPath}} # 6. visit in browser (URL): # localhost:PORT` -func generateContent(testfs ...fs.FS) (string, error) { +func generateContent(testfs fs.FS) (string, error) { var cfg config.Config - if len(testfs) > 0 { //for testing, copied from utils.go + if testfs != nil { //for testing, copied from utils.go loader := config.NewLoader(config.SiteConfigName) cfg = config.DefaultConfig() - if err := loader.Load(testfs[0], &cfg); err != nil { + if err := loader.Load(testfs, &cfg); err != nil { return "", err } @@ -98,7 +98,7 @@ var generateDockerfileCmd = &cobra.Command{ defer f.Close() Info("generating Dockerfile...") - s, err := generateContent() + s, err := generateContent(nil) if err != nil { return err }