Skip to content

Commit

Permalink
Add Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
vruello committed May 2, 2024
1 parent f00361a commit df71286
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/target
/.vscode
/.idea
53 changes: 53 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
FROM rust:slim-bookworm as chef
RUN cargo install cargo-chef
WORKDIR /SRC

FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
# Install system deps
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
clang \
libssl-dev \
libkrb5-dev \
make \
pkgconf

COPY --from=planner /SRC/recipe.json recipe.json
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --recipe-path recipe.json

# Build application
COPY . .
RUN cargo build --release


FROM debian:bookworm-slim
ARG APP=/usr/src/openwec
ARG DATA=/var/lib/openwec/data
ARG DB=/var/lib/openwec/db

EXPOSE 5985
ENV APP_USER=openwec

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
libgssapi-krb5-2 \
&& rm -rf /var/lib/apt/lists/* \
&& groupadd $APP_USER \
&& useradd -g $APP_USER $APP_USER \
&& mkdir -p ${APP} ${DATA} ${DB}

COPY --from=builder /SRC/target/release/openwec ${APP}/openwec
COPY --from=builder /SRC/target/release/openwecd ${APP}/openwecd
COPY ./docker/entrypoint.sh ${APP}/entrypoint.sh

RUN chown -R $APP_USER:$APP_USER ${APP} ${DATA} ${DB}

USER $APP_USER
WORKDIR ${APP}

CMD ["./entrypoint.sh"]
15 changes: 15 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -eux

# Try to create openwec db if not already existing
# This also applies migrations
./openwec db init

# Load subscriptions configuration files if provided
if [ -d /etc/openwec.d/ ]; then
./openwec subscriptions load /etc/openwec.d
fi

# Start openwecd
exec ./openwecd

0 comments on commit df71286

Please sign in to comment.