Skip to content

Commit 2742424

Browse files
committed
fix: dockerfile
1 parent 4f9fee8 commit 2742424

File tree

7 files changed

+257
-61
lines changed

7 files changed

+257
-61
lines changed

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
[workspace]
2+
members = ["src/public"]
23
resolver = "2"
3-
members = [
4-
"src/public",
5-
]

Dockerfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Using the `rust-musl-builder` as base image, instead of
22
# the official Rust toolchain
3-
FROM --platform=linux/amd64 clux/muslrust:stable AS chef
3+
FROM clux/muslrust:stable AS chef
44
USER root
55
RUN cargo install cargo-chef
66
WORKDIR /app
@@ -14,21 +14,20 @@ RUN cargo chef prepare --recipe-path recipe.json
1414

1515
FROM chef AS builder
1616
COPY --from=planner /app/recipe.json recipe.json
17-
# Notice that we are specifying the --target flag!
18-
RUN cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json
17+
RUN cargo chef cook --release --recipe-path recipe.json
1918
COPY . .
20-
RUN cargo build --release --target x86_64-unknown-linux-musl --bin cli
19+
RUN mv target/${CARGO_BUILD_TARGET}/release /out
2120

2221
FROM scratch AS prod
2322
WORKDIR /user
2423
COPY src/public/config/00-default.toml 00-default.toml
25-
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/cli /usr/local/bin/rust-server
24+
COPY --from=builder /out/cli /usr/local/bin/rust-server
2625
ENTRYPOINT ["/usr/local/bin/rust-server", "--config-path=*.toml"]
2726

2827
FROM alpine AS dev
2928
WORKDIR /user
3029
COPY src/public/config/00-default.toml 00-default.toml
31-
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/cli /usr/local/bin/rust-server
30+
COPY --from=builder /out/cli /usr/local/bin/rust-server
3231
COPY --from=bunyan /root/.cargo/bin/bunyan /usr/local/bin/
3332
ENTRYPOINT ["/bin/sh"]
3433
CMD ["-c", "/usr/local/bin/rust-server --config-path=*.toml | bunyan"]

README.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,31 @@ Welcome to the Rust API Server! This server provides a simple REST interface for
1111
guide you through setting up and running the server, as well as configuring its various options.
1212

1313
## Deploy
14+
1415
**Automated Builds:**
15-
Builds are automatically generated for each commit to the repository in the `main` branch and are subsequently pushed to Docker Hub. Tags are applied using the commit SHA, branch name, and the latest tag if released on the main branch. You can find a list of available tags [here](https://hub.docker.com/r/thuan2172001/rust-server/tags).
16+
Builds are automatically generated for each commit to the repository in the `main` branch and are subsequently pushed to Docker Hub.
17+
Tags are applied using the commit SHA, branch name, and the latest tag if released on the main branch. You can find a list of available
18+
tags [here](https://hub.docker.com/r/thuan2172001/rust-server/tags).
1619

1720
**Release Binaries:**
18-
For every release, separate `cli` binaries are built. These binaries can be downloaded from [here](https://github.com/sonntuet1997/rust-web-api-microservice-template/releases) and are available for various operating systems and architectures. You are welcome to use the automated binaries or build your own.
21+
For every release, separate `cli` binaries are built. These binaries can be downloaded
22+
from [here](https://github.com/sonntuet1997/rust-web-api-microservice-template/releases) and are available for various operating
23+
systems and architectures. You are welcome to use the automated binaries or build your own.
1924

2025
**Contributions and PRs:**
21-
If you submit a pull request, please note that images are not built by default. A maintainer will need to retag them for the build process to take place.
26+
If you submit a pull request, please note that images are not built by default. A maintainer will need to retag them for the build
27+
process to take place.
2228

2329
### Docker
30+
2431
1. Pull the docker image
32+
2533
```commit to only the main branch
2634
docker pull thuan2172001/rust-server:latest
2735
```
2836

2937
2. Run the image
38+
3039
```
3140
docker run -d -p 8000:8000 thuan2172001/rust-server:latest
3241
```
@@ -132,18 +141,20 @@ Demonstrate proficiency in advanced development practices including:
132141
3. [x] Multiple Implementations.
133142
4. [x] Advanced Tracing.
134143
5. [x] CI/CD.
135-
1. [ ] Migrate DB tool/image.
136-
2. [x] Publish binary artifacts in [Github](https://github.com/).
137-
3. [x] Push Docker images.
138-
4. [x]
139-
Deploy [Dependabot](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuring-dependabot-version-updates)
144+
1. [x] Publish binary artifacts in [Github](https://github.com/).
145+
2. [x] Push Docker images.
146+
3. [x] Build pipeline on amd arch.
147+
4. [ ] Build pipeline on arm arch.
140148
6. [x] Docker Image Optimization.
141149
7. [x] Load test using [K6](https://k6.io/).
142150
1. [x] Use [Flamegraph](https://github.com/flamegraph-rs/flamegraph) for profiling.
143151
2. [ ] [Better UI](https://medium.com/swlh/beautiful-load-testing-with-k6-and-docker-compose-4454edb3a2e3).
144152
8. [ ] Comprehensive DB query filter for list().
145153
9. [ ] Optimize release binary performance.
146154
10. [ ] Docs on how to use this repo, the design behind the scene.
155+
11. [x] Dependabot
156+
1. [x] Update Rust.
157+
2. [x] Update Docker image.
147158

148159
Feel free to explore and expand upon these functionalities as needed for your project. Happy coding!
149160

src/adapter/Cargo.toml

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,56 @@
1+
bin = []
2+
bench = []
3+
test = []
4+
example = []
5+
16
[package]
27
name = "adapter"
3-
version = "0.1.0"
48
edition = "2021"
9+
version = "0.0.1"
10+
autobins = true
11+
autoexamples = true
12+
autotests = true
13+
autobenches = true
514

615
[dependencies]
7-
rust_core = { path = "../core" }
8-
async-trait = { version = "0.1.77" }
9-
tokio = { version = "1.36.0", features = ["full"] }
10-
diesel = { version = "2.1.4", features = [
11-
"postgres",
12-
"postgres_backend",
13-
"uuid",
14-
] }
15-
serde = { version = "1.0", features = ["derive"] }
16-
deadpool-diesel = { version = "0.5.0", features = ["postgres", "serde"] }
1716
diesel_migrations = "2.1.0"
18-
testcontainers-modules = { version = "0.3.4", features = ["postgres"] }
17+
18+
[dependencies.async-trait]
19+
version = "0.1.77"
20+
21+
[dependencies.deadpool-diesel]
22+
version = "0.5.0"
23+
features = ["postgres", "serde"]
24+
25+
[dependencies.diesel]
26+
version = "2.1.4"
27+
features = ["postgres", "postgres_backend", "uuid"]
28+
29+
[dependencies.rust_core]
30+
path = "../core"
31+
32+
[dependencies.serde]
33+
version = "1.0"
34+
features = ["derive"]
35+
36+
[dependencies.testcontainers-modules]
37+
version = "0.3.4"
38+
features = ["postgres"]
39+
40+
[dependencies.tokio]
41+
version = "1.36.0"
42+
features = ["full"]
43+
44+
[lib]
45+
path = "src/lib.rs"
46+
name = "adapter"
47+
test = true
48+
doctest = true
49+
bench = true
50+
doc = true
51+
plugin = false
52+
proc-macro = false
53+
harness = true
54+
edition = "2021"
55+
required-features = []
56+
crate-type = ["rlib"]

src/common/Cargo.toml

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,56 @@
1+
bin = []
2+
bench = []
3+
test = []
4+
example = []
5+
16
[package]
27
name = "common"
3-
version = "0.1.0"
48
edition = "2021"
9+
version = "0.0.1"
10+
autobins = true
11+
autoexamples = true
12+
autotests = true
13+
autobenches = true
514

615
[dependencies]
7-
serde = { version = "1.0", features = ["derive"] }
8-
opentelemetry-semantic-conventions = { version = "0.14.0" }
916
config = "0.14.0"
1017
glob = "0.3.1"
1118
tracing = "0.1"
12-
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
13-
tracing-opentelemetry = "0.23.0"
1419
tracing-bunyan-formatter = "0.3.9"
15-
opentelemetry = { version = "0.22.0" }
16-
opentelemetry_sdk = { version = "0.22.1", features = ["rt-tokio"] }
17-
opentelemetry-otlp = { version = "0.15.0", features = ["tonic"] }
20+
tracing-opentelemetry = "0.23.0"
21+
22+
[dependencies.opentelemetry]
23+
version = "0.22.0"
24+
25+
[dependencies.opentelemetry-otlp]
26+
version = "0.15.0"
27+
features = ["tonic"]
28+
29+
[dependencies.opentelemetry-semantic-conventions]
30+
version = "0.14.0"
31+
32+
[dependencies.opentelemetry_sdk]
33+
version = "0.22.1"
34+
features = ["rt-tokio"]
35+
36+
[dependencies.serde]
37+
version = "1.0"
38+
features = ["derive"]
39+
40+
[dependencies.tracing-subscriber]
41+
version = "0.3.18"
42+
features = ["env-filter"]
43+
44+
[lib]
45+
path = "src/lib.rs"
46+
name = "common"
47+
test = true
48+
doctest = true
49+
bench = true
50+
doc = true
51+
plugin = false
52+
proc-macro = false
53+
harness = true
54+
edition = "2021"
55+
required-features = []
56+
crate-type = ["rlib"]

src/core/Cargo.toml

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
1+
bin = []
2+
bench = []
3+
test = []
4+
example = []
5+
16
[package]
27
name = "rust_core"
3-
version = "0.1.0"
48
edition = "2021"
9+
version = "0.0.1"
10+
autobins = true
11+
autoexamples = true
12+
autotests = true
13+
autobenches = true
14+
15+
[dependencies.async-trait]
16+
version = "0.1.77"
17+
18+
[dependencies.serde]
19+
version = "1.0"
20+
features = ["derive"]
521

6-
[dependencies]
7-
serde = { version = "1.0", features = ["derive"] }
8-
async-trait = { version = "0.1.77" }
22+
[lib]
23+
path = "src/lib.rs"
24+
name = "rust_core"
25+
test = true
26+
doctest = true
27+
bench = true
28+
doc = true
29+
plugin = false
30+
proc-macro = false
31+
harness = true
32+
edition = "2021"
33+
required-features = []
34+
crate-type = ["rlib"]

0 commit comments

Comments
 (0)