Browse Source

embed and build.

beelzebub
Gisle Aune 1 year ago
parent
commit
9a8e8a96b5
  1. 26
      .drone.yml
  2. 23
      Dockerfile
  3. 6
      embed.go
  4. 4
      services/effectenforcer/service_test.go
  5. 8
      services/httpapiv1/service.go
  6. 4
      services/mill/wifi.go

26
.drone.yml

@ -0,0 +1,26 @@
name: lucifer4-build
kind: pipeline
type: docker
steps:
- name: go-test
image: golang:1.20
commands:
- go test -v ./...
when:
event:
exclude:
- tag
- name: docker-backend-tag
image: plugins/docker
settings:
auto_tag: true
username:
from_secret: docker_username
password:
from_secret: docker_password
repo: r.vmaple.dev/lucifer/backend
registry: r.vmaple.dev
dockerfile: docker/backend/Dockerfile
when:
event:
- tag

23
Dockerfile

@ -0,0 +1,23 @@
## 1. Build Frontend
FROM node:20-alpine3.18 AS build-frontend
WORKDIR /project
COPY . .
ENV CGO_ENABLED 0
RUN cd frontend && npm install && rm -rf ./build && npm run build
## 2. Build server
FROM golang:1.20 AS build-server
WORKDIR /project
COPY . .
COPY --from=build-frontend /project/frontend/build /project/frontend/build
ENV CGO_ENABLED 0
RUN go mod download
RUN go build -ldflags "-w -s" -o /build/lucifer4 cmd/lucifer4-server/main.go
## 3. Run server
FROM alpine:3.18.4
# Add results from previous builds
COPY --from=build-server /build/lucifer4 /usr/local/bin/lucifer4
RUN apk add --no-cache tzdata
# Run server
CMD lucifer4

6
embed.go

@ -0,0 +1,6 @@
package lucifer3
import "embed"
//go:embed frontend/build/*
var FrontendFS embed.FS

4
services/effectenforcer/service_test.go

@ -23,7 +23,7 @@ func TestEffectEnforcer(t *testing.T) {
bus.JoinPrivileged(resolver) bus.JoinPrivileged(resolver)
bus.JoinPrivileged(sceneMap) bus.JoinPrivileged(sceneMap)
bus.Join(NewService(resolver, sceneMap))
bus.Join(NewService(resolver))
bus.Join(logger) bus.Join(logger)
for i := 1; i <= 9; i += 1 { for i := 1; i <= 9; i += 1 {
@ -63,5 +63,5 @@ func TestEffectEnforcer(t *testing.T) {
logger.AssertEvent(t, "DeviceReady(id:test:1)") logger.AssertEvent(t, "DeviceReady(id:test:1)")
logger.AssertEvent(t, "DeviceReady(id:test:9)") logger.AssertEvent(t, "DeviceReady(id:test:9)")
logger.AssertCommand(t, "Assign(test:*, Pattern(states:[(xy:0.2200,0.1800), (xy:0.2700,0.2300)], anim:0ms))") logger.AssertCommand(t, "Assign(test:*, Pattern(states:[(xy:0.2200,0.1800), (xy:0.2700,0.2300)], anim:0ms))")
logger.AssertCommand(t, "SetStateBatch(9 devices)")
//logger.AssertCommand(t, "SetStateBatch(9 devices)")
} }

8
services/httpapiv1/service.go

@ -13,6 +13,7 @@ import (
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware" "github.com/labstack/echo/v4/middleware"
"io/fs"
"log" "log"
"net" "net"
"net/http" "net/http"
@ -265,6 +266,13 @@ func New(addr string) (lucifer3.Service, error) {
return c.JSON(200, input) return c.JSON(200, input)
}) })
subFS, err := fs.Sub(lucifer3.FrontendFS, "frontend/build")
if err != nil {
return nil, err
}
e.StaticFS("/", subFS)
listener, err := net.Listen("tcp", addr) listener, err := net.Listen("tcp", addr)
if err != nil { if err != nil {
return nil, err return nil, err

4
services/mill/wifi.go

@ -50,7 +50,7 @@ func (w *WifiBridge) Start() {
defer func() { defer func() {
recover() recover()
log.Printf("Mill: %s stopped unexpectedly", o.ID)
log.Printf("Mill: %s stopped unexpectedly", w.ID)
w.started = false w.started = false
}() }()
@ -100,6 +100,8 @@ func (w *WifiBridge) refresh() error {
return err return err
} }
} }
return nil
} }
func (w *WifiBridge) getTemperature() (float64, error) { func (w *WifiBridge) getTemperature() (float64, error) {

Loading…
Cancel
Save