diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8a4bddc..6fd5375 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,6 +11,7 @@ jobs: build-server: name: Server runs-on: ubuntu-latest + container: golang:alpine steps: - uses: actions/checkout@v4 - uses: arduino/setup-task@v2 @@ -21,7 +22,7 @@ jobs: - run: task server:build - uses: actions/upload-artifact@v4 with: - path: server/build/server + path: server/build/botw-iss name: server retention-days: 3 diff --git a/server/.gitignore b/server/.gitignore index 796b96d..e8df3ac 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -1 +1,3 @@ /build +/dist +/.env diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000..753811b --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,30 @@ +# FROM golang:alpine AS build +# COPY . /build/ +# WORKDIR /build +# RUN ls -a +# RUN go mod tidy +# RUN go mod download +# RUN go build -o server +# + + +FROM ubuntu:latest +EXPOSE 80 +ENV APP_DIR=/opt/app +COPY ./dist $APP_DIR +# COPY --from=build /build/server $APP_DIR/server +RUN chmod +x $APP_DIR/server/server +# RUN chmod +x $APP_DIR/server/test.sh + +WORKDIR $APP_DIR + +ENV ISS_LOG=info \ + ISS_LOG_COLOR=false \ + ISS_MANUAL_PATH=/opt/iss/manual \ + ISS_LEGACY_PATH=/opt/iss/legacy + +# RUN stat /bin/sh +# RUN stat ./server/test.sh + +# ENTRYPOINT ["/usr/bin/dumb-init", "--"] +CMD ["./server/server"] diff --git a/server/Taskfile.yml b/server/Taskfile.yml index 890b7b3..c53299c 100644 --- a/server/Taskfile.yml +++ b/server/Taskfile.yml @@ -19,12 +19,13 @@ tasks: desc: Build the server executable cmds: - mkdir -p build - - go build -o build/server + - go build -o build/botw-iss dev: desc: Run the server in watch mode env: ISS_LOG: info + ISS_LOG_COLOR: "false" ISS_ADDRESS: https://pistonite.local:8000 ISS_CERT: ../cert ISS_MANUAL_PATH: ../manual/book @@ -33,4 +34,41 @@ tasks: cmds: - cargo watch -C . -s 'go run .' + ###################################### + # Container Local Testing + ###################################### + + pull: + desc: Pull the latest build artifact from GitHub + dotenv: + - .env + cmds: + - magnesis -o dist + + container: + desc: Build the Docker container + cmds: + - docker build -t pistonite/botw-iss . + + run: + desc: Run the Docker container + cmds: + - docker run -p 8000:80 -e ISS_ADDRESS=http://pistonite.local:80 pistonite/botw-iss:latest + + connect: + desc: Connect to the running Docker container + cmds: + - docker exec -it $(docker container ls -q --filter ancestor=pistonite/botw-iss) /bin/sh + + stop: + desc: Stop the running Docker container + cmds: + - docker stop $(docker ps ls -q -a --filter ancestor=pistonite/botw-iss) + + clean: + desc: Clean the containers + cmds: + - docker container prune + - docker image rm $(docker image ls -q -a --filter reference=pistonite/botw-iss) + diff --git a/server/main.go b/server/main.go index dcb597d..4d7d432 100644 --- a/server/main.go +++ b/server/main.go @@ -4,25 +4,24 @@ import ( "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/log" "github.com/gofiber/fiber/v2/middleware/logger" - // "github.com/gofiber/fiber/v2/utils" + // // "github.com/gofiber/fiber/v2/utils" ) func main() { DrawStart() - + env := ParseEnvConfig() log.SetLevel(env.LogLevel) log.Debugf("Set Log Level to: %s\n", env.LogLevel) - + // Create the app app := fiber.New() - app.Use(logger.New(logger.Config{ DisableColors: !env.LogColor, })) - + DrawSection("Asset Paths") - + DrawLine("Manual", env.ManualPath) app.Get("/manual", func(ctx *fiber.Ctx) error { return ctx.Redirect("/manual/index.html") @@ -31,13 +30,13 @@ func main() { Compress: true, MaxAge: 3600, }) - + DrawLine("Legacy", env.LegacyPath) app.Static("/legacy", env.LegacyPath, fiber.Static{ Compress: true, MaxAge: 3600, }) - + DrawEnd() addr := env.Address