Skip to content

Commit

Permalink
Upgrade to go1.16, use go:embed for bundling assets (evcc-io#555)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Feb 21, 2021
1 parent b2ddbd4 commit 3bb58e5
Show file tree
Hide file tree
Showing 36 changed files with 471 additions and 15,602 deletions.
44 changes: 37 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ jobs:
- name: Setup
uses: actions/setup-go@v2
with:
go-version: ^1.14
go-version: ^1.16
id: go

- uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
**/node_modules
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ hashFiles('**/package-lock.json') }}
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
Expand All @@ -34,7 +33,7 @@ jobs:
run: make install

- name: Assets & UI
run: make npm assets
run: make assets

- name: Porcelain
run: |
Expand All @@ -52,13 +51,40 @@ jobs:
- name: Test
run: make test

build-ui:
name: Build UI
runs-on: ubuntu-latest

steps:
- uses: actions/cache@v2
with:
path: |
**/node_modules
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Checkout
uses: actions/checkout@v2

- name: Install tools
run: make install-ui

- name: Assets & UI
run: make ui

- name: Porcelain
run: |
test -z "$(git status --porcelain)" || (git status; git diff; false)
dockerlatest:
name: Publish :latest
if: |
startsWith(github.ref, 'refs/heads/master')
&& ! contains(github.head_ref, 'refs/heads/chore/')
needs: build
needs:
- build
- build-ui
runs-on: ubuntu-latest

steps:
Expand All @@ -83,7 +109,9 @@ jobs:
dockerrelease:
name: Publish :release
if: "startsWith(github.ref, 'refs/tags')"
needs: build
needs:
- build
- build-ui
runs-on: ubuntu-latest

steps:
Expand All @@ -109,7 +137,9 @@ jobs:
release:
name: Release
if: "startsWith(github.ref, 'refs/tags')"
needs: build
needs:
- build
- build-ui
runs-on: ubuntu-latest

steps:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ evcc_*
flags/*
buildflags/*
linux-*.Dockerfile
dist
node_modules
3 changes: 0 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ release:
github:
owner: andig
name: evcc
# before:
# hooks:
# - make npm assets
extra_files:
- glob: evcc_*.image.gz
- glob: evcc_*.rootfs.gz
Expand Down
49 changes: 30 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,50 @@
#
# STEP 1 build executable binary
#
# STEP 1 build ui
FROM node:14-alpine as node

FROM golang:1.14-alpine as builder
RUN apk update && apk add --no-cache make

WORKDIR /build

# install node tools
COPY Makefile .
COPY package*.json ./
RUN make install-ui

# build ui
COPY assets assets
COPY vue.config.js vue.config.js
RUN make clean ui


# STEP 2 build executable binary
FROM golang:1.16-alpine as builder

# Install git + SSL ca certificates.
# Git is required for fetching the dependencies.
# Ca-certificates is required to call HTTPS endpoints.
RUN apk update && apk add --no-cache git ca-certificates tzdata alpine-sdk npm && update-ca-certificates
RUN apk update && apk add --no-cache git ca-certificates tzdata alpine-sdk && update-ca-certificates

WORKDIR /build

# cache modules
# install go tools and cache modules
COPY Makefile .
COPY go.mod .
COPY go.sum .
RUN go mod download

# install go and node tools
COPY Makefile .
COPY package*.json ./
RUN make install
RUN go mod download

# build ui
COPY assets assets
COPY vue.config.js vue.config.js
RUN make clean npm

# prepare
COPY . .
RUN make assets

# copy ui
COPY --from=node /build/dist /build/dist

# build
RUN make build

#
# STEP 2 build a small image including module support
#

# STEP 3 build a small image including module support
FROM alpine:3.12

WORKDIR /evcc
Expand Down
36 changes: 19 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: default clean install lint test assets build binaries test-release release
.PHONY: publish-testing publish-latest publish-images
.PHONY: image image-rootfs image-update
.PHONY: default all clean install install-ui ui assets lint test build test-release release
.PHONY: docker publish-testing publish-latest publish-images
.PHONY: prepare-image image-rootfs image-update

# build vars
TAG_NAME := $(shell test -d .git && git describe --abbrev=0 --tags)
Expand All @@ -13,24 +13,33 @@ BUILD_ARGS := -ldflags='$(LD_FLAGS)'

# docker
DOCKER_IMAGE := andig/evcc
ALPINE_VERSION := 3.12
ALPINE_VERSION := 3.13
TARGETS := arm.v6,arm.v8,amd64

# image
IMAGE_FILE := evcc_$(TAG_NAME).image
IMAGE_ROOTFS := evcc_$(TAG_NAME).rootfs
IMAGE_OPTIONS := -hostname evcc -http_port 8080 github.com/gokrazy/serial-busybox github.com/gokrazy/breakglass github.com/andig/evcc

default: clean install npm assets lint test build
default: build

all: clean install install-ui ui assets lint test build

clean:
rm -rf dist/

install:
go install github.com/mjibson/esc
go install github.com/golang/mock/mockgen

install-ui:
npm ci

ui:
npm run build

assets:
go generate ./...

lint:
golangci-lint run
npm run lint
Expand All @@ -39,17 +48,6 @@ test:
@echo "Running testsuite"
go test ./...

npm:
npm run build

ui:
npm run build
go generate main.go

assets:
@echo "Generating embedded assets"
go generate ./...

build:
@echo Version: $(VERSION) $(BUILD_DATE)
go build -v $(BUILD_TAGS) $(BUILD_ARGS)
Expand All @@ -60,6 +58,10 @@ release-test:
release:
goreleaser --rm-dist

docker:
@echo Version: $(VERSION) $(BUILD_DATE)
docker build --tag $(DOCKER_IMAGE):testing .

publish-testing:
@echo Version: $(VERSION) $(BUILD_DATE)
seihon publish --dry-run=false --template docker/tmpl.Dockerfile --base-runtime-image alpine:$(ALPINE_VERSION) \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ When using Docker with a device that requires multicast UDP like SMA, make sure
docker run --network host andig/evcc ...
```

To build EVCC from source, [Go](2) 1.13 and [Node](3) 14 are required:
To build EVCC from source, [Go](2) 1.16 and [Node](3) 14 are required:

make

Expand Down
118 changes: 3 additions & 115 deletions cmd/demo.go
Original file line number Diff line number Diff line change
@@ -1,127 +1,15 @@
package cmd

import (
_ "embed" // for yaml
"fmt"

"github.com/spf13/viper"
"gopkg.in/yaml.v3"
)

const demoYaml = `
log: info
javascript:
- vm: shared
script: |
state = {
residualpower: 200,
pvpower: -3000,
batterypower: 200,
gridpower: -2000,
chargepower: 0,
maxcurrent: 0,
battery: 63, // car
};
function get() {
console.log("state:", JSON.stringify(state));
}
function set() {
console.log(param+":", val);
console.log("state:", JSON.stringify(state));
}
meters:
- name: grid
type: default
power:
type: js
vm: shared
script: state.gridpower = state.pvpower + state.chargepower + state.residualpower + state.batterypower;
- name: pv
type: default
power:
type: js
vm: shared
script: state.pvpower += 100*Math.random();
- name: battery
type: default
power:
type: js
vm: shared
script: state.batterypower;
soc:
type: js
vm: shared
script: "30"
- name: charge
type: default
power:
type: js
vm: shared
script: state.chargepower;
soc:
type: js
vm: shared
script: "30"
chargers:
- name: demo
type: default
enable:
type: js
vm: shared
script: |
set();
state.enabled = val;
if (state.enabled) state.chargepower = state.maxcurrent * 230; else state.chargepower = 0;
enabled:
type: js
vm: shared
script: |
state.enabled;
status:
type: js
vm: shared
script: |
if (state.enabled) "C"; else "B";
maxcurrent:
type: js
vm: shared
script: |
set();
state.maxcurrent = val;
if (state.enabled) state.chargepower = state.maxcurrent * 230;
vehicles:
- name: demo
title: e-Golf
type: default
charge:
type: js
vm: shared
script: |
if (state.chargepower > 0) state.battery++; else state.battery--;
if (state.battery < 15) state.battery = 15;
if (state.battery > 100) state.battery = 100;
state.battery;
cache: 1s
site:
title: Demo
meters:
grid: grid
pv: pv
battery: battery
loadpoints:
- title: Carport
charger: demo
meters:
charge: charge
vehicle: demo
`
//go:embed demo.yaml
var demoYaml string

func demoConfig() (conf config) {
demo := map[string]interface{}{}
Expand Down
Loading

0 comments on commit 3bb58e5

Please sign in to comment.