Skip to content

Commit

Permalink
Implement generateDockerfileCmd
Browse files Browse the repository at this point in the history
  • Loading branch information
toshinari123 committed Mar 5, 2024
1 parent e64e10f commit dfc0f21
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
42 changes: 40 additions & 2 deletions cmd/pageship/app/generate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package app

import (
"fmt"
"os"

"github.com/spf13/cobra"
)
Expand All @@ -21,11 +21,49 @@ var generateCmd = &cobra.Command{
},
}

var Version = "dev"
var dockerfileFrom = "FROM ghcr.io/oursky/pageship:git-"
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()

_, 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
},
}
3 changes: 3 additions & 0 deletions cmd/pageship/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit dfc0f21

Please sign in to comment.