Compare commits
No commits in common. "39f9b997edb6e40032f0d7238658246337739ef3" and "73a2b077ed03e3f9a4c73d4efd21799ad59c77d8" have entirely different histories.
39f9b997ed
...
73a2b077ed
49
.drone.yml
Normal file
49
.drone.yml
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: default
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: build
|
||||||
|
image: docker
|
||||||
|
volumes:
|
||||||
|
- name: socket
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
commands:
|
||||||
|
- DOCKER_BUILDKIT=1 docker build -t automation_rs .
|
||||||
|
|
||||||
|
- name: deploy
|
||||||
|
image: docker
|
||||||
|
volumes:
|
||||||
|
- name: socket
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
environment:
|
||||||
|
MQTT_PASSWORD:
|
||||||
|
from_secret: MQTT_PASSWORD
|
||||||
|
HUE_TOKEN:
|
||||||
|
from_secret: HUE_TOKEN
|
||||||
|
NTFY_TOPIC:
|
||||||
|
from_secret: NTFY_TOPIC
|
||||||
|
RUST_LOG:
|
||||||
|
from_secret: RUST_LOG
|
||||||
|
commands:
|
||||||
|
- docker stop automation_rs || true
|
||||||
|
|
||||||
|
- docker rm automation_rs || true
|
||||||
|
|
||||||
|
# Networks need to be setup to to allow broadcasts: https://www.devwithimagination.com/2020/06/15/homebridge-docker-and-wake-on-lan/ https://github.com/dhutchison/container-images/blob/0c2d7d96bab751fb0a008cc91ba2990724bbd11f/homebridge/configure_docker_networks_for_wol.sh
|
||||||
|
# Needs to be done for ALL networks, because we can't seem to control which interface gets used to send the broadcast
|
||||||
|
- docker create -e RUST_LOG=$RUST_LOG -e MQTT_PASSWORD=$MQTT_PASSWORD -e HUE_TOKEN=$HUE_TOKEN -e NTFY_TOPIC=$NTFY_TOPIC --network mqtt --restart unless-stopped --name automation_rs automation_rs
|
||||||
|
- docker network connect web automation_rs
|
||||||
|
- docker start automation_rs
|
||||||
|
|
||||||
|
when:
|
||||||
|
branch:
|
||||||
|
- master
|
||||||
|
event:
|
||||||
|
exclude:
|
||||||
|
- pull_request
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- name: socket
|
||||||
|
host:
|
||||||
|
path: /var/run/docker.sock
|
|
@ -1,102 +0,0 @@
|
||||||
# Based on: https://pastebin.com/99Fq2b2w
|
|
||||||
name: Build and deploy automation_rs
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
- feature/actions
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
name: Build
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container: catthehacker/ubuntu:act-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Setup Rust
|
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
|
||||||
with:
|
|
||||||
rustflags: ""
|
|
||||||
|
|
||||||
- name: Formatting
|
|
||||||
uses: actions-rust-lang/rustfmt@v1
|
|
||||||
|
|
||||||
- name: Clippy
|
|
||||||
run: cargo clippy --all-targets --all -- -D warnings
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
run: cargo build --release
|
|
||||||
|
|
||||||
- name: Upload artifact
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: build
|
|
||||||
path: target/x86_64-unknown-linux-gnu/release/automation
|
|
||||||
|
|
||||||
container:
|
|
||||||
name: Create container
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [build]
|
|
||||||
container: catthehacker/ubuntu:act-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Download artifact
|
|
||||||
uses: actions/download-artifact@v3
|
|
||||||
with:
|
|
||||||
name: build
|
|
||||||
|
|
||||||
- name: Set permissions
|
|
||||||
run: |
|
|
||||||
chown 65532:65532 ./build/*
|
|
||||||
chmod 0755 ./build/*
|
|
||||||
|
|
||||||
- name: Login to registry
|
|
||||||
uses: https://github.com/docker/login-action@v3
|
|
||||||
with:
|
|
||||||
registry: git.huizinga.dev
|
|
||||||
username: ${{ gitea.actor }}
|
|
||||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
||||||
|
|
||||||
- name: Build & Push Docker Image
|
|
||||||
uses: https://github.com/docker/build-push-action@v5
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
push: ${{ gitea.ref == 'refs/heads/master' }}
|
|
||||||
# TODO: Automatically add the correct tags here
|
|
||||||
tags: git.huizinga.dev/dreaded_x/automation_rs:latest
|
|
||||||
|
|
||||||
deploy:
|
|
||||||
name: Deploy Docker container
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container: catthehacker/ubuntu:act-latest
|
|
||||||
needs: [container]
|
|
||||||
if: gitea.ref == 'refs/heads/master'
|
|
||||||
steps:
|
|
||||||
- name: Stop and remove current container
|
|
||||||
run: |
|
|
||||||
docker stop automation_rs || true
|
|
||||||
docker rm automation_rs || true
|
|
||||||
|
|
||||||
- name: Create container
|
|
||||||
run: |
|
|
||||||
docker create \
|
|
||||||
--pull always \
|
|
||||||
--restart unless-stopped \
|
|
||||||
--name automation_rs \
|
|
||||||
-e RUST_LOG=automation=debug \
|
|
||||||
-e MQTT_PASSWORD=${{ secrets.MQTT_PASSWORD }} \
|
|
||||||
-e HUE_TOKEN=${{ secrets.HUE_TOKEN }} \
|
|
||||||
-e NTFY_TOPIC=${{ secrets.NTFY_TOPIC }} \
|
|
||||||
git.huizinga.dev/dreaded_x/automation_rs:latest
|
|
||||||
|
|
||||||
docker network connect mqtt automation_rs
|
|
||||||
docker network connect web automation_rs
|
|
||||||
|
|
||||||
- name: Start container
|
|
||||||
run: docker start automation_rs
|
|
||||||
|
|
||||||
# TODO: Perform a healthcheck
|
|
62
Dockerfile
62
Dockerfile
|
@ -1,8 +1,64 @@
|
||||||
FROM gcr.io/distroless/cc-debian12:nonroot
|
FROM rust:bookworm AS build
|
||||||
|
|
||||||
|
# Create user
|
||||||
|
ENV USER=automation
|
||||||
|
ENV UID=10001
|
||||||
|
RUN adduser \
|
||||||
|
--disabled-password \
|
||||||
|
--gecos "" \
|
||||||
|
--home "/nonexistent" \
|
||||||
|
--shell "/sbin/nologin" \
|
||||||
|
--no-create-home \
|
||||||
|
--uid "${UID}" \
|
||||||
|
"${USER}"
|
||||||
|
|
||||||
|
# Create basic project structure
|
||||||
|
RUN cargo new --bin /app
|
||||||
|
RUN cargo new --lib /app/impl_cast && truncate -s 0 /app/impl_cast/src/lib.rs
|
||||||
|
RUN cargo new --lib /app/google-home
|
||||||
|
|
||||||
|
# Get the correct version of the compiler
|
||||||
|
RUN rustup default nightly
|
||||||
|
|
||||||
|
# Copy cargo config
|
||||||
|
COPY .cargo/config.toml /app/.cargo/config.toml
|
||||||
|
|
||||||
|
# Copy the Cargo.toml files
|
||||||
|
COPY impl_cast/Cargo.toml /app/impl_cast
|
||||||
|
COPY google-home/Cargo.toml /app/google-home
|
||||||
|
COPY Cargo.toml Cargo.lock /app/
|
||||||
|
|
||||||
|
# Download and build all the dependencies
|
||||||
|
WORKDIR /app
|
||||||
|
RUN --mount=type=cache,target=/usr/local/cargo/registry cargo build --release
|
||||||
|
|
||||||
|
# Build impl_cast
|
||||||
|
COPY impl_cast/src/ /app/impl_cast/src/
|
||||||
|
RUN --mount=type=cache,target=/usr/local/cargo/registry set -e; touch /app/impl_cast/src/lib.rs; cargo build --release --package impl_cast
|
||||||
|
|
||||||
|
# Build google-home
|
||||||
|
COPY google-home/src/ /app/google-home/src/
|
||||||
|
RUN --mount=type=cache,target=/usr/local/cargo/registry set -e; touch /app/google-home/src/lib.rs; cargo build --release --package google-home
|
||||||
|
|
||||||
|
# Build automation
|
||||||
|
COPY src/ /app/src/
|
||||||
|
RUN --mount=type=cache,target=/usr/local/cargo/registry set -e; touch /app/src/main.rs /app/src/lib.rs /app/google-home/src/lib.rs /app/impl_cast/src/lib.rs; cargo build --release
|
||||||
|
|
||||||
|
CMD ["/app/target/release/automation"]
|
||||||
|
|
||||||
|
|
||||||
|
# FINAL IMAGE
|
||||||
|
FROM gcr.io/distroless/cc-debian12:latest
|
||||||
|
|
||||||
|
COPY --from=build /etc/passwd /etc/passwd
|
||||||
|
COPY --from=build /etc/group /etc/group
|
||||||
|
|
||||||
ENV AUTOMATION_CONFIG=/app/config.yml
|
ENV AUTOMATION_CONFIG=/app/config.yml
|
||||||
COPY ./config/config.yml /app/config.yml
|
COPY config/config.yml /app/config.yml
|
||||||
|
|
||||||
COPY ./build/automation /app/automation
|
WORKDIR /app
|
||||||
|
COPY --from=build /app/target/x86_64-unknown-linux-gnu/release/automation ./
|
||||||
|
|
||||||
|
USER automation:automation
|
||||||
|
|
||||||
CMD ["/app/automation"]
|
CMD ["/app/automation"]
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
[toolchain]
|
|
||||||
channel = "nightly-2023-11-15"
|
|
||||||
components = ["rustfmt", "clippy"]
|
|
||||||
profile = "minimal"
|
|
Loading…
Reference in New Issue
Block a user