Skip to content

Commit 252ed3c

Browse files
author
D
committed
auto build docker for Actions
1 parent 79a9158 commit 252ed3c

File tree

3 files changed

+91
-32
lines changed

3 files changed

+91
-32
lines changed

.github/workflows/docker-build.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Create Docker Images
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
env:
12+
NODE_LATEST: 16
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
node: [ 14, 16, 18 ]
18+
suffix: [ "" ]
19+
20+
steps:
21+
- name: 1-checkout
22+
uses: actions/checkout@v3
23+
with:
24+
fetch-depth: 0
25+
- name: 2-setup-image-setting
26+
id: setting
27+
run: |
28+
SUFFIX=""
29+
if [ "${{ matrix.suffix }}" != "" ]; then
30+
SUFFIX="-${{ matrix.suffix}}"
31+
fi
32+
33+
TAGS="ghcr.io/${{ github.repository }}:${{ matrix.node }}$SUFFIX"
34+
if [ "${{ matrix.node }}" == "${{ env.NODE_LATEST }}" ]; then
35+
TAGS="$TAGS,ghcr.io/${{ github.repository }}:latest$SUFFIX"
36+
fi
37+
38+
echo "current tags $TAGS"
39+
echo "TAGS=$TAGS" >> $GITHUB_ENV
40+
41+
- name: 3-setup-qemu-action
42+
uses: docker/setup-qemu-action@v2
43+
- name: 4-login-action
44+
uses: docker/#-action@v2
45+
with:
46+
registry: ghcr.io
47+
username: ${{ github.repository_owner }}
48+
password: ${{ secrets.GITHUB_TOKEN }}
49+
- name: 5-setup-buildx-action
50+
uses: docker/setup-buildx-action@v2
51+
- name: 6-build-push-action
52+
uses: docker/build-push-action@v3
53+
continue-on-error: true
54+
with:
55+
context: ./
56+
file: ./Dockerfile
57+
platforms: linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6
58+
push: true
59+
build-args: |
60+
NODE_VERSION=${{ matrix.node }}
61+
tags: |
62+
${{ env.TAGS }}

Dockerfile

+21-24
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
1-
FROM balenalib/rpi-raspbian:latest
1+
ARG NODE_VERSION=16
22

3-
ARG ARCH=armv6l
4-
ARG NODE_VERSION=8.17.0
3+
FROM node:${NODE_VERSION}-alpine AS build
54

6-
RUN apt-get update \
7-
&& apt-get install -y bluetooth \
8-
bluez \
9-
libbluetooth-dev \
10-
libudev-dev \
11-
mosquitto-clients \
12-
build-essential \
13-
python3 \
14-
ca-certificates \
15-
&& apt-get clean
5+
COPY / /app
166

17-
RUN update-ca-certificates --fresh
7+
RUN set -x \
8+
&& apk add --no-cache --virtual .build-deps \
9+
build-base \
10+
linux-headers \
11+
eudev-dev \
12+
python3 \
13+
git \
14+
&& cd /app \
15+
&& npm i --production --verbose \
16+
&& apk del .build-deps
1817

19-
RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH.tar.gz" \
20-
&& tar -xzf "node-v$NODE_VERSION-linux-$ARCH.tar.gz" -C /usr/local --strip-components=1 \
21-
&& rm "node-v$NODE_VERSION-linux-$ARCH.tar.gz"
18+
FROM node:${NODE_VERSION}-alpine
2219

23-
ADD / /EspruinoHub
20+
COPY --from=build /app /app
2421

25-
WORKDIR /EspruinoHub
22+
RUN set -x \
23+
&& apk add --no-cache tzdata \
24+
&& mkdir -p /data \
25+
&& cp /app/config.json /data/config.json
2626

27-
RUN npm install \
28-
&& npm cache clean --force
27+
WORKDIR /app
2928

30-
VOLUME ["/EspruinoHub/log"]
31-
32-
ENTRYPOINT ["node", "index.js"]
29+
CMD [ "node", "index.js", "-c", "/data/config.json" ]

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ These instructions install up to date Node.js and Node-RED - however it can take
2525
```
2626
sudo apt-get update
2727
# OPTIONAL: Update everything to latest versions
28-
sudo apt-get upgrade -y
28+
sudo apt-get upgrade -y
2929
# Get required packages
3030
sudo apt-get install -y build-essential python-rpi.gpio nodejs nodered git-core
3131
# OPTIONAL: Install a modern version of nodejs and nodered
@@ -61,7 +61,7 @@ You can now type `./start.sh` to run EspruinoHub, but it's worth checking out th
6161
# Install Node, Bluetooth, etc
6262
sudo apt-get update
6363
# OPTIONAL: Update everything to latest versions
64-
sudo apt-get upgrade -y
64+
sudo apt-get upgrade -y
6565
# Get required packages
6666
sudo apt-get install -y git-core nodejs npm build-essential mosquitto mosquitto-clients bluetooth bluez libbluetooth-dev libudev-dev
6767
# Now get EspruinoHub
@@ -144,13 +144,13 @@ sudo rm -rf ~/EspruinoHub
144144
Run with Docker
145145
---------------
146146

147-
Build on Raspberry Pi Zero:
147+
Install:
148148

149-
docker build -t espruino/espruinohub:armhf https://github.com/espruino/EspruinoHub.git
149+
docker pull ghcr.io/espruino/espruinohub
150150

151151
Run from the directory containing your `config.json`:
152152

153-
docker run -d -v $PWD/config.json:/EspruinoHub/config.json:ro --restart=always --net=host --name espruinohub espruino/espruinohub:armhf
153+
docker run -d -v $PWD/config.json:/data/config.json:ro --restart=always --net=host --name espruinohub ghcr.io/espruino/espruinohub
154154

155155
Usage
156156
-----
@@ -241,7 +241,7 @@ var data = {a:1,b:2};
241241
NRF.setAdvertising({},{
242242
showName:false,
243243
manufacturer:0x0590,
244-
manufacturerData:E.toJS(data)
244+
manufacturerData:E.toJS(data)
245245
});
246246
// Note: JSON.stringify(data) can be used instead of
247247
// E.toJS(data) to produce 'standard' JSON like {"a":1,"b":2}
@@ -335,7 +335,7 @@ However, you can also request historical data by sending the JSON:
335335
{
336336
"topic" : "/hist/hour/ble/temp/f5:47:c8:0b:49:04",
337337
"interval" : "minute",
338-
"age" : 6
338+
"age" : 6
339339
}
340340
```
341341

@@ -363,7 +363,7 @@ Requests can be of the form:
363363
"age" : 1, // hours
364364
// or:
365365
"from" : "1 July 2018",
366-
"to" : "5 July 2018" (or anything that works in new Date(...))
366+
"to" : "5 July 2018" (or anything that works in new Date(...))
367367
}
368368
```
369369

0 commit comments

Comments
 (0)