diff --git a/.env b/.env index d9b7d1a..99415cf 100644 --- a/.env +++ b/.env @@ -1 +1,2 @@ -export PROJ=/home/esilva/Desktop/projetos/fax +registry=git.esilva.org +repo=esilva diff --git a/Dockerfile b/Dockerfile index 84b1b05..05c0dc7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ RUN apk --no-cache add bash zsh go make sqlite \ # Copy the source files -COPY ./src /frontend-src +COPY ./src/build /frontend # Add the entrypoint diff --git a/Makefile b/Makefile index fdbaa76..25ed3a8 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,27 @@ +include vars.mk +build = ./build/expensesweb +image = $(registry)/$(repo)/fax-frontend:$(tag) + build: - docker buildx build -t esilva-fax . + make -C src build_release_alpine + +build_image: build + podman buildx build -t $(image) . + +push_image: + podman push $(image) clean: - docker container rm esilva-fax-container-test --force + podman container rm esilva-fax-container-test --force attach: - docker exec -u root -it esilva-fax-container zsh + podman exec -u root -it esilva-fax-container zsh attach-test: - docker exec -u root -it esilva-fax-container-test zsh + podman exec -u root -it esilva-fax-container-test zsh test: clean - docker run \ + podman run \ --name esilva-fax-container-test \ -v ./data.db:/data.db \ -v ./src/config.yml:/etc/fax/config.yml \ diff --git a/Readme.md b/Readme.md index e74bbc5..15ca0d9 100644 --- a/Readme.md +++ b/Readme.md @@ -4,4 +4,4 @@ These faxes will be printed on a thermal printer. Pretty neat. # Docker You need to mount the `data.db` sqlit3 DB on `/data.db` in the container. -We should change this to a more appropriate location tho. +We should change this to a more appropriate location. diff --git a/container/start.sh b/container/start.sh index 3e811a4..6033946 100755 --- a/container/start.sh +++ b/container/start.sh @@ -1,16 +1,5 @@ #!/bin/sh set -e -if [ ! -d /frontend ]; then - export GOPROXY="https://goproxy.io" - cd /frontend-src - make clean - make build - mv build /frontend - cd .. - rm -r /frontend-src - ln -s /data.db /frontend/data.db -fi - cd /frontend exec ./frontend --config "/etc/fax/config.yml" diff --git a/src/Makefile b/src/Makefile index 688bad2..b9f275f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,6 +3,11 @@ build: clean go build -o build/frontend cp -r ./assets build +build_release_alpine: clean + mkdir build + CGO_ENABLED=1 GOOS=linux CC=musl-gcc go build -o build/frontend + cp -r ./assets build + clean: rm -rf ./build diff --git a/src/config.yml b/src/config.yml index 9e0925f..c3e0f83 100644 --- a/src/config.yml +++ b/src/config.yml @@ -4,6 +4,5 @@ network: port: "9099" usb: path: "/dev/usb/lp0" -fake: -dbpath: "./data.db" \ No newline at end of file +dbpath: "/data.db" diff --git a/src/config.yml.bk b/src/config.yml.bk new file mode 100644 index 0000000..a7c0c1c --- /dev/null +++ b/src/config.yml.bk @@ -0,0 +1,8 @@ +use: "network" +network: + host: "127.0.0.1" + port: "9099" +usb: + path: "/dev/usb/lp0" + +dbpath: "./data.db" \ No newline at end of file diff --git a/src/config/config.go b/src/config/config.go index b4eb061..14ac4ac 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -98,12 +98,18 @@ func (c *Configuration) loadConfiguration(data []byte) error { errStr := fmt.Sprintf("failed to read file: %s", err) return errors.New(errStr) } + + log.Println("Loaded configuration from: ", c.Path) } + log.Println("Config RAW: ", contents) + err := cparser.parseConfigFile(contents) if err != nil { return err } + log.Println("Parsed Config: ", c) + return nil } diff --git a/src/controllers/sendFax.go b/src/controllers/sendFax.go index dd7ea73..7c75b16 100644 --- a/src/controllers/sendFax.go +++ b/src/controllers/sendFax.go @@ -86,9 +86,6 @@ func SendFax(w http.ResponseWriter, r *http.Request) { return } - // REMOVE THIS YO - // time.Sleep(3 * time.Second) - // Create the model access var dacc models.DB m, err := models.NewModel(&dacc) @@ -122,11 +119,13 @@ func SendFax(w http.ResponseWriter, r *http.Request) { msg := signMessage(message.Text, user.Name, mDate.Format("2006-01-02 15:04:05")) _, err = sendRequestToPrinter(msg) if err != nil { + log.Fatalf("Failed to send message: %v\n", err) // When we have our history table working we can set the state of it here // log.Println("printer failed to process fax:", err) // w.Write([]byte("{\"state\":\"failed\"}")) // return } + log.Printf("Message sent: %v\n", msg) /* Another workflow to add here is to send the message into the DB right away diff --git a/src/models/models.go b/src/models/models.go index a1598e9..fe236f2 100644 --- a/src/models/models.go +++ b/src/models/models.go @@ -4,6 +4,7 @@ import ( "database/sql" "errors" "log" + "thermalFax/config" _ "github.com/mattn/go-sqlite3" @@ -43,5 +44,7 @@ func (d *DB) openDB() (*sql.DB, error) { return nil, err } + log.Println("opened DB on: ", cfg.DBPath) + return db, nil } diff --git a/vars.mk b/vars.mk new file mode 100644 index 0000000..6e8aeb4 --- /dev/null +++ b/vars.mk @@ -0,0 +1,8 @@ +include $(dir $(lastword $(MAKEFILE_LIST))).env + +REQUIRED_VARS := registry repo + +$(foreach v,$(REQUIRED_VARS),\ + $(if $(value $(v)),,$(error Variable '$(v)' is required but empty))) + +tag = v0.1.0