Feature: Use Gitea Actions to build automation_rs
All checks were successful
Build and deploy automation_rs / Build (push) Successful in 6m39s
Build and deploy automation_rs / Create Docker container (push) Successful in 1m1s

Builds automation_rs and the corresponding docker image.
The binary is uploaded as an artifact and the image is uploaded to the
registry.

In order to improve caching the nightly version is locked using
rust-toolchain.toml
This commit is contained in:
2023-11-16 01:45:45 +01:00
parent 73a2b077ed
commit c77064b5b9
4 changed files with 76 additions and 108 deletions

View File

@@ -1,64 +1,8 @@
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
FROM gcr.io/distroless/cc-debian12:nonroot
ENV AUTOMATION_CONFIG=/app/config.yml
COPY config/config.yml /app/config.yml
COPY ./config/config.yml /app/config.yml
WORKDIR /app
COPY --from=build /app/target/x86_64-unknown-linux-gnu/release/automation ./
USER automation:automation
COPY ./build/automation /app/automation
CMD ["/app/automation"]