Skip to content

Commit

Permalink
chore: build infrastructure for go
Browse files Browse the repository at this point in the history
chore: build infrastructure for go

fix(ci): fix the build
  • Loading branch information
philipparndt committed Oct 13, 2024
1 parent 625d815 commit 23f83af
Show file tree
Hide file tree
Showing 55 changed files with 165 additions and 15,922 deletions.
1 change: 0 additions & 1 deletion .env

This file was deleted.

60 changes: 21 additions & 39 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,78 +16,60 @@ jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
permissions:
contents: write

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 20.x
steps:
- uses: actions/checkout@v4

- uses: philipparndt/get-release-number@v2
- uses: philipparndt/get-release-number@v3
id: next
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
releaseType: ${{ github.event.inputs.releaseType }}

- name: Update version
working-directory: app
env:
RELEASE_VERSION: ${{ steps.next.outputs.version }}
run: npm version $RELEASE_VERSION --allow-same-version

- name: Install
working-directory: app
shell: bash
run: npm install
- uses: actions/setup-go@v5
with:
go-version: '1.22.5'

- name: Build
working-directory: app
shell: bash
run: npm run build
run: |
go build .
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build docker container and push
id: docker_build
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
env:
RELEASE_VERSION: ${{ steps.next.outputs.version }}
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
context: ./app
file: ./app/Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true
tags: |
pharndt/eltakomqtt:latest
pharndt/eltakomqtt:${{env.RELEASE_VERSION}}
- name: Create Release
id: create_release
uses: ncipollo/release-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_VERSION: ${{ steps.next.outputs.version }}
- uses: ncipollo/release-action@v1
with:
tag: ${{env.RELEASE_VERSION}}
name: ${{env.RELEASE_VERSION}}
name: ${{ steps.next.outputs.version }}
tag: ${{ steps.next.outputs.version }}
body: |
Docker tag: `pharndt/eltakomqtt:${{env.RELEASE_VERSION}}`
Docker tag: `pharndt/eltakomqtt:${{ steps.next.outputs.version }}`
Changes in this Release
- Dependency update
- ...
draft: false
prerelease: false
34 changes: 16 additions & 18 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,26 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v3
- uses: actions/setup-go@v5
with:
node-version: 20.x

- name: Install
working-directory: app
run: |
npm install
- name: Lint/Test
working-directory: app
run: |
npm run lint
npm test
go-version: '1.22.5'

- name: Build
working-directory: app
run: |
npm run build
go build .
- name: Build container
run: docker compose build
- name: Build docker container and push
id: docker_build
uses: docker/build-push-action@v6
env:
RELEASE_VERSION: ${{ steps.next.outputs.version }}
with:
context: ./app
file: ./app/Dockerfile
platforms: linux/amd64
push: false
tags: |
pharndt/eltakomqtt:latest
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ config-auth.json
.DS_Store

.idea
*.iml
*.iml

eltako-to-mqtt-gw
5 changes: 0 additions & 5 deletions Dockerfile

This file was deleted.

13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ Topic: `home/eltako/<device-name>/set`
}
```

### Tilt the blinds

Topic: `home/eltako/<device-name>/set`

```json
{
"action": "tilt",
"position": 50
}
```

This will move the position to 50% and then tilt the blinds.

## Configuration

Example configuration:
Expand Down
47 changes: 0 additions & 47 deletions app/.eslintrc.json

This file was deleted.

4 changes: 0 additions & 4 deletions app/.gitignore

This file was deleted.

26 changes: 26 additions & 0 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Build the application from source
FROM golang:1.22 AS build-stage

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download

COPY . ./

RUN CGO_ENABLED=0 GOOS=linux go build -o /eltako-to-mqtt-gw

# Run the tests in the container
FROM build-stage AS run-test-stage
RUN go test -v ./...

# Deploy the application binary into a lean image
FROM gcr.io/distroless/base-debian11 AS build-release-stage

WORKDIR /

COPY --from=build-stage /eltako-to-mqtt-gw /eltako-to-mqtt-gw

USER nonroot:nonroot

ENTRYPOINT ["/eltako-to-mqtt-gw", "/var/lib/eltako-to-mqtt-gw/config.json"]
33 changes: 33 additions & 0 deletions app/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Makefile for Go application

# Set the Go binary and flags
GO = go
GOFLAGS = -v

# Set the paths
BUILD_DIR = build
CONFIG_DIR = $(PWD)/../production/config

# Set the binary name
BINARY_NAME = eltako-to-mqtt-gw
DOCKER_IMAGE_NAME = pharndt/eltako:latest

.PHONY: build
build:
@echo "Building the application..."
@$(GO) build $(GOFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) .

.PHONY: run
run: build
@echo "Running the application..."
@$(BUILD_DIR)/$(BINARY_NAME) $(CONFIG_DIR)/config.json

.PHONY: docker
docker: build
@echo "Building Docker image..."
@docker build -t $(DOCKER_IMAGE_NAME) .

.PHONY: clean
clean:
@echo "Cleaning up..."
@rm -rf $(BUILD_DIR)
2 changes: 1 addition & 1 deletion v2/commands/commands.go → app/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (c *Action) validate() (LLCommand, error) {
llc.Action = LLActionSet
llc.Position = c.Position
case string(ActionCloseAndOpenBlinds):
llc.Action = LLActionSet
llc.Action = LLActionTilt
llc.Position = 0
case string(ActionTilt):
llc.Action = LLActionTilt
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions v2/eltako/command.go → app/eltako/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ func (s *ShadingActor) Apply(command commands.LLCommand) {

switch command.Action {
case commands.LLActionSet:
position, err := s.SetPosition(command.Position)
_, err := s.SetPosition(command.Position)
if err != nil {
logger.Error("Failed setting position", err)
} else {
logger.Info("Set position to", position)
logger.Info("Set position to", command.Position)
}
case commands.LLActionTilt:
s.Tilt(command.Position)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions app/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module github.com/mqtt-home/eltako-to-mqtt-gw

go 1.22.2

require (
github.com/philipparndt/go-logger v1.0.0
github.com/philipparndt/mqtt-gateway v1.3.0
)

require (
github.com/eclipse/paho.mqtt.golang v1.5.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sync v0.8.0 // indirect
)
12 changes: 12 additions & 0 deletions app/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
github.com/eclipse/paho.mqtt.golang v1.5.0 h1:EH+bUVJNgttidWFkLLVKaQPGmkTUfQQqjOsyvMGvD6o=
github.com/eclipse/paho.mqtt.golang v1.5.0/go.mod h1:du/2qNQVqJf/Sqs4MEL77kR8QTqANF7XU7Fk0aOTAgk=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/philipparndt/go-logger v1.0.0 h1:5khKl1q8q6FH74S1wF5KPl6DvdZnRdPKqKbBPQDr9P4=
github.com/philipparndt/go-logger v1.0.0/go.mod h1:4mWf8eNH82GhKl5byAFwXcux9WPNuaePaPaAFbgjHXg=
github.com/philipparndt/mqtt-gateway v1.3.0 h1:QeJ0XIEnlzH4Qm7vqAQN3WTrI45UcPxlcQFcTrCXvn8=
github.com/philipparndt/mqtt-gateway v1.3.0/go.mod h1:N6LC57xFs/u41Xc5csPHTACm/00GyOyMgIC+oOqp32Y=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
28 changes: 0 additions & 28 deletions app/jest.config.js

This file was deleted.

20 changes: 0 additions & 20 deletions app/lib/actorRegistry.ts

This file was deleted.

Loading

0 comments on commit 23f83af

Please sign in to comment.