Skip to content

Commit

Permalink
Merge pull request #7 from ThetaGamma/testing
Browse files Browse the repository at this point in the history
fix #5
  • Loading branch information
ThetaGamma committed Mar 14, 2021
2 parents f9def75 + 8881d68 commit 41e65b8
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 22 deletions.
11 changes: 2 additions & 9 deletions dist/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
# 1. build the image with
# export BUILD_VERSION=$(curl -Ls https://api.github.com/repos/mdzio/ccu-jack/releases/latest | grep -oP '"tag_name": "v\K(.*)(?=")')
# docker build --rm --no-cache \
# --build-arg BUILD_VERSION="${BUILD_VERSION}" \
# --build-arg BUILD_DATE="$(date +"%Y-%m-%dT%H:%M:%SZ")" \
# --tag ccu-jack:latest --tag ccu-jack:${BUILD_VERSION} .
#
# 2. you have to mount your config DIRECTORY into container and run the image, i.e.
# docker run -d -v $PWD/conf/ccu-jack.cfg:/app/conf/ccu-jack.cfg -v $PWD/cert:/app/cert --name ccu-jack ccu-jack:latest
# Please don't use this filke directly but
# build the image with Shellscript "./build-release.sh"

FROM alpine

Expand Down
57 changes: 57 additions & 0 deletions dist/docker/Dockerfile.nightly
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Please don't use this filke directly but
# build the image with Shellscript "./build-nightly.sh"

# Start from golang alpine base image
FROM golang:alpine3.13 as builder
RUN apk --no-cache add unzip

# Set the Current Working Directory inside the container
WORKDIR /app

# Get the current source
RUN wget -q "https://github.com/mdzio/ccu-jack/archive/master.zip" && \
unzip master.zip
RUN cd ccu-jack-master/build && go run .

######## Start a new stage from scratch and build the dist container #######
FROM alpine

ARG BUILD_DATE
ARG BUILD_VERSION
ARG BUILD_VERSION_NIGHTLY

LABEL maintainer="Theta Gamma <thetagamma11@gmail.com>"
LABEL org.opencontainers.image.created=$BUILD_DATE \
org.opencontainers.image.version=$BUILD_VERSION_NIGHTLY \
org.opencontainers.image.title="CCU-Jack" \
org.opencontainers.image.description="REST/MQTT-Server for the HomeMatic CCU" \
org.opencontainers.image.vendor="CCU-Jack OpenSource Project" \
org.opencontainers.image.authors="mdzio <info@ccu-historian.de>" \
org.opencontainers.image.licenses="GPL-3.0 License" \
org.opencontainers.image.url="https://github.com/mdzio/ccu-jack" \
org.opencontainers.image.documentation="https://github.com/mdzio/ccu-jack/blob/master/README.md"

# Set work directory
WORKDIR /app

# Get the compiled binary and extract it locally
COPY --from=builder /app/ccu-jack-master/ccu-jack-linux-${BUILD_VERSION}.tar.gz .

RUN tar -xvzf ccu-jack-linux-${BUILD_VERSION}.tar.gz && \
mkdir -p /app/conf /app/cert /data && \
adduser -h /app -D -H ccu-jack -u 1000 -s /sbin/nologin && \
chown -R ccu-jack:ccu-jack /data && chmod -R g+rwX /data && \
chown -R ccu-jack:ccu-jack /app && chmod -R g+rwX /app

USER ccu-jack

# MQTT, MQTT TLS, CCU-Jack VEAM/UI, CCU-Jack VEAM/UI TLS, CUxD
EXPOSE 1883 8883 2121 2122 2123

# Add a healthcheck (default every 30 secs)
HEALTHCHECK --interval=30s --timeout=5s --start-period=40s --retries=3 \
CMD wget --spider -S -q http://localhost:2121/ui/ 2>&1 | head -1 || exit 1

# Start it up with full path

ENTRYPOINT [ "/app/ccu-jack","-config","/app/conf/ccu-jack.cfg" ]
56 changes: 44 additions & 12 deletions dist/docker/README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,58 @@
# Docker

Um CCU-Jack in einem Docker-Container zu starten sind folgende Schritte nötig:
## Start von CCU Jack mit einem fertigen Image

1. `Dockerfile` und ggf. `docker-compose.yml` herunterladen.
Am einfachsten geht das Starten des Containers (unter Linux) mit Docker-Compose. Dazu einfach die Datei `docker-compose.yml` herunterladen und folgenden Befehl ausführen:

```bash
docker-compose up -d .
```

In der `docker-compose.yml` können Netzwerk-Ports, die in der eigenen Umgebung nicht genutzt werden, auskommentiert werden.

## Eigenes Docker Image bauen und nutzen

Um einen eigenes CCU-Jack-Container-Image zu bauen gibt es zwei verschiedene Möglichkeiten

### Variante 1: Image aus stabilen "Release" von mdzio/ccu-jack bauen

das ist die empfohlene Variante, wenn man auf der sicheren Seite sein möchte.

1. `Dockerfile` und `build-release.sh` herunterladen
2. Docker-Image bauen:

```bash
export BUILD_VERSION=$(curl -Ls https://api.github.com/repos/mdzio/ccu-jack/releases/latest | grep -oP '"tag_name": "v\K(.*)(?=")')

docker build --rm --no-cache \
--build-arg BUILD_VERSION="${BUILD_VERSION}" \
--build-arg BUILD_DATE="$(date +"%Y-%m-%dT%H:%M:%SZ")" \
--tag ccu-jack:latest --tag ccu-jack:${BUILD_VERSION} .
sh build-release.sh
```
3. Die Verzeichnisse `conf` und `cert` erstellen, und dort die eigene Konfiguration bzw. die eigenen Zertifikate speichern.
4. a) Starten direkt über Docker:

### Variante 2: Image aus dem aktuellen Code im Repo von mdzio/ccu-jack bauen

das ist die Variante, wenn man neueste Änderungen aus dem Repo benötigt

1. `Dockerfile` und `build-nightly.sh` herunterladen
2. Docker-Image bauen:

```bash
sh build-nightly.sh
```

### Konfiguration und Start des Containers

- nun die Verzeichnisse `conf` und `cert` erstellen, und dort die eigene Konfiguration bzw. die eigenen Zertifikate speichern.
- Starten direkt über Docker:

```bash
docker run -d -v "$PWD"/conf:/app/conf --name ccu-jack ccu-jack:latest
```

b) Starten mit Docker-Compose:
- Alternativ: im `docker-compose.yml` die `image` Zeile ersetzen durch

```yaml
image: ccu-jack:latest
```

und starten mit

```bash
docker-compose up -d .
```
In der `docker-compose.yml` können Netzwerk-Ports, die in der eigenen Umgebung nicht genutzt werden, auskommentiert werden.
11 changes: 11 additions & 0 deletions dist/docker/build-nightly.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
# used to build a "nightly" image from the latest source code at mdzio/ccu-jack which might not be a release yet
#
# TODO: multi-arch
export BUILD_VERSION=$(curl -Ls https://api.github.com/repos/mdzio/ccu-jack/releases/latest | grep -oP '"tag_name": "v\K(.*)(?=")')
docker build --rm --no-cache \
--build-arg BUILD_VERSION="${BUILD_VERSION}" \
--build-arg BUILD_DATE="$(date +"%Y-%m-%dT%H:%M:%SZ")" \
--build-arg BUILD_VERSION_NIGHTLY="${BUILD_VERSION}-$(date +"%Y-%m-%d")" \
--tag ccu-jack:${BUILD_VERSION}_nightly \
-f Dockerfile.nightly .
8 changes: 8 additions & 0 deletions dist/docker/build-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
# used to build a stable image from the latest release from mdzio/ccu-jack
#
export BUILD_VERSION=$(curl -Ls https://api.github.com/repos/mdzio/ccu-jack/releases/latest | grep -oP '"tag_name": "v\K(.*)(?=")')
docker build --rm --no-cache \
--build-arg BUILD_VERSION="${BUILD_VERSION}" \
--build-arg BUILD_DATE="$(date +"%Y-%m-%dT%H:%M:%SZ")" \
--tag ccu-jack:latest --tag ccu-jack:${BUILD_VERSION} .
4 changes: 3 additions & 1 deletion dist/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ version: "3"
#
services:
ccu-jack:
image: ccu-jack:latest
image: thetagamma/ccu-jack:latest
# to use a local image use instead
# image: ccu-jack:latest
container_name: ccu-jack
hostname: ccu-jack
environment:
Expand Down

0 comments on commit 41e65b8

Please sign in to comment.