leonev commited on
Commit
ad297a0
1 Parent(s): a912ac0

✨ Build arguments to make writing GitHub action for auto releasing new docker images easier (#324)

Browse files

* ✨ feat: Dockerfile with arch and feature build arguments

* 🛠️ fix: missing issuer certificate error

* ⚙️ refactor: replace `--update` with new `--no-cache` option

Files changed (2) hide show
  1. Cargo.toml +7 -1
  2. Dockerfile +28 -25
Cargo.toml CHANGED
@@ -6,8 +6,14 @@ description = "An open-source alternative to Searx that provides clean, ad-free,
6
  repository = "https://github.com/neon-mmd/websurfx"
7
  license = "AGPL-3.0"
8
 
 
 
 
 
 
 
9
  [dependencies]
10
- reqwest = {version="0.11.21",features=["json"]}
11
  tokio = {version="1.32.0",features=["rt-multi-thread","macros"]}
12
  serde = {version="1.0.188",features=["derive"]}
13
  handlebars = { version = "4.4.0", features = ["dir_source"] }
 
6
  repository = "https://github.com/neon-mmd/websurfx"
7
  license = "AGPL-3.0"
8
 
9
+ [[bin]]
10
+ name = "websurfx"
11
+ test = true
12
+ bench = false
13
+ path = "src/bin/websurfx.rs"
14
+
15
  [dependencies]
16
+ reqwest = {version="0.11.21",default-features = false,features = ["json", "rustls-tls"]}
17
  tokio = {version="1.32.0",features=["rt-multi-thread","macros"]}
18
  serde = {version="1.0.188",features=["derive"]}
19
  handlebars = { version = "4.4.0", features = ["dir_source"] }
Dockerfile CHANGED
@@ -1,40 +1,43 @@
1
- FROM rust:latest AS chef
2
  # We only pay the installation cost once,
3
  # it will be cached from the second build onwards
 
4
  RUN cargo install cargo-chef --locked
5
 
6
  WORKDIR /app
7
 
8
  FROM chef AS planner
9
- COPY . .
10
  RUN cargo chef prepare --recipe-path recipe.json
11
 
12
- FROM chef AS builder
13
  COPY --from=planner /app/recipe.json recipe.json
14
- # Build dependencies - this is the caching Docker layer!
15
- # Uncomment the line below if you want to use the `hybrid` caching feature.
16
- # RUN cargo chef cook --release --features redis-cache --recipe-path recipe.json
17
- # Comment the line below if you don't want to use the `In-Memory` caching feature.
18
- RUN cargo chef cook --release --recipe-path recipe.json
19
- # Uncomment the line below if you want to use the `no cache` feature.
20
- # RUN cargo chef cook --release --no-default-features --recipe-path recipe.json
21
- # Uncomment the line below if you want to use the `redis` caching feature.
22
- # RUN cargo chef cook --release --no-default-features --features redis-cache --recipe-path recipe.json
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- # Build application
25
- COPY . .
26
- # Uncomment the line below if you want to use the `hybrid` caching feature.
27
- # RUN cargo install --path . --features redis-cache
28
- # Comment the line below if you don't want to use the `In-Memory` caching feature.
29
- RUN cargo install --path .
30
- # Uncomment the line below if you want to use the `no cache` feature.
31
- # RUN cargo install --path . --no-default-features
32
- # Uncomment the line below if you want to use the `redis` caching feature.
33
- # RUN cargo install --path . --no-default-features --features redis-cache
34
 
35
- # We do not need the Rust toolchain to run the binary!
36
- FROM gcr.io/distroless/cc-debian12
37
  COPY --from=builder /app/public/ /opt/websurfx/public/
38
  VOLUME ["/etc/xdg/websurfx/"]
39
- COPY --from=builder /usr/local/cargo/bin/* /usr/local/bin/
40
  CMD ["websurfx"]
 
1
+ FROM --platform=$BUILDPLATFORM rust:1.73.0-alpine3.18 AS chef
2
  # We only pay the installation cost once,
3
  # it will be cached from the second build onwards
4
+ RUN apk add --no-cache alpine-sdk musl-dev g++ make libcrypto3 libressl-dev upx perl build-base
5
  RUN cargo install cargo-chef --locked
6
 
7
  WORKDIR /app
8
 
9
  FROM chef AS planner
10
+ COPY ./Cargo.toml ./Cargo.lock ./
11
  RUN cargo chef prepare --recipe-path recipe.json
12
 
13
+ FROM --platform=$BUILDPLATFORM chef AS builder
14
  COPY --from=planner /app/recipe.json recipe.json
15
+ # Specify the cache type to use (memory, redis, hybrid, no-cache)
16
+ ARG CACHE=memory
17
+ ENV CACHE=${CACHE}
18
+ # Cook the dependencies
19
+ RUN export ARCH=$(uname -m) && \
20
+ if [ "$CACHE" = "memory" ] ; then cargo chef cook --release --target=$ARCH-unknown-linux-musl --recipe-path recipe.json ; \
21
+ else if [ "$CACHE" = "redis" ] ; then cargo chef cook --release --target=$ARCH-unknown-linux-musl --no-default-features --features redis-cache --recipe-path recipe.json ; \
22
+ else if [ "$CACHE" = "hybrid" ] ; then cargo chef cook --release --target=$ARCH-unknown-linux-musl --features redis-cache --recipe-path recipe.json ; \
23
+ else if [ "$CACHE" = "no-cache" ] ; then cargo chef cook --release --target=$ARCH-unknown-linux-musl --no-default-features --recipe-path recipe.json ; fi ; fi ; fi ; fi
24
+ # Copy the source code and public folder
25
+ COPY ./src ./src
26
+ COPY ./public ./public
27
+ # Build the application
28
+ RUN export ARCH=$(uname -m) && \
29
+ if [ "$CACHE" = "memory" ] ; then cargo build --release --target=$ARCH-unknown-linux-musl ; \
30
+ else if [ "$CACHE" = "redis" ] ; then cargo build --release --target=$ARCH-unknown-linux-musl --no-default-features --features redis-cache ; \
31
+ else if [ "$CACHE" = "hybrid" ] ; then cargo build --release --target=$ARCH-unknown-linux-musl --features redis-cache ; \
32
+ else if [ "$CACHE" = "no-cache" ] ; then cargo build --release --target=$ARCH-unknown-linux-musl --no-default-features ; fi ; fi ; fi ; fi
33
+ # Optimise binary size with UPX
34
+ RUN export ARCH=$(uname -m) \
35
+ && upx --lzma --best /app/target/$ARCH-unknown-linux-musl/release/websurfx \
36
+ && cp /app/target/$ARCH-unknown-linux-musl/release/websurfx /usr/local/bin/websurfx
37
 
 
 
 
 
 
 
 
 
 
 
38
 
39
+ FROM --platform=$BUILDPLATFORM scratch
 
40
  COPY --from=builder /app/public/ /opt/websurfx/public/
41
  VOLUME ["/etc/xdg/websurfx/"]
42
+ COPY --from=builder /usr/local/bin/websurfx /usr/local/bin/websurfx
43
  CMD ["websurfx"]