-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docker: Added the docker logic to be able to deploy it
Needed to change a lot of things basically to not have any 'ebiten' imports from the server because then it's really difficult to deploy it as 'ebiten' requires a lot of libs not installed by default on servers and it's quite obnoxious, so for this reason now there are 2 binaries and other changes related to that.
- Loading branch information
Showing
30 changed files
with
499 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/xescugc/go-flux" | ||
"github.com/xescugc/ltw/client" | ||
"github.com/xescugc/ltw/inputer" | ||
"github.com/xescugc/ltw/store" | ||
) | ||
|
||
var ( | ||
room string | ||
name string | ||
hostURL string | ||
screenW int | ||
screenH int | ||
|
||
clientCmd = &cobra.Command{ | ||
Use: "client", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
var err error | ||
|
||
d := flux.NewDispatcher() | ||
ad := client.NewActionDispatcher(d) | ||
|
||
s := store.NewStore(d) | ||
|
||
g := &client.Game{ | ||
Store: s, | ||
} | ||
|
||
i := inputer.NewEbiten() | ||
|
||
// TODO: Change this to pass the specific store needed instead of all the game object | ||
cs := client.NewCameraStore(d, s, screenW, screenH) | ||
g.Camera = cs | ||
g.Units, err = client.NewUnits(g) | ||
if err != nil { | ||
return fmt.Errorf("failed to initialize Units: %w", err) | ||
} | ||
|
||
g.Towers, err = client.NewTowers(g) | ||
if err != nil { | ||
return fmt.Errorf("failed to initialize Towers: %w", err) | ||
} | ||
|
||
g.HUD, err = client.NewHUDStore(d, i, g) | ||
if err != nil { | ||
return fmt.Errorf("failed to initialize HUDStore: %w", err) | ||
} | ||
|
||
l, err := client.NewLobbyStore(d, i, s, cs) | ||
if err != nil { | ||
return fmt.Errorf("failed to initialize LobbyStore: %w", err) | ||
} | ||
rs := client.NewRouterStore(d, g, l) | ||
ctx := context.Background() | ||
|
||
err = client.New(ctx, ad, rs, client.Options{ | ||
HostURL: hostURL, | ||
Room: room, | ||
Name: name, | ||
ScreenW: screenW, | ||
ScreenH: screenH, | ||
}) | ||
|
||
return err | ||
}, | ||
} | ||
) | ||
|
||
func init() { | ||
clientCmd.Flags().StringVar(&hostURL, "port", "localhost:5555", "The URL of the server") | ||
clientCmd.Flags().StringVar(&room, "room", "room", "The room name to join") | ||
clientCmd.Flags().StringVar(&name, "name", "john doe", "The name of the client") | ||
clientCmd.Flags().IntVar(&screenW, "screenw", 288, "The default width of the screen when not full screen") | ||
clientCmd.Flags().IntVar(&screenH, "screenh", 240, "The default height of the screen when not full screen") | ||
} | ||
|
||
func main() { | ||
if err := clientCmd.Execute(); err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"github.com/xescugc/go-flux" | ||
"github.com/xescugc/ltw/server" | ||
) | ||
|
||
var ( | ||
serverCmd = &cobra.Command{ | ||
Use: "server", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
d := flux.NewDispatcher() | ||
ad := server.NewActionDispatcher(d) | ||
rooms := server.NewRoomsStore(d) | ||
|
||
err := server.New(ad, rooms, server.Options{ | ||
Port: viper.GetString("port"), | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("server error: %w", err) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
) | ||
|
||
func init() { | ||
viper.AutomaticEnv() | ||
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) | ||
|
||
serverCmd.Flags().String("port", "5555", "The port in which the sever is open") | ||
viper.BindPFlag("port", serverCmd.Flags().Lookup("port")) | ||
} | ||
|
||
func main() { | ||
if err := serverCmd.Execute(); err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM golang:1.21 as builder | ||
|
||
WORKDIR /app | ||
|
||
COPY go.mod . | ||
COPY go.sum . | ||
|
||
RUN go mod download && go mod verify | ||
|
||
COPY . . | ||
|
||
RUN make wasm | ||
|
||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o maze-wars_app ./cmd/server/ | ||
ENTRYPOINT ["/app/maze-wars_app"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
FROM golang:1.21 as builder | ||
|
||
WORKDIR /app | ||
|
||
COPY go.mod . | ||
COPY go.sum . | ||
|
||
RUN go mod download && go mod verify | ||
|
||
COPY . . | ||
|
||
RUN make wasm | ||
|
||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o maze-wars_app ./cmd/server/ | ||
ENTRYPOINT ["/app/maze-wars_app"] | ||
|
||
# final stage | ||
|
||
FROM scratch | ||
COPY --from=builder /app/maze-wars_app /app/ | ||
ENTRYPOINT ["/app/maze-wars_app"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: "3" | ||
services: | ||
maze-wars: | ||
build: | ||
context: .. | ||
dockerfile: docker/Dockerfile.maze-wars.dev | ||
ports: | ||
#- '5555:5555' | ||
- '4000:4000' | ||
environment: | ||
- PORT=4000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
version: "3" | ||
services: | ||
maze-wars: | ||
volumes: | ||
- cache:/go | ||
networks: | ||
maze-wars: | ||
|
||
volumes: | ||
cache: | ||
attachments: | ||
driver: local | ||
|
||
networks: | ||
maze-wars: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
version: "3" | ||
services: | ||
nginx-proxy: | ||
image: nginxproxy/nginx-proxy:0.9.1 | ||
ports: | ||
- "80:80" | ||
volumes: | ||
- /var/run/docker.sock:/tmp/docker.sock:ro | ||
networks: | ||
maze-wars: | ||
|
||
maze-wars: | ||
build: | ||
context: .. | ||
dockerfile: docker/Dockerfile.maze-wars.prod | ||
expose: | ||
- 3000 | ||
environment: | ||
- PORT=3000 | ||
- VIRTUAL_HOST=maze-wars.com,www.maze-wars.com | ||
restart: on-failure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.