Skip to content

Commit 8d25d99

Browse files
committed
Improve Docker image building and deployment
- Changed the base image in Dockerfile to `ghcr.io/zenika/alpine-chrome:124` - Updated the `Cargo.toml` file to remove the `features = ["fetch"]` specification and update the git URL for the `headless_chrome` dependency - Added a new workflow file for Docker build and push - Set up QEMU and Docker Buildx in the workflow - Built and pushed a Docker image using Docker Buildx, tagging it with `latest` and the commit SHA for Linux amd64 and arm64 platforms - Modified the IP address in `warp::serve` function call in `src/main.rs`
1 parent 6ec0d85 commit 8d25d99

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build-and-push:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v3
15+
16+
- name: Set up QEMU
17+
uses: docker/setup-qemu-action@v2
18+
with:
19+
platforms: linux/amd64,linux/arm64
20+
21+
- name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v2
23+
24+
- name: Log in to GitHub Container Registry
25+
uses: docker/login-action@v2
26+
with:
27+
registry: ghcr.io
28+
username: ${{ github.repository_owner }}
29+
password: ${{ secrets.GITHUB_TOKEN }}
30+
31+
- name: Build and push Docker image
32+
uses: docker/build-push-action@v4
33+
with:
34+
context: .
35+
push: true
36+
tags: |
37+
ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:latest
38+
ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:${{ github.sha }}
39+
platforms: linux/amd64,linux/arm64
40+

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
headless_chrome = {git = "https://github.com/rust-headless-chrome/rust-headless-chrome", features = ["fetch"]}
7+
headless_chrome = { git = "https://github.com/rust-headless-chrome/rust-headless-chrome" }
88
warp = "0.3.7"
99
serde = { version = "1.0", features = ["derive"] }
1010
tokio = { version = "1", features = ["full"] }

Dockerfile

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ COPY . ./
1010
RUN cargo build --release
1111

1212
# Runtime stage
13-
FROM ghcr.io/zenika/alpine-chrome
13+
FROM ghcr.io/zenika/alpine-chrome:124
1414

15+
USER root
1516
# Install required packages
1617
RUN apk add --no-cache tini
1718

1819
# Copy the compiled binary from the build stage
1920
COPY --from=builder /usr/src/renderer_rs/target/release/renderer_rs /usr/local/bin/renderer_rs
2021

22+
USER chrome
23+
2124
# Expose port 8080
2225
EXPOSE 8080
2326

src/main.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ async fn main() {
3030
.and(with_semaphore(semaphore))
3131
.and_then(render_handler);
3232

33-
warp::serve(render_route).run(([127, 0, 0, 1], 8080)).await;
33+
println!("Server running on http://0.0.0.0:8080");
34+
warp::serve(render_route).run(([0, 0, 0, 0], 8080)).await;
3435
}
3536

3637
#[derive(Deserialize)]
@@ -82,4 +83,4 @@ async fn render_handler(
8283
})?;
8384

8485
Ok(warp::reply::html(content))
85-
}
86+
}

0 commit comments

Comments
 (0)