Skip to content

Commit

Permalink
fix: improve the default dockerfile
Browse files Browse the repository at this point in the history
Signed-off-by: Mateusz Urbanek <[email protected]>
  • Loading branch information
shanduur committed Nov 15, 2024
1 parent 765f5d2 commit 7616e1c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
35 changes: 19 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,44 +1,47 @@
ARG ALPINE_VERSION=edge

FROM alpine:$ALPINE_VERSION AS builder
# Stage 1: Build the application
FROM docker.io/library/rust:1.80-alpine AS builder

# Update Alpine packages and install build dependencies
RUN apk update && apk add --no-cache --virtual .build-dependencies \
cargo \
cmake \
build-base \
file \
libgcc \
musl-dev \
protobuf \
protobuf-dev \
rust

RUN apk add --no-cache llvm-libunwind \
pkgconfig
musl-dev \
protobuf \
protobuf-dev

# Copy the source code into the image
COPY . /usr/src/sozu
WORKDIR /usr/src/sozu

# Build the application in release mode with a frozen lockfile
RUN cargo vendor --locked
RUN cargo build --release --frozen

FROM alpine:$ALPINE_VERSION AS bin
# Stage 2: Create the runtime environment
FROM docker.io/library/alpine:3.20 AS bin

# Expose ports for the application
EXPOSE 80
EXPOSE 443

# Define volumes for configuration and runtime state
VOLUME /etc/sozu
VOLUME /run/sozu

# Create a directory for persistent state
RUN mkdir -p /var/lib/sozu

# Install runtime dependencies
RUN apk update && apk add --no-cache \
llvm-libunwind \
libgcc \
ca-certificates

# Copy the built binary from the builder stage
COPY --from=builder /usr/src/sozu/target/release/sozu /usr/local/bin/sozu

# Copy the default configuration file
COPY os-build/config.toml /etc/sozu/config.toml

# Set the default entry point to the binary and provide default command
# to start the application with a specific config
ENTRYPOINT ["/usr/local/bin/sozu"]
CMD ["start", "-c", "/etc/sozu/config.toml"]
9 changes: 1 addition & 8 deletions doc/how_to_use.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@ Check out the command line [documentation](./configure_cli.md) for more informat

## Run it with Docker

The repository provides a multi-stage [Dockerfile][df] image based on `alpine:edge`.
The repository provides a multi-stage [Dockerfile][df] image based on `alpine:3.20`.

You can build the image by doing:

docker build -t sozu .

There's also the [clevercloud/sozu](https://hub.docker.com/r/clevercloud/sozu/) image
following the master branch (outdated).

Run it with the command:

```bash
Expand All @@ -55,10 +52,6 @@ docker run \
sozu
```

To build an image with a specific version of Alpine:

docker build --build-arg ALPINE_VERSION=3.14 -t sozu:main-alpine-3.14 .

### Using a custom `config.toml` configuration file

The default configuration for sozu can be found in `../os-build/docker/config.toml`.
Expand Down

0 comments on commit 7616e1c

Please sign in to comment.