-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #262 from developer79433/master
Containerise this
- Loading branch information
Showing
19 changed files
with
313 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: C/C++ CI | ||
|
||
on: | ||
push: | ||
branches: [ "*" ] | ||
pull_request: | ||
branches: [ "*" ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: make | ||
run: sudo apt install -y libmosquittopp-dev && make |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Docker Image CI | ||
|
||
on: | ||
push: | ||
branches: [ "*" ] | ||
pull_request: | ||
branches: [ "*" ] | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ testmode.h | |
build-1284/* | ||
.vscode | ||
.pio | ||
*.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
FROM debian:bookworm-slim as base | ||
|
||
######################################## | ||
## 1st stage compiles OpenSprinkler runtime dependency raspi-gpio | ||
FROM base as raspi-gpio-build | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
RUN apt-get update && apt-get install -y git gcc make automake && rm -rf /var/lib/apt/lists/* | ||
RUN mkdir /raspi-gpio && cd /raspi-gpio && git clone --depth 1 https://github.com/RPi-Distro/raspi-gpio.git . && autoreconf -f -i && (./configure || cat config.log) && make | ||
|
||
######################################## | ||
## 2nd stage compiles OpenSprinkler code | ||
FROM base as os-build | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
RUN apt-get update && apt-get install -y bash g++ make libmosquittopp-dev && rm -rf /var/lib/apt/lists/* | ||
COPY . /OpenSprinkler | ||
RUN cd /OpenSprinkler && make | ||
|
||
######################################## | ||
## 3rd stage is minimal runtime + executable | ||
FROM base | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
RUN apt-get update && apt-get install -y libstdc++6 libmosquittopp1 && rm -rf /var/lib/apt/lists/* \ | ||
&& \ | ||
mkdir /OpenSprinkler && \ | ||
mkdir -p /data/logs | ||
|
||
COPY --from=os-build /OpenSprinkler/OpenSprinkler /OpenSprinkler/OpenSprinkler | ||
COPY --from=raspi-gpio-build /raspi-gpio/raspi-gpio /usr/bin/raspi-gpio | ||
WORKDIR /OpenSprinkler | ||
|
||
#-- Logs and config information go into the volume on /data | ||
VOLUME /data | ||
|
||
#-- OpenSprinkler interface is available on 8080 | ||
EXPOSE 8080 | ||
|
||
#-- By default, start OS using /data for saving data/NVM/log files | ||
CMD [ "/OpenSprinkler/OpenSprinkler", "-d", "/data" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
CXX=g++ | ||
# -std=gnu++17 | ||
CXXFLAGS=-std=gnu++14 -DOSPI -Wall | ||
LD=$(CXX) | ||
LIBS=pthread mosquitto | ||
LDFLAGS=$(addprefix -l,$(LIBS)) | ||
BINARY=OpenSprinkler | ||
SOURCES=main.cpp OpenSprinkler.cpp program.cpp opensprinkler_server.cpp utils.cpp weather.cpp gpio.cpp etherport.cpp mqtt.cpp | ||
HEADERS=$(wildcard *.h) | ||
OBJECTS=$(SOURCES:.cpp=.o) | ||
|
||
.PHONY: all | ||
all: $(BINARY) | ||
|
||
%.o: %.cpp $(HEADERS) | ||
$(CXX) -c -o "$@" $(CXXFLAGS) "$<" | ||
|
||
$(BINARY): $(OBJECTS) | ||
$(CXX) -o $(BINARY) $(OBJECTS) $(LDFLAGS) | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -f $(OBJECTS) $(BINARY) | ||
|
||
.PHONY: container | ||
container: | ||
docker build . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Running OpenSprinkler via Docker | ||
|
||
## Building the container | ||
From this directory, create the image: | ||
|
||
```sh | ||
$ docker build -t opensprinkler . | ||
``` | ||
|
||
Notes: | ||
* This requires a version of Docker that supports multi-stage builds | ||
(i.e., version >= 17.06). | ||
* The container is built for the armhf architecture. | ||
|
||
## Running the container | ||
Once the container is built, it can be started via: | ||
|
||
```sh | ||
$ mkdir ~/opensprinkler | ||
$ docker run -d \ | ||
--name opensprinkler \ # Give it a handy name | ||
--privileged \ # Privileged because we need access to devices | ||
--publish 8080:8080 \ # Make the web interface accessible | ||
--restart always \ # Auto restart on crash/exit | ||
--volume /dev:/dev \ # Provide access to /dev | ||
--volume ~/opensprinkler:/data \ # Where to save NVM & logs | ||
opensprinkler # The image (from above) | ||
``` | ||
|
||
The persistent data generated by OS is written to the volume mounted at `/data` | ||
within the container. This includes the NVM files, IFTTT key file, and log | ||
directory. In the above sample command line, these files will end up in the | ||
user's home directory (`${HOME}/opensprinkler`). Other options, including using | ||
a docker data volume are possible. NOTE: If you don't specify a volume or dir to | ||
mount here, your OpenSprinkler configuration will not persist across restarts of | ||
the container. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.