Skip to content

Commit 6056f5f

Browse files
authored
Add a Dockerfile to build and run Squawk (#422)
Introduce a multi-stage Dockerfile for the Squawk project. The builder stage compiles the Rust application, while the final stage creates a lightweight container to run Squawk as a non-root user. This setup improves portability and simplifies deployment. Refers to #290
1 parent 910adac commit 6056f5f

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

Dockerfile

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Builder stage
2+
FROM rust:1-slim-bookworm AS builder
3+
4+
# Labels for the builder stage
5+
LABEL stage=builder
6+
7+
# Install build dependencies
8+
RUN apt-get update && apt-get install -y --no-install-recommends \
9+
libclang-dev \
10+
perl \
11+
pkg-config \
12+
make \
13+
&& rm -rf /var/lib/apt/lists/*
14+
15+
# Create a new empty shell project
16+
WORKDIR /usr/src/squawk
17+
18+
# First, copy only the workspace configuration and toolchain files
19+
COPY Cargo.toml Cargo.lock rust-toolchain.toml ./
20+
21+
# Copy the entire project
22+
COPY . .
23+
24+
# Build the release version
25+
RUN cargo build --release
26+
27+
# Final stage
28+
FROM debian:bookworm-slim
29+
30+
# Metadata labels
31+
LABEL org.opencontainers.image.title="Squawk"
32+
LABEL org.opencontainers.image.description="Linter for PostgreSQL focused on database migrations"
33+
LABEL org.opencontainers.image.licenses="GPL-3.0"
34+
LABEL org.opencontainers.image.source="https://github.com/sbdchd/squawk"
35+
36+
# Create a non-root user to run the application
37+
RUN groupadd -r squawk && useradd -r -g squawk squawk
38+
39+
# Install runtime dependencies
40+
RUN apt-get update && apt-get install -y --no-install-recommends \
41+
ca-certificates \
42+
libssl-dev \
43+
&& rm -rf /var/lib/apt/lists/*
44+
45+
# Copy the binary from the builder stage
46+
COPY --from=builder /usr/src/squawk/target/release/squawk /usr/local/bin/squawk
47+
48+
# Set the ownership of the binary
49+
RUN chown squawk:squawk /usr/local/bin/squawk
50+
51+
# Switch to non-root user
52+
USER squawk
53+
54+
WORKDIR /data
55+
56+
# Command to run when the container starts
57+
ENTRYPOINT ["squawk"]
58+
CMD ["--help"]

0 commit comments

Comments
 (0)