Skip to content

Commit 274e2bf

Browse files
Add Docker files
1 parent acbb42a commit 274e2bf

9 files changed

+189
-7
lines changed
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Build and deploy timelapse
2+
3+
on:
4+
push:
5+
branches: main
6+
paths:
7+
- rpi-timelapse/**
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
environment: prod
13+
steps:
14+
- name: checkout code
15+
uses: actions/checkout@v2
16+
- name: Set up QEMU
17+
uses: docker/setup-qemu-action@v1
18+
- name: Set up Docker Buildx
19+
uses: docker/setup-buildx-action@v1
20+
- name: Login to DockerHub
21+
uses: docker/login-action@v1
22+
with:
23+
username: ${{ secrets.DOCKER_USERNAME }}
24+
password: ${{ secrets.DOCKER_PASSWORD }}
25+
- name: build the image
26+
run: |
27+
docker buildx build --push \
28+
--tag ticklethepanda/timelapse:latest \
29+
--platform linux/amd64,linux/arm/v7,linux/arm64 ./rpi-timelapse
30+
- name: Setup k8s context
31+
uses: azure/k8s-set-context@v1
32+
with:
33+
method: kubeconfig
34+
kubeconfig: ${{ secrets.KUBE_CONFIG }}
35+
- name: Rollout latest image
36+
run: kubectl rollout restart deployment/timelapse-deployment --namespace=home

deploy/timelapse--dep.yaml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: timelapse-deployment
6+
labels:
7+
app: timelapse
8+
namespace: home
9+
spec:
10+
selector:
11+
matchLabels:
12+
app: timelapse
13+
template:
14+
metadata:
15+
labels:
16+
app: timelapse
17+
spec:
18+
containers:
19+
- name: timelapse
20+
image: ticklethepanda/rpi-timelapse:latest
21+
env:
22+
- name: SPEED_TEST_SITE_ROOT
23+
value: "/timelapse"
24+
- name: RPI_CAMERA_STORAGE_DIR
25+
value: "/data"
26+
ports:
27+
- containerPort: 80
28+
securityContext:
29+
runAsNonRoot: true
30+
runAsUser: 10001
31+
capabilities:
32+
drop:
33+
- all
34+
add:
35+
- NET_BIND_SERVICE
36+
volumeMounts:
37+
- mountPath: /data
38+
name: timelapse-volume
39+
- mountPath: /dev/vcsm-cma
40+
name: timelapse-vcsm-cma
41+
- mountPath: /dev/vchiq
42+
name: timelapse-vchiq
43+
tolerations:
44+
- key: "pi-camera"
45+
operator: "Exists"
46+
effect: "NoSchedule"
47+
volumes:
48+
- name: timelapse-volume
49+
persistentVolumeClaim:
50+
claimName: timelapse-pvc
51+
- name: timelapse-vcsm-cma
52+
hostPath:
53+
path: /dev/vcsm
54+
- name: timelapse-vchiq
55+
hostPath:
56+
path: /dev/vchiq

deploy/timelapse--pvc.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
kind: PersistentVolumeClaim
3+
apiVersion: v1
4+
metadata:
5+
name: timelapse-pvc
6+
namespace: home
7+
spec:
8+
accessModes:
9+
- ReadWriteOnce
10+
storageClassName: local-storage
11+
volumeName: timelapse-pv
12+
resources:
13+
requests:
14+
storage: 16Gi

deploy/timelapse--svc.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
apiVersion: v1
3+
kind: Service
4+
metadata:
5+
name: timelapse
6+
labels:
7+
name: timelapse
8+
namespace: home
9+
spec:
10+
ports:
11+
# the port that this service should serve on
12+
- port: 80
13+
targetPort: 10000
14+
selector:
15+
app: timelapse

deploy/timelapse--vol.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
apiVersion: v1
3+
kind: PersistentVolume
4+
metadata:
5+
name: timelapse-pv
6+
namespace: home
7+
spec:
8+
capacity:
9+
storage: 16Gi
10+
volumeMode: Filesystem
11+
accessModes:
12+
- ReadWriteOnce
13+
persistentVolumeReclaimPolicy: Retain
14+
storageClassName: local-storage
15+
local:
16+
path: /mnt/disk/timelapse
17+
nodeAffinity:
18+
required:
19+
nodeSelectorTerms:
20+
- matchExpressions:
21+
- key: kubernetes.io/hostname
22+
operator: In
23+
values:
24+
- k8s-node-camera-1
25+

rpi-timelapse/.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
data
2+
.git
3+

rpi-timelapse/Dockerfile

+34-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,38 @@
1-
FROM golang:alpine
1+
FROM alpine:3.12 AS camera-binaries
22

3-
RUN mkdir app
4-
WORKDIR app
3+
RUN mkdir /build
4+
WORKDIR /build
5+
6+
RUN apk add --update --no-cache \
7+
cmake \
8+
gcc \
9+
g++ \
10+
git \
11+
linux-headers \
12+
make
13+
14+
RUN git clone https://github.com/raspberrypi/userland.git . && \
15+
git checkout 3fd8527eefd8790b4e8393458efc5f94eb21a615 --quiet
16+
17+
RUN mkdir build && \
18+
cd build && \
19+
CXX=g++ cmake -DHAVE_MTRACE=false -DSKIP_TAINTED_CHECK=true -DCMAKE_BUILD_TYPE=armv71 -DARM64=OFF ../ && \
20+
make && \
21+
make install
22+
23+
FROM golang:alpine3.12
24+
25+
RUN apk add --update --no-cache \
26+
libc6-compat \
27+
musl \
28+
psmisc
29+
30+
COPY --from=camera-binaries /opt/vc /opt/vc
31+
ENV PATH="${PATH}:/opt/vc/bin"
32+
ENV LD_LIBRARY_PATH="/opt/vc/lib"
33+
34+
RUN mkdir /app
35+
WORKDIR /app
536
COPY go.* ./
637
RUN go mod download
738

rpi-timelapse/src/server.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ var DEFAULT_CAMERA_SETTINGS CameraSettings = CameraSettings{
4646
VFlip: false,
4747
Width: 1600,
4848
Height: 1080,
49-
Rotation: 270,
49+
Rotation: 180,
5050
}
5151

5252
var NOW_CAMERA_SETTINGS CameraSettings = CameraSettings{
5353
HFlip: false,
5454
VFlip: false,
55-
Width: 320,
56-
Height: 240,
57-
Rotation: 270,
55+
Width: 1600,
56+
Height: 1080,
57+
Rotation: 180,
5858
}
5959

6060
func (ih *ImageResultHander) GetLatestImage(w http.ResponseWriter, r *http.Request) {

rpi-timelapse/src/timelapse-camera.go

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ func (c *TimelapseCamera) CaptureImage(cameraSettings *CameraSettings, w io.Writ
4949
s.Camera.VFlip = cameraSettings.VFlip
5050
s.Camera.HFlip = cameraSettings.HFlip
5151
s.Camera.Rotation = cameraSettings.Rotation
52+
s.Args = []string{"--flicker", "50hz"}
53+
s.Camera.MeteringMode = raspicam.MeteringAverage
5254
s.Width = cameraSettings.Width
5355
s.Height = cameraSettings.Height
5456
s.Encoding = raspicam.EncodingPNG

0 commit comments

Comments
 (0)