Skip to content

Commit

Permalink
Refactor lawndon-pi build and deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
jordojordo committed Nov 23, 2024
1 parent 476bd05 commit 5411a3c
Show file tree
Hide file tree
Showing 20 changed files with 453 additions and 562 deletions.
108 changes: 108 additions & 0 deletions .github/workflows/build-lawndon.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Build Lawndon

on:
workflow_dispatch:
release:
types: [released]

jobs:
build-lawndon:
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Arduino cli
uses: arduino/setup-arduino-cli@v2

- name: Install libraries
run: |
arduino-cli lib install IBusBM Servo
- name: Compile Lawndon
uses: arduino/compile-sketches@v1
with:
fqbn: "arduino:avr:mega"
libraries: |
- name: IBusBM
- name: Servo
sketch-paths: |
- ./lawndon
enable-warnings-report: true
verbose: false
cli-compile-flags: |
- --export-binaries
- name: Package build
if: startsWith(github.ref, 'refs/tags/')
run: |
for dir in ./lawndon/build/*; do
if [ -d "${dir}" ]; then
tar -czvf "${dir}.tar.gz" -C "${dir}" .
fi
done
- name: Release build
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
lawndon/build/*.tar.gz
build-lawndon-pi:
runs-on: ubuntu-latest
needs: build-lawndon
env:
WORKING_DIR: ./pi
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up QEMU for multi-platform builds
uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64,linux/arm64

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --allow-insecure-entitlement security.insecure
install: true

- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push server image
uses: docker/build-push-action@v4
working-directory: ${{ env.WORKING_DIR }}
with:
context: .
file: ./Dockerfile.server
push: true
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/${{ github.repository_owner }}/lawndon-pi-server:${{ github.ref_name }}
ghcr.io/${{ github.repository_owner }}/lawndon-pi-server:${{ github.sha }}
- name: Build and push UI image
uses: docker/build-push-action@v4
working-directory: ${{ env.WORKING_DIR }}
with:
context: .
file: ./Dockerfile.ui
push: true
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/${{ github.repository_owner }}/lawndon-pi-ui:${{ github.ref_name }}
ghcr.io/${{ github.repository_owner }}/lawndon-pi-ui:${{ github.sha }}
82 changes: 0 additions & 82 deletions .github/workflows/build-lawndon.yml

This file was deleted.

12 changes: 6 additions & 6 deletions .github/workflows/tests.yml → .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- cron: "0 4 * * 4"

jobs:
build-lawndon:
build-lawndon-test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand Down Expand Up @@ -41,7 +41,7 @@ jobs:
cli-compile-flags: |
- --export-binaries
package-lawndon-pi:
build-lawndon-pi-test:
runs-on: ubuntu-latest
env:
WORKING_DIR: ./pi
Expand Down Expand Up @@ -79,12 +79,12 @@ jobs:
run: |
pnpm build:server
- name: Run package script
- name: Test Docker build for Server
working-directory: ${{ env.WORKING_DIR }}
run: |
./package.sh
docker build --no-cache --file ./Dockerfile.server --tag lawndon-pi-server-test .
- name: Verify package contents
- name: Test Docker build for UI
working-directory: ${{ env.WORKING_DIR }}
run: |
tar -df lawndon-pi.tar.gz lawndon-pi
docker build --no-cache --file ./Dockerfile.ui --tag lawndon-pi-ui-test .
27 changes: 27 additions & 0 deletions pi/Dockerfile.server
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Build stage
FROM node:22-alpine AS build
WORKDIR /usr/src/app

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
ENV NODE_ENV=production
ENV CONFIG_PATH=/usr/src/app/config

RUN corepack enable
COPY server/package*.json ./
RUN pnpm install

COPY server ./server
WORKDIR /usr/src/app/server
RUN pnpm build

# Runtime stage
FROM node:22-alpine
WORKDIR /usr/src/app

COPY --from=build /usr/src/app/server/dist ./dist
COPY --from=build /usr/src/app/server/node_modules ./node_modules
COPY config ./config

EXPOSE 5000 8080
CMD ["node", "dist/server.js"]
22 changes: 22 additions & 0 deletions pi/Dockerfile.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Build stage
FROM node:22-alpine AS build
WORKDIR /usr/src/app

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
ENV VITE_NODE_ENV=production

RUN corepack enable
COPY ui/package*.json ./
RUN pnpm install

COPY ui ./ui
WORKDIR /usr/src/app/ui
RUN pnpm build

# Runtime stage
FROM nginx:alpine
COPY --from=build /usr/src/app/ui/dist /usr/share/nginx/html

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
28 changes: 28 additions & 0 deletions pi/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
services:
server:
image: ghcr.io/jordojordo/lawndon-pi-server:latest
environment:
NODE_ENV: production
CONFIG_PATH: /usr/src/app/config
ports:
- "5000:5000" # WebSocket and API
- "8080:8080" # ESP32 module communication
volumes:
- ./config:/usr/src/app/config:ro # Mount config for anchor positions
networks:
- app_network

ui:
image: ghcr.io/jordojordo/uwb-ui:latest
environment:
VITE_NODE_ENV: production
ports:
- "80:80" # Expose UI
depends_on:
- server
networks:
- app_network

networks:
app_network:
driver: bridge
3 changes: 2 additions & 1 deletion pi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "lawndon-pi",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"install:ui": "pnpm install --prefix ui",
"install:server": "pnpm install --prefix server",
Expand All @@ -10,7 +11,7 @@
"start": "node server/dist/server.js",
"dev": "concurrently -k -n SERVER,UI \"pnpm dev:server\" \"pnpm dev:ui\"",
"dev:ui": "pnpm --prefix ui dev",
"dev:server": "NODE_ENV=development pnpm --prefix server dev"
"dev:server": "pnpm --prefix server dev"
},
"packageManager": "pnpm@9.14.2",
"devDependencies": {
Expand Down
1 change: 0 additions & 1 deletion pi/server/.env.dev
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
NODE_ENV="development"
CONFIG_PATH="../../config"
UI_PATH="../../ui"
1 change: 0 additions & 1 deletion pi/server/.env.prod
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
NODE_ENV="production"
CONFIG_PATH="../config"
UI_PATH="../ui"
21 changes: 0 additions & 21 deletions pi/server/esbuild.config.js

This file was deleted.

13 changes: 7 additions & 6 deletions pi/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
"name": "uwb-server",
"version": "0.1.0",
"description": "",
"main": "dist/server.cjs",
"main": "dist/server.js",
"type": "module",
"scripts": {
"start": "node dist/server.cjs",
"build": "NODE_ENV=production node esbuild.config.js",
"dev": "nodemon --watch src --ext ts --exec 'ts-node ./src/server.ts'",
"start": "node dist/server.js",
"build": "tsc --outDir dist",
"dev": "NODE_ENV=development nodemon --watch src --ext ts --exec 'node --loader ts-node/esm ./src/server.ts'",
"lint": "npx eslint .",
"format": "npx eslint . --fix"
},
Expand All @@ -23,9 +24,9 @@
},
"devDependencies": {
"@types/cors": "^2.8.17",
"@types/dotenv": "^8.2.3",
"@types/express": "^5.0.0",
"@types/node": "^22.9.1",
"esbuild": "^0.24.0",
"@types/node": "^22.9.3",
"eslint": "^9.15.0",
"globals": "^15.12.0",
"http-proxy-middleware": "^3.0.3",
Expand Down
Loading

0 comments on commit 5411a3c

Please sign in to comment.